1 <?php 2 /* Copyright (c) 2013, Geert Bergman (geert@scrivo.nl) 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright notice, 9 * this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright notice, 11 * this list of conditions and the following disclaimer in the documentation 12 * and/or other materials provided with the distribution. 13 * 3. Neither the name of "Scrivo" nor the names of its contributors may be 14 * used to endorse or promote products derived from this software without 15 * specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 27 * POSSIBILITY OF SUCH DAMAGE. 28 * 29 * $Id: PropertySet.php 841 2013-08-19 22:19:47Z geert $ 30 */ 31 32 /** 33 * Implementation of the \Scrivo\PropertySet class. 34 */ 35 36 namespace Scrivo; 37 38 /** 39 * A property set provides property access to the page properties of 40 * a page or list item properties of a list item. 41 * 42 * When constructing pages or list items their list items will be added 43 * to the property sets that belong to these pages or list items. 44 * 45 * The property set also deals with the late binding of application 46 * properties. 47 */ 48 class PropertySet implements \Iterator { 49 50 /** 51 * An array to hold the properties. 52 * 53 * @var array 54 */ 55 protected $properties; 56 57 /** 58 * Construct an empty property set. 59 */ 60 public function __construct() { 61 $this->properties = array(); 62 } 63 64 /** 65 * Retrieve a property from the property set. 66 * 67 * @param string $name The name of the property. 68 * 69 * @return \Scrivo\PageProperty|\Scrivo\ListItemProperty $property The 70 * property to retrieve. 71 */ 72 public function __get($name) { 73 if (isset($this->properties[$name])) { 74 return $this->properties[$name]; 75 } 76 throw new \Scrivo\SystemException("Invalid property \"$name\". Valid ". 77 "properties are: ".implode(", ", array_keys($this->properties))); 78 } 79 80 /** 81 * Add a property to the property set. 82 * 83 * @param string $name The name of the property . 84 * @param \Scrivo\PageProperty|\Scrivo\ListItemProperty $property The 85 * property to add. 86 */ 87 public function __set($name, $property) { 88 if ($property instanceof \Scrivo\PageProperty 89 || $property instanceof \Scrivo\ListItemProperty) { 90 $this->properties[$name] = $property; 91 } else { 92 throw new \Scrivo\SystemException("Illegal argument"); 93 } 94 } 95 96 /** 97 * Rewind the properties array so iterating will start at the beginning 98 * again. 99 */ 100 function rewind() { 101 reset($this->properties); 102 } 103 104 /** 105 * Get the current property when iterating. 106 */ 107 function current() { 108 return current($this->properties); 109 } 110 111 /** 112 * Get the key of the current property when iterating. 113 */ 114 function key() { 115 return key($this->properties); 116 } 117 118 /** 119 * Get the next property when iterating. 120 */ 121 function next() { 122 next($this->properties); 123 } 124 125 /** 126 * Check if the current key is valid. 127 */ 128 function valid() { 129 return key($this->properties) ? true : false; 130 } 131 132 } 133 134 ?>
Documentation generated by phpDocumentor 2.0.0a12 and ScrivoDocumentor on August 29, 2013