Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function __construct(array $values)
 {
     $string = $values['value'];
     // Handle classes.
     if (strpos($string, '::') !== FALSE) {
         list($class, $constant) = explode('::', $string);
         try {
             $reflection = new \ReflectionClass($class);
             if ($reflection->hasConstant($constant)) {
                 $this->value = $reflection->getConstant($constant);
                 return;
             }
         } catch (\ReflectionException $e) {
         }
     }
     // Handle procedural constants.
     if (!$this->value && defined($string)) {
         $this->value = constant($string);
         return;
     }
     throw AnnotationException::semanticalErrorConstants($this->value);
 }
Ejemplo n.º 2
0
 /**
  * Constant ::= integer | string | float | boolean
  *
  * @throws AnnotationException
  * @return mixed
  */
 private function Constant()
 {
     $identifier = $this->Identifier();
     if (!defined($identifier) && false !== strpos($identifier, '::') && '\\' !== $identifier[0]) {
         list($className, $const) = explode('::', $identifier);
         $alias = false === ($pos = strpos($className, '\\')) ? $className : substr($className, 0, $pos);
         $found = false;
         switch (true) {
             case !empty($this->namespaces):
                 foreach ($this->namespaces as $ns) {
                     if (class_exists($ns . '\\' . $className) || interface_exists($ns . '\\' . $className)) {
                         $className = $ns . '\\' . $className;
                         $found = true;
                         break;
                     }
                 }
                 break;
             case isset($this->imports[$loweredAlias = strtolower($alias)]):
                 $found = true;
                 if (false !== $pos) {
                     $className = $this->imports[$loweredAlias] . substr($className, $pos);
                 } else {
                     $className = $this->imports[$loweredAlias];
                 }
                 break;
             default:
                 if (isset($this->imports['__NAMESPACE__'])) {
                     $ns = $this->imports['__NAMESPACE__'];
                     if (class_exists($ns . '\\' . $className) || interface_exists($ns . '\\' . $className)) {
                         $className = $ns . '\\' . $className;
                         $found = true;
                     }
                 }
                 break;
         }
         if ($found) {
             $identifier = $className . '::' . $const;
         }
     }
     if (!defined($identifier)) {
         throw AnnotationException::semanticalErrorConstants($identifier, $this->context);
     }
     return constant($identifier);
 }
Ejemplo n.º 3
0
 private function complementType($type, $context)
 {
     static $builtin = ['int', 'integer', 'bool', 'boolean', 'float', 'double', 'string', 'array', 'mixed', 'string', 'null'];
     if (($p = strrpos($type, '[]')) !== false) {
         return $this->complementType(substr($type, 0, $p), $context) . '[]';
     }
     if (in_array($type, $builtin)) {
         return $type;
     }
     foreach ($this->uses as $u) {
         $fqcn = $u . '\\' . $type;
         if (class_exists($fqcn)) {
             return $fqcn;
         }
     }
     if (class_exists($type)) {
         return $type;
     }
     throw AnnotationException::semanticalErrorConstants($type, $context);
 }