コード例 #1
0
 /**
  * Fetches the metadata for a property of a class
  *
  * @param mixed $class An instance of the class or it's name as a string
  * @param string $prop The name of the property 
  * @return AttributeReader An attribute reader instance
  */
 public static function PropertyAttributes($class, $prop_name)
 {
     if (!$class instanceof ReflectionClass) {
         $class = new ReflectionClass($class);
     }
     $prop = new ReflectionProperty($class->getName(), $prop_name);
     $cache = Cache::GetCache('attributes');
     $key = 'cp-' . $class->getFileName() . '-' . $prop_name;
     $reader = $cache->get($key);
     if (!$reader) {
         $yaml = AttributeReader::ParseDocComments($prop->getDocComment());
         if (trim($yaml) == '') {
             $reader = new AttributeReader();
         } else {
             $reader = new AttributeReader(yaml_parse($yaml));
         }
         $parent = $class->getParentClass();
         if ($parent) {
             $pmeta = AttributeReader::PropertyAttributes($parent, $prop_name);
             $reader = $pmeta->merge($reader);
         }
         $cache->set($key, $reader);
     }
     return $reader;
 }
コード例 #2
0
ファイル: attributetest.php プロジェクト: jawngee/HeavyMetal
 /**
  * Test the attribute reading meta attributes inheritance.
  */
 public function testInheritance()
 {
     $class = new AttributeChildClass();
     $classmeta = AttributeReader::ClassAttributes($class);
     $this->assertTrue($classmeta->grand == '123');
     $this->assertTrue($classmeta->parent == '456');
     $this->assertTrue($classmeta->child == '789');
     $methodmeta = AttributeReader::MethodAttributes($class, 'method');
     $this->assertTrue($methodmeta->grand == 'ABC');
     $this->assertTrue($methodmeta->parent == 'DEF');
     $this->assertTrue($methodmeta->child == 'GHI');
     $propmeta = AttributeReader::PropertyAttributes($class, 'property');
     $this->assertTrue($propmeta->grand == 'abc');
     $this->assertTrue($propmeta->parent == 'def');
     $this->assertTrue($propmeta->child == 'ghi');
 }