Exemplo n.º 1
0
 /**
  * Return a single property by given name or index of info
  *
  * @param  string|int $propertyNameOrInfoIndex
  * @throws Exception\InvalidArgumentException
  * @return bool|PropertyScanner
  */
 public function getProperty($propertyNameOrInfoIndex)
 {
     $this->scan();
     if (is_int($propertyNameOrInfoIndex)) {
         $info = $this->infos[$propertyNameOrInfoIndex];
         if ($info['type'] != 'property') {
             throw new Exception\InvalidArgumentException('Index of info offset is not about a property');
         }
     } elseif (is_string($propertyNameOrInfoIndex)) {
         $propertyFound = false;
         foreach ($this->infos as $info) {
             if ($info['type'] === 'property' && $info['name'] === $propertyNameOrInfoIndex) {
                 $propertyFound = true;
                 break;
             }
         }
         if (!$propertyFound) {
             return false;
         }
     } else {
         throw new Exception\InvalidArgumentException('Invalid property name of info index type.  Must be of type int or string');
     }
     if (!isset($info)) {
         return false;
     }
     $p = new PropertyScanner(array_slice($this->tokens, $info['tokenStart'], $info['tokenEnd'] - $info['tokenStart'] + 1), $this->nameInformation);
     $p->setClass($this->name);
     $p->setScannerClass($this);
     return $p;
 }