[ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 /* 3 * $Id: XMLElement.php 315 2005-12-24 20:48:31Z hans $ 4 * 5 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 6 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 7 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 8 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 9 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 10 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 11 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 12 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 13 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 14 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 15 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 16 * 17 * This software consists of voluntary contributions made by many individuals 18 * and is licensed under the LGPL. For more information please see 19 * <http://propel.phpdb.org>. 20 */ 21 22 /** 23 * An abstract class for elements represented by XML tags (e.g. Column, Table). 24 * 25 * @author Hans Lellelid <hans@xmpl.org> 26 * @version $Revision: 315 $ 27 * @package propel.engine.database.model 28 */ 29 abstract class XMLElement { 30 31 protected $attributes = array(); 32 33 protected $vendorSpecificInfo = array(); 34 35 /** 36 * Replaces the old loadFromXML() so that we can use loadFromXML() to load the attribs into the class. 37 */ 38 abstract protected function setupObject(); 39 40 /** 41 * This is the entry point method for loading data from XML. 42 * It calls a setupObject() method that must be implemented by the child class. 43 * @param array $attributes The attributes for the XML tag. 44 */ 45 public function loadFromXML($attributes) { 46 $this->attributes = array_change_key_case($attributes, CASE_LOWER); 47 $this->setupObject(); 48 } 49 50 /** 51 * Returns the assoc array of attributes. 52 * All attribute names (keys) are lowercase. 53 * @return array 54 */ 55 public function getAttributes() { 56 return $this->attributes; 57 } 58 59 /** 60 * Gets a particular attribute by [case-insensitive] name. 61 * If attribute is not set then the $defaultValue is returned. 62 * @param string $name The [case-insensitive] name of the attribute to lookup. 63 * @param mixed $defaultValue The default value to use in case the attribute is not set. 64 * @return mixed The value of the attribute or $defaultValue if not set. 65 */ 66 public function getAttribute($name, $defaultValue = null) { 67 $name = strtolower($name); 68 if (isset($this->attributes[$name])) { 69 return $this->attributes[$name]; 70 } else { 71 return $defaultValue; 72 } 73 } 74 75 /** 76 * Converts value specified in XML to a boolean value. 77 * This is to support the default value when used w/ a boolean column. 78 * @return value 79 */ 80 protected function booleanValue($val) { 81 if (is_numeric($val)) { 82 return (bool) $val; 83 } else { 84 return (in_array(strtolower($val), array('true', 't', 'y', 'yes'), true) ? true : false); 85 } 86 } 87 88 /** 89 * Sets vendor specific parameter that applies to this object. 90 * @param string $name 91 * @param string $value 92 */ 93 public function setVendorParameter($name, $value) 94 { 95 $this->vendorSpecificInfo[$name] = $value; 96 } 97 98 /** 99 * Whether specified vendor specific information is set. 100 * @param string $name 101 * @return boolean 102 */ 103 public function hasVendorParameter($name) 104 { 105 return isset($this->vendorSpecificInfo[$name]); 106 } 107 108 /** 109 * Returns specified vendor specific information is set. 110 * @param string $name 111 * @return string 112 */ 113 public function getVendorParameter($name) 114 { 115 if (isset($this->vendorSpecificInfo[$name])) { 116 return $this->vendorSpecificInfo[$name]; 117 } 118 return null; // just to be explicit 119 } 120 121 /** 122 * Sets vendor specific information for this object. 123 * @param array $info 124 */ 125 public function setVendorSpecificInfo($info) 126 { 127 $this->vendorSpecificInfo = $info; 128 } 129 130 /** 131 * Retrieves vendor specific information for this object. 132 * @return array 133 */ 134 public function getVendorSpecificInfo() 135 { 136 return $this->vendorSpecificInfo; 137 } 138 139 140 141 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |