| [ Index ] |
PHP Cross Reference of MantisBT |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * File containing the ezcBaseOptions class. 4 * 5 * @package Base 6 * @version 1.8 7 * @copyright Copyright (C) 2005-2009 eZ Systems AS. All rights reserved. 8 * @license http://ez.no/licenses/new_bsd New BSD License 9 */ 10 11 /** 12 * Base options class for all eZ components. 13 * 14 * @package Base 15 * @version 1.8 16 */ 17 abstract class ezcBaseOptions implements ArrayAccess 18 { 19 /** 20 * Container to hold the properties 21 * 22 * @var array(string=>mixed) 23 */ 24 protected $properties; 25 26 /** 27 * Construct a new options object. 28 * Options are constructed from an option array by default. The constructor 29 * automatically passes the given options to the __set() method to set them 30 * in the class. 31 * 32 * @throws ezcBasePropertyNotFoundException 33 * If trying to access a non existent property. 34 * @throws ezcBaseValueException 35 * If the value for a property is out of range. 36 * @param array(string=>mixed) $options The initial options to set. 37 */ 38 public function __construct( array $options = array() ) 39 { 40 foreach ( $options as $option => $value ) 41 { 42 $this->__set( $option, $value ); 43 } 44 } 45 46 /** 47 * Merge an array into the actual options object. 48 * This method merges an array of new options into the actual options object. 49 * 50 * @throws ezcBasePropertyNotFoundException 51 * If trying to access a non existent property. 52 * @throws ezcBaseValueException 53 * If the value for a property is out of range. 54 * @param array(string=>mixed) $newOptions The new options. 55 */ 56 public function merge( array $newOptions ) 57 { 58 foreach ( $newOptions as $key => $value ) 59 { 60 $this->__set( $key, $value ); 61 } 62 } 63 64 /** 65 * Property get access. 66 * Simply returns a given option. 67 * 68 * @throws ezcBasePropertyNotFoundException 69 * If a the value for the property options is not an instance of 70 * @param string $propertyName The name of the option to get. 71 * @return mixed The option value. 72 * @ignore 73 * 74 * @throws ezcBasePropertyNotFoundException 75 * if the given property does not exist. 76 * @throws ezcBasePropertyPermissionException 77 * if the property to be set is a write-only property. 78 */ 79 public function __get( $propertyName ) 80 { 81 if ( $this->__isset( $propertyName ) === true ) 82 { 83 return $this->properties[$propertyName]; 84 } 85 throw new ezcBasePropertyNotFoundException( $propertyName ); 86 } 87 88 /** 89 * Sets an option. 90 * This method is called when an option is set. 91 * 92 * @param string $propertyName The name of the option to set. 93 * @param mixed $propertyValue The option value. 94 * @ignore 95 * 96 * @throws ezcBasePropertyNotFoundException 97 * if the given property does not exist. 98 * @throws ezcBaseValueException 99 * if the value to be assigned to a property is invalid. 100 * @throws ezcBasePropertyPermissionException 101 * if the property to be set is a read-only property. 102 */ 103 abstract public function __set( $propertyName, $propertyValue ); 104 105 /** 106 * Returns if a option exists. 107 * 108 * @param string $propertyName Option name to check for. 109 * @return bool Whether the option exists. 110 * @ignore 111 */ 112 public function __isset( $propertyName ) 113 { 114 return array_key_exists( $propertyName, $this->properties ); 115 } 116 117 /** 118 * Returns if an option exists. 119 * Allows isset() using ArrayAccess. 120 * 121 * @param string $propertyName The name of the option to get. 122 * @return bool Whether the option exists. 123 */ 124 public function offsetExists( $propertyName ) 125 { 126 return $this->__isset( $propertyName ); 127 } 128 129 /** 130 * Returns an option value. 131 * Get an option value by ArrayAccess. 132 * 133 * @throws ezcBasePropertyNotFoundException 134 * If $propertyName is not a key in the $properties array. 135 * @param string $propertyName The name of the option to get. 136 * @return mixed The option value. 137 */ 138 public function offsetGet( $propertyName ) 139 { 140 return $this->__get( $propertyName ); 141 } 142 143 /** 144 * Set an option. 145 * Sets an option using ArrayAccess. 146 * 147 * @throws ezcBasePropertyNotFoundException 148 * If $propertyName is not a key in the $properties array. 149 * @throws ezcBaseValueException 150 * If the value for a property is out of range. 151 * @param string $propertyName The name of the option to set. 152 * @param mixed $propertyValue The value for the option. 153 */ 154 public function offsetSet( $propertyName, $propertyValue ) 155 { 156 $this->__set( $propertyName, $propertyValue ); 157 } 158 159 /** 160 * Unset an option. 161 * Unsets an option using ArrayAccess. 162 * 163 * @throws ezcBasePropertyNotFoundException 164 * If $propertyName is not a key in the $properties array. 165 * @throws ezcBaseValueException 166 * If a the value for a property is out of range. 167 * @param string $propertyName The name of the option to unset. 168 */ 169 public function offsetUnset( $propertyName ) 170 { 171 $this->__set( $propertyName, null ); 172 } 173 } 174 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Thu Jul 28 15:48:31 2011 | Cross-referenced by PHPXref 0.7 |