Exemple #1
0
 /**
  * @param TagInterface $tag
  * @throws Exception\InvalidArgumentException
  */
 public function addTagPrototype(TagInterface $tag)
 {
     $tagName = str_replace(array('-', '_'), '', $tag->getName());
     if (in_array($tagName, $this->tagNames)) {
         throw new Exception\InvalidArgumentException('A tag with this name already exists in this manager');
     }
     $this->tagNames[] = $tagName;
     $this->tags[] = $tag;
     if ($tag instanceof GenericTag) {
         $this->genericTag = $tag;
     }
 }
Exemple #2
0
 /**
  * Build a Tag generator object from a reflection object
  *
  * @param  ReflectionDocBlockTag $reflectionTag
  * @return Tag
  */
 public static function fromReflection(ReflectionDocBlockTag $reflectionTag)
 {
     $tagName = $reflectionTag->getName();
     $codeGenDocBlockTag = new self();
     $codeGenDocBlockTag->setName($tagName);
     // transport any properties via accessors and mutators from reflection to codegen object
     $reflectionClass = new \ReflectionClass($reflectionTag);
     foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
         if (substr($method->getName(), 0, 3) == 'get') {
             $propertyName = substr($method->getName(), 3);
             if (method_exists($codeGenDocBlockTag, 'set' . $propertyName)) {
                 $codeGenDocBlockTag->{'set' . $propertyName}($reflectionTag->{'get' . $propertyName}());
             }
         }
     }
     return $codeGenDocBlockTag;
 }
Exemple #3
0
 /**
  * @param ReflectionTagInterface $reflectionTag
  * @return TagInterface
  */
 public function createTagFromReflection(ReflectionTagInterface $reflectionTag)
 {
     $tagName = $reflectionTag->getName();
     /* @var TagInterface $newTag */
     $newTag = $this->getClonedPrototype($tagName);
     // transport any properties via accessors and mutators from reflection to codegen object
     $reflectionClass = new \ReflectionClass($reflectionTag);
     foreach ($reflectionClass->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
         if (substr($method->getName(), 0, 3) == 'get') {
             $propertyName = substr($method->getName(), 3);
             if (method_exists($newTag, 'set' . $propertyName)) {
                 $newTag->{'set' . $propertyName}($reflectionTag->{'get' . $propertyName}());
             }
         } elseif (substr($method->getName(), 0, 2) == 'is') {
             $propertyName = ucfirst($method->getName());
             if (method_exists($newTag, 'set' . $propertyName)) {
                 $newTag->{'set' . $propertyName}($reflectionTag->{$method->getName()}());
             }
         }
     }
     return $newTag;
 }