コード例 #1
0
ファイル: controller.php プロジェクト: jawngee/HeavyMetal
 public function __construct($request)
 {
     $this->session = Session::Get();
     $this->request = $request;
     $this->metadata = AttributeReader::ClassAttributes($this);
     $this->setup();
 }
コード例 #2
0
ファイル: client.php プロジェクト: jawngee/HeavyMetal
 /**
  * @throws BadRequestException
  *
  */
 public function __construct()
 {
     $meta = AttributeReader::ClassAttributes($this);
     $apiconf = Config::Get('api');
     $this->conf = $apiconf->{$meta->api};
     if (!$this->conf) {
         throw new BadRequestException('Missing api info');
     }
 }
コード例 #3
0
 /**
  * Fetches the metadata for a class
  *
  * @param mixed $class An instance of a class or it's name as a string
  * @return AttributeReader An attribute reader instance
  */
 public static function ClassAttributes($class)
 {
     if (!$class instanceof ReflectionClass) {
         $class = new ReflectionClass($class);
     }
     $cache = Cache::GetCache('attributes');
     $key = 'cm-' . $class->getFileName();
     $reader = $cache->get($key);
     if (!$reader) {
         $yaml = AttributeReader::ParseDocComments($class->getDocComment());
         if (trim($yaml) == '') {
             $reader = new AttributeReader();
         } else {
             $reader = new AttributeReader(yaml_parse($yaml));
         }
         $parent = $class->getParentClass();
         if ($parent) {
             $pmeta = AttributeReader::ClassAttributes($parent);
             $reader = $pmeta->merge($reader);
         }
         $cache->set($key, $reader);
     }
     return $reader;
 }
コード例 #4
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');
 }
コード例 #5
0
ファイル: serializer.php プロジェクト: jawngee/HeavyMetal
 /**
  * Sets up serialization
  * 
  * @param mixed $object The object to serialize
  */
 protected function setup_serialization($object)
 {
     if (!$this->node_conf) {
         $attrs = AttributeReader::ClassAttributes($object);
         if (!$attrs || !$attrs->serializer) {
             throw new Exception('Class is missing necessary metadata for serialization.');
         }
         $this->node_config = self::GetNodeConf($attrs->serializer);
         $this->root = $attrs->serializer->node;
     }
     $this->object = $object;
     $this->content = $this->do_serialize();
 }