Example #1
0
 /**
  * Obtain the config for a named class
  * @param string $class The class to get the config for
  * @return \Weasel\JsonMarshaller\Config\ClassMarshaller The config, or null if not found
  */
 public function getConfig($class)
 {
     $key = strtolower($class);
     if (isset($this->cache)) {
         $found = false;
         $cached = $this->cache->get($key, "JsonConfig", $found);
         if ($found) {
             return $cached;
         }
     }
     $config = $this->_getConfig($class);
     if (isset($this->cache)) {
         $this->cache->set($key, $config, "JsonConfig");
     }
     return $config;
 }
 public function get($name)
 {
     if (isset($this->cache)) {
         $found = false;
         $cached = $this->cache->get($name, "Annotation", $found);
         if ($found) {
             return $cached;
         }
     }
     if (self::$builtIns->getAnnotation($name)) {
         return self::$builtIns->getAnnotation($name);
     }
     $class = new \ReflectionClass($name);
     $reader = $this->readerFactory->getReaderForClass($class);
     /**
      * @var \Weasel\Annotation\Config\Annotations\Annotation $annotation
      */
     $annotation = $reader->getSingleClassAnnotation('\\Weasel\\Annotation\\Config\\Annotations\\Annotation');
     if (!isset($annotation)) {
         throw new \RuntimeException("Did not find an @Annotation annotation on {$name}");
     }
     $metaConfig = new Config\Annotation($name, $annotation->getOn(), $annotation->getMax());
     foreach ($class->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
         /**
          * @var \ReflectionMethod $method
          * @var \Weasel\Annotation\Config\Annotations\AnnotationCreator $creator
          */
         $creator = $reader->getSingleMethodAnnotation($method->getName(), '\\Weasel\\Annotation\\Config\\Annotations\\AnnotationCreator');
         if (isset($creator)) {
             if (!$method->isStatic() && !$method->isConstructor()) {
                 throw new \RuntimeException("Non-static methods cannot be configured as creators");
             }
             $metaConfig->setCreatorMethod($method->getName());
             $creatorArgs = $method->getParameters();
             if (count($creatorArgs) != count($creator->getParams())) {
                 throw new \RuntimeException("Creator args don't match with method args");
             }
             $i = 0;
             foreach ($creator->getParams() as $param) {
                 $paramName = $param->getName();
                 if (!isset($paramName)) {
                     $paramName = $creatorArgs[$i]->getName();
                 }
                 $creatorParam = new Config\Param($paramName, $param->getType(), $param->getRequired());
                 $i++;
                 $metaConfig->addCreatorParam($creatorParam);
             }
         }
     }
     foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
         /**
          * @var \ReflectionProperty $property
          * @var \Weasel\Annotation\Config\Annotations\Property $annotProperty
          */
         $annotProperty = $reader->getSinglePropertyAnnotation($property->getName(), '\\Weasel\\Annotation\\Config\\Annotations\\Property');
         if (isset($annotProperty)) {
             $propertyConfig = new Config\Property($property->getName(), $annotProperty->getType());
             $metaConfig->addProperty($propertyConfig);
         }
         /**
          * @var \Weasel\Annotation\Config\Annotations\Enum $annotEnum
          */
         $annotEnum = $reader->getSinglePropertyAnnotation($property->getName(), '\\Weasel\\Annotation\\Config\\Annotations\\Enum');
         if (isset($annotEnum)) {
             if (!$property->isStatic()) {
                 throw new \RuntimeException("Enums must be static properties");
             }
             $name = $annotEnum->getName();
             if (!isset($name)) {
                 $name = $property->getName();
             }
             $value = $property->getValue(null);
             if (!is_array($value)) {
                 throw new \RuntimeException("Enum must be an array");
             }
             $metaConfig->addEnum(new Config\Enum($name, $value));
         }
     }
     if (isset($this->cache)) {
         $this->cache->set($name, $metaConfig, "Annotation");
     }
     return $metaConfig;
 }
 /**
  * Deletes a cache entry.
  *
  * @param string $id The cache id.
  *
  * @return boolean TRUE if the cache entry was successfully deleted, FALSE otherwise.
  */
 protected function doDelete($id)
 {
     $this->delegate->delete($id);
     return true;
 }