|
TYPO3 API
SVNRelease
|
00001 <?php 00002 /*************************************************************** 00003 * Copyright notice 00004 * 00005 * (c) 2009 Christopher Hlubek <hlubek@networkteam.com> 00006 * All rights reserved 00007 * 00008 * This script is part of the TYPO3 project. The TYPO3 project is 00009 * free software; you can redistribute it and/or modify 00010 * it under the terms of the GNU General Public License as published by 00011 * the Free Software Foundation; either version 2 of the License, or 00012 * (at your option) any later version. 00013 * 00014 * The GNU General Public License can be found at 00015 * http://www.gnu.org/copyleft/gpl.html. 00016 * 00017 * This script is distributed in the hope that it will be useful, 00018 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 * GNU General Public License for more details. 00021 * 00022 * This copyright notice MUST APPEAR in all copies of the script! 00023 ***************************************************************/ 00024 00025 /** 00026 * Extended version of the ReflectionProperty 00027 * 00028 * @package Extbase 00029 * @subpackage Reflection 00030 * @version $Id: PropertyReflection.php 1052 2009-08-05 21:51:32Z sebastian $ 00031 */ 00032 class Tx_Extbase_Reflection_PropertyReflection extends ReflectionProperty { 00033 00034 /** 00035 * @var Tx_Extbase_Reflection_DocCommentParser: An instance of the doc comment parser 00036 */ 00037 protected $docCommentParser; 00038 00039 /** 00040 * The constructor, initializes the reflection class 00041 * 00042 * @param string $className Name of the property's class 00043 * @param string $propertyName Name of the property to reflect 00044 * @return void 00045 */ 00046 public function __construct($className, $propertyName) { 00047 parent::__construct($className, $propertyName); 00048 } 00049 00050 /** 00051 * Checks if the doc comment of this property is tagged with 00052 * the specified tag 00053 * 00054 * @param string $tag Tag name to check for 00055 * @return boolean TRUE if such a tag has been defined, otherwise FALSE 00056 */ 00057 public function isTaggedWith($tag) { 00058 $result = $this->getDocCommentParser()->isTaggedWith($tag); 00059 return $result; 00060 } 00061 00062 /** 00063 * Returns an array of tags and their values 00064 * 00065 * @return array Tags and values 00066 */ 00067 public function getTagsValues() { 00068 return $this->getDocCommentParser()->getTagsValues(); 00069 } 00070 00071 /** 00072 * Returns the values of the specified tag 00073 * 00074 * @return array Values of the given tag 00075 */ 00076 public function getTagValues($tag) { 00077 return $this->getDocCommentParser()->getTagValues($tag); 00078 } 00079 00080 /** 00081 * Returns the value of the reflected property - even if it is protected. 00082 * 00083 * @param object $object Instance of the declaring class Tx_Extbase_Reflection_to read the value from 00084 * @return mixed Value of the property 00085 * @throws Tx_Extbase_Reflection_Exception 00086 * @todo Maybe support private properties as well, as of PHP 5.3.0 we can do 00087 * $obj = new Foo; 00088 * $prop = new ReflectionProperty('Foo', 'y'); // y is private member 00089 * $prop->setAccessible(true); 00090 * var_dump($prop->getValue($obj)); // int(2) 00091 */ 00092 public function getValue($object = NULL) { 00093 if (!is_object($object)) throw new Tx_Extbase_Reflection_Exception('$object is of type ' . gettype($object) . ', instance of class ' . $this->class . ' expected.', 1210859212); 00094 if ($this->isPublic()) return parent::getValue($object); 00095 if ($this->isPrivate()) throw new Tx_Extbase_Reflection_Exception('Cannot return value of private property "' . $this->name . '.', 1210859206); 00096 00097 parent::setAccessible(TRUE); 00098 return parent::getValue($object); 00099 } 00100 00101 /** 00102 * Returns an instance of the doc comment parser and 00103 * runs the parse() method. 00104 * 00105 * @return Tx_Extbase_Reflection_DocCommentParser 00106 */ 00107 protected function getDocCommentParser() { 00108 if (!is_object($this->docCommentParser)) { 00109 $this->docCommentParser = new Tx_Extbase_Reflection_DocCommentParser; 00110 $this->docCommentParser->parseDocComment($this->getDocComment()); 00111 } 00112 return $this->docCommentParser; 00113 } 00114 } 00115 00116 ?>
1.8.0