コード例 #1
0
 /**
  * @param string $method
  * @throws InvalidArgumentException
  * @return MethodElement
  */
 public function getInstance($method = null)
 {
     if (!$method) {
         throw new InvalidArgumentException('Bad method');
     }
     $class = $this->broker->getClass(__CLASS__);
     return parent::getInstance($class->getMethod($method));
 }
コード例 #2
0
 protected function setUp()
 {
     $container = $this->getMock('Go\\Core\\AspectContainer');
     $reader = $this->getMock('Doctrine\\Common\\Annotations\\Reader');
     $loader = $this->getMock('Go\\Core\\AspectLoader', array(), array($container, $reader));
     $this->adviceMatcher = new AdviceMatcher($loader, $container);
     $brokerInstance = new Broker(new Broker\Backend\Memory());
     $brokerInstance->processFile(__FILE__);
     $this->reflectionClass = $brokerInstance->getClass(__CLASS__);
 }
コード例 #3
0
 /**
  * Exports a reflected object.
  *
  * @param \TokenReflection\Broker $broker   Broker instance
  * @param string|object|null      $class    Class name, class instance or null
  * @param string                  $constant Constant name
  * @param boolean                 $return   Return the export instead of outputting it
  *
  * @return string|null
  * @throws \TokenReflection\Exception\RuntimeException If requested parameter doesn't exist.
  */
 public static function export(Broker $broker, $class, $constant, $return = false)
 {
     $className = is_object($class) ? get_class($class) : $class;
     $constantName = $constant;
     if (null === $className) {
         $constant = $broker->getConstant($constantName);
         if (null === $constant) {
             throw new Exception\RuntimeException('Constant does not exist.', Exception\RuntimeException::DOES_NOT_EXIST);
         }
     } else {
         $class = $broker->getClass($className);
         if ($class instanceof Invalid\ReflectionClass) {
             throw new Exception\RuntimeException('Class is invalid.', Exception\RuntimeException::UNSUPPORTED);
         } elseif ($class instanceof Dummy\ReflectionClass) {
             throw new Exception\RuntimeException('Class does not exist.', Exception\RuntimeException::DOES_NOT_EXIST, $class);
         }
         $constant = $class->getConstantReflection($constantName);
     }
     if ($return) {
         return $constant->__toString();
     }
     echo $constant->__toString();
 }
コード例 #4
0
 /**
  * Exports a reflected object.
  *
  * @param \TokenReflection\Broker $broker Broker instance
  * @param string|object           $class  Class name or class instance
  * @param string                  $method Method name
  * @param boolean                 $return Return the export instead of outputting it
  *
  * @return string|null
  * @throws \TokenReflection\Exception\RuntimeException If requested parameter doesn't exist.
  */
 public static function export(Broker $broker, $class, $method, $return = false)
 {
     $className = is_object($class) ? get_class($class) : $class;
     $methodName = $method;
     $class = $broker->getClass($className);
     if ($class instanceof Invalid\ReflectionClass) {
         throw new Exception\RuntimeException('Class is invalid.', Exception\RuntimeException::UNSUPPORTED);
     } elseif ($class instanceof Dummy\ReflectionClass) {
         throw new Exception\RuntimeException(sprintf('Class %s does not exist.', $className), Exception\RuntimeException::DOES_NOT_EXIST);
     }
     $method = $class->getMethod($methodName);
     if ($return) {
         return $method->__toString();
     }
     echo $method->__toString();
 }
コード例 #5
0
 /**
  * Exports a reflected object.
  *
  * @param \TokenReflection\Broker $broker Broker instance
  * @param string|object $className Class name or class instance
  * @param boolean $return Return the export instead of outputting it
  * @return string|null
  * @throws \TokenReflection\Exception\RuntimeException If requested parameter doesn't exist.
  */
 public static function export(Broker $broker, $className, $return = false)
 {
     if (is_object($className)) {
         $className = get_class($className);
     }
     $class = $broker->getClass($className);
     if ($class instanceof Invalid\ReflectionClass) {
         throw new Exception\RuntimeException('Class is invalid.', Exception\RuntimeException::UNSUPPORTED);
     } elseif ($class instanceof Dummy\ReflectionClass) {
         throw new Exception\RuntimeException('Class does not exist.', Exception\RuntimeException::DOES_NOT_EXIST);
     }
     if ($return) {
         return $class->__toString();
     }
     echo $class->__toString();
 }
コード例 #6
0
 /**
  * Tests getting of static variables.
  */
 public function testStaticVariables()
 {
     static $testName = 'staticVariables';
     $rfl = $this->getMethodReflection($testName);
     $this->assertSame($rfl->internal->getStaticVariables(), $rfl->token->getStaticVariables());
     $this->assertSame(array('string' => 'string', 'integer' => 1, 'float' => 1.1, 'boolean' => true, 'null' => null, 'array' => array(1 => 1), 'array2' => array(1 => 1, 2 => 2), 'constants' => array('self constant', 'parent constant')), $rfl->token->getStaticVariables());
     // The same test with parsing method bodies turned off
     $broker = new Broker(new Broker\Backend\Memory(), Broker::OPTION_DEFAULT & ~Broker::OPTION_PARSE_FUNCTION_BODY);
     $broker->processFile($this->getFilePath($testName));
     $reflection = $broker->getClass($this->getClassName($testName))->getMethod($this->getMethodName($testName));
     $this->assertSame(array(), $reflection->getStaticVariables());
 }
コード例 #7
0
 /**
  * Creates a reflection instance.
  *
  * @param \ReflectionClass $internalReflection Internal reflection instance
  * @param \TokenReflection\Broker $broker Reflection broker instance
  * @return \TokenReflection\Php\ReflectionClass
  * @throws \TokenReflection\Exception\RuntimeException If an invalid internal reflection object was provided.
  */
 public static function create(Reflector $internalReflection, Broker $broker)
 {
     if (!$internalReflection instanceof InternalReflectionClass) {
         throw new Exception\RuntimeException('Invalid reflection instance provided, ReflectionClass expected.', Exception\RuntimeException::INVALID_ARGUMENT);
     }
     return $broker->getClass($internalReflection->getName());
 }
コード例 #8
0
 private function getTokenizedReflectionClass(\ReflectionClass $class)
 {
     $this->broker->processFile($class->getFileName());
     return $this->broker->getClass($class->name);
 }