public function __construct($request) { $this->session = Session::Get(); $this->request = $request; $this->metadata = AttributeReader::ClassAttributes($this); $this->setup(); }
/** * @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'); } }
/** * 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; }
/** * 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'); }
/** * 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(); }