Example #1
0
 /**
  * @param object|NULL
  * @return AccessBase $this
  */
 public function asInstance($object)
 {
     if (is_object($object)) {
         if ($this->reflection instanceof ReflectionClass) {
             $class = $this->reflection->getName();
         } else {
             $class = $this->reflection->getDeclaringClass()->getName();
         }
         if (!$object instanceof $class) {
             throw new Exception('Must be instance of accessible class.');
         }
     } else {
         if ($object !== NULL) {
             throw new Exception('Instance must be object or NULL.');
         }
     }
     $this->instance = $object;
     return $this;
 }
 /**
  * @param string $comment
  * @param string $current_tag
  * @param \ReflectionMethod|\ReflectionClass $reflection
  * @return array
  */
 private function extractTagsFromComment($comment, $current_tag = 'description', $reflection)
 {
     $ns = $reflection instanceof \ReflectionClass ? $reflection->getNamespaceName() : $reflection->getDeclaringClass()->getNamespaceName();
     $tags = array($current_tag => '');
     foreach (explode(PHP_EOL, $comment) as $line) {
         if ($current_tag != 'example') {
             $line = trim($line);
         }
         $words = explode(' ', trim($line));
         if (strpos($words[0], '@') === false) {
             // Append to tag
             $joinWith = $current_tag == 'example' ? PHP_EOL : ' ';
             $tags[$current_tag] .= $joinWith . $line;
         } elseif ($words[0] == '@param') {
             // Get parameter declaration
             if ($paramData = $this->figureOutParamDeclaration($words, $ns)) {
                 list($name, $data) = $paramData;
                 $tags['params'][$name] = $data;
             }
         } else {
             // Start new tag
             $current_tag = substr($words[0], 1);
             array_splice($words, 0, 1);
             if (empty($tags[$current_tag])) {
                 $tags[$current_tag] = '';
             }
             $tags[$current_tag] .= trim(join(' ', $words));
         }
     }
     foreach ($tags as $name => $val) {
         if (is_array($val)) {
             foreach ($val as $subName => $subVal) {
                 if (is_string($subVal)) {
                     $tags[$name][$subName] = trim($subVal);
                 }
             }
         } else {
             $tags[$name] = trim($val);
         }
     }
     return $tags;
 }
Example #3
0
 /**
  * @param \ReflectionClass|\ReflectionMethod $reflection
  * @return string
  */
 private function getNameSpace($reflection)
 {
     if ($reflection instanceof \ReflectionClass) {
         return $reflection->getNamespaceName();
     } else {
         return $reflection->getDeclaringClass()->getNamespaceName();
     }
 }