Esempio n. 1
0
 public function testPropertyScannerHasPropertyInformation()
 {
     $file = new FileScanner(__DIR__ . '/../TestAsset/FooClass.php');
     $class = $file->getClass('ZendTest\\Code\\TestAsset\\FooClass');
     $property = $class->getProperty('bar');
     $this->assertEquals('bar', $property->getName());
     $this->assertEquals('value', $property->getValue());
     $this->assertFalse($property->isPublic());
     $this->assertTrue($property->isProtected());
     $this->assertFalse($property->isPrivate());
     $this->assertTrue($property->isStatic());
     $property = $class->getProperty('foo');
     $this->assertEquals('foo', $property->getName());
     $this->assertEquals('value2', $property->getValue());
     $this->assertTrue($property->isPublic());
     $this->assertFalse($property->isProtected());
     $this->assertFalse($property->isPrivate());
     $this->assertFalse($property->isStatic());
     $property = $class->getProperty('baz');
     $this->assertEquals('baz', $property->getName());
     $this->assertEquals(3, $property->getValue());
     $this->assertFalse($property->isPublic());
     $this->assertFalse($property->isProtected());
     $this->assertTrue($property->isPrivate());
     $this->assertFalse($property->isStatic());
 }
 public function testClassScannerReturnsPropertyWithNoDefault()
 {
     $file = new FileScanner(__DIR__ . '/../TestAsset/BazClass.php');
     $class = $file->getClass('BazClass');
     $method = $class->getMethod('__construct');
     $this->assertTrue($method->isPublic());
 }
Esempio n. 3
0
 public function testMethodScannerReturnsBodyMethods()
 {
     $file = new FileScanner(__DIR__ . '/../TestAsset/BarClass.php');
     $class = $file->getClass('ZendTest\\Code\\TestAsset\\BarClass');
     $method = $class->getMethod('three');
     $expected = "\n" . '        $x = 5 + 5;' . "\n" . '        $y = \'this string\';' . "\n    ";
     $this->assertEquals($expected, $method->getBody());
 }
Esempio n. 4
0
 public function testClassScannerReturnsMethodsWithMethodScanners()
 {
     $file = new FileScanner(__DIR__ . '/../TestAsset/FooClass.php');
     $class = $file->getClass('ZendTest\\Code\\TestAsset\\FooClass');
     $methods = $class->getMethods(true);
     foreach ($methods as $method) {
         $this->assertInstanceOf('Zend\\Code\\Scanner\\MethodScanner', $method);
     }
 }
Esempio n. 5
0
 public function testMethodScannerMethodSignatureLatestOptionalParamHasParentheses()
 {
     $file = new FileScanner(__DIR__ . '/../TestAsset/BarClass.php');
     $class = $file->getClass('ZendTest\\Code\\TestAsset\\BarClass');
     $method = $class->getMethod('four');
     $paramTwo = $method->getParameter(1);
     $optionalValue = $paramTwo->getDefaultValue();
     $this->assertEquals('array(array(array(\'default\')))', $optionalValue);
 }
Esempio n. 6
0
 public function testClassScannerCanReturnLineNumbers()
 {
     $file = new FileScanner(__DIR__ . '/../TestAsset/FooClass.php');
     $class = $file->getClass('ZendTest\\Code\\TestAsset\\FooClass');
     $this->assertEquals(11, $class->getLineStart());
     $this->assertEquals(23, $class->getLineEnd());
     $file = new FileScanner(__DIR__ . '/../TestAsset/BarClass.php');
     $class = $file->getClass('ZendTest\\Code\\TestAsset\\BarClass');
     $this->assertEquals(10, $class->getLineStart());
     $this->assertEquals(33, $class->getLineEnd());
 }
Esempio n. 7
0
 public function testConstantScannerHasConstantInformation()
 {
     $file = new FileScanner(__DIR__ . '/../TestAsset/FooClass.php');
     $class = $file->getClass('ZendTest\\Code\\TestAsset\\FooClass');
     $constant = $class->getConstant('BAR');
     $this->assertEquals('BAR', $constant->getName());
     $this->assertEquals(5, $constant->getValue());
     $constant = $class->getConstant('FOO');
     $this->assertEquals('FOO', $constant->getName());
     $this->assertEquals(5, $constant->getValue());
     $constant = $class->getConstant('BAZ');
     $this->assertEquals('BAZ', $constant->getName());
     $this->assertEquals('baz', $constant->getValue());
     $this->assertNotNull('Some comment', $constant->getDocComment());
 }
Esempio n. 8
0
 public function testParameterScannerHasParameterInformation()
 {
     $file = new FileScanner(__DIR__ . '/../TestAsset/BarClass.php');
     $class = $file->getClass('ZendTest\\Code\\TestAsset\\BarClass');
     $method = $class->getMethod('three');
     $parameter = $method->getParameter('t');
     $this->assertEquals('ZendTest\\Code\\TestAsset\\BarClass', $parameter->getDeclaringClass());
     $this->assertEquals('three', $parameter->getDeclaringFunction());
     $this->assertEquals('t', $parameter->getName());
     $this->assertEquals(2, $parameter->getPosition());
     $this->assertEquals('2', $parameter->getDefaultValue());
     $this->assertFalse($parameter->isArray());
     $this->assertTrue($parameter->isDefaultValueAvailable());
     $this->assertTrue($parameter->isOptional());
     $this->assertTrue($parameter->isPassedByReference());
 }
 /**
  * 
  * @param ModuleEvent $event
  */
 public function onMergeConfig(ModuleEvent $event)
 {
     $config = $event->getConfigListener()->getMergedConfig(false);
     $resolvedControllers = $this->resolveControllers($config);
     $controllerInvokables = empty($config['controllers']['invokables']) ? [] : $config['controllers']['invokables'];
     $controllerFactories = empty($config['controllers']['factories']) ? [] : $config['controllers']['factories'];
     $controllers = array_merge($controllerInvokables, $controllerFactories);
     $injections = array();
     foreach ($controllers as $controller) {
         $ref = new ReflectionClass($controller);
         $fileScanner = new FileScanner($ref->getFileName());
         $classScanner = $fileScanner->getClass($controller);
         $methods = $classScanner->getMethods();
         $className = $classScanner->getName();
         $controllerName = $resolvedControllers[$className];
         foreach ($methods as $method) {
             $methodName = $method->getName();
             $actionName = preg_replace('/Action$/', '', $methodName);
             foreach ($method->getParameters() as $parameter) {
                 $parameterScanner = $method->getParameter($parameter);
                 $parameterName = $parameterScanner->getName();
                 $class = $parameterScanner->getClass();
                 if ($class) {
                     $objectManager = $this->detectObjectManager($class, $config['mvc']['doctrine_object_injector']);
                     if (null !== $objectManager) {
                         $injections[$controllerName][$actionName][$parameterName] = [$class, $objectManager, !$parameterScanner->isOptional()];
                     }
                 } else {
                     $injections[$controllerName][$actionName][$parameterName] = null;
                 }
             }
         }
     }
     $config['mvc']['doctrine_object_injector']['injections'] = $injections;
     $event->getConfigListener()->setMergedConfig($config);
 }
 /**
  * @param  int|string $className
  * @return ClassScanner
  */
 public function getClass($className)
 {
     return $this->fileScanner->getClass($className);
 }
Esempio n. 11
0
 public function testClassScannerCanScanInterface()
 {
     $file  = new FileScanner(__DIR__ . '/../TestAsset/FooInterface.php');
     $class = $file->getClass('ZendTest\Code\TestAsset\FooInterface');
     $this->assertEquals('ZendTest\Code\TestAsset\FooInterface', $class->getName());
 }
 /**
  * Retrieve any traits used by the class.
  *
  * @return ClassScanner[]
  */
 public function getTraits()
 {
     if (!empty($this->traits)) {
         return $this->traits;
     }
     // get list of trait names
     $traitNames = $this->getTraitNames();
     foreach ($traitNames as $traitName) {
         $r = new ReflectionClass($traitName);
         if (!$r->isTrait()) {
             throw new Exception\RuntimeException(sprintf('Non-trait class detected as a trait: %s', $traitName));
         }
         $fileName = $r->getFileName();
         $file = new FileScanner($fileName);
         $this->traits[] = $file->getClass($traitName);
     }
     return $this->traits;
 }
Esempio n. 13
0
 public function testClassScannerCanScanAnnotations()
 {
     $file = new FileScanner(__DIR__ . '/../Annotation/TestAsset/EntityWithAnnotations.php');
     $class = $file->getClass('ZendTest\\Code\\Annotation\\TestAsset\\EntityWithAnnotations');
     $annotations = $class->getAnnotations($this->manager);
     $this->assertTrue($annotations->hasAnnotation('ZendTest\\Code\\Annotation\\TestAsset\\Foo'));
     $this->assertTrue($annotations->hasAnnotation('ZendTest\\Code\\Annotation\\TestAsset\\Bar'));
     $this->assertEquals('first', $annotations[0]->content);
     $this->assertEquals('second', $annotations[1]->content);
     $this->assertEquals('third', $annotations[2]->content);
 }
Esempio n. 14
0
 public function testFileScannerCanReturnClasses()
 {
     $tokenScanner = new FileScanner(__DIR__ . '/../TestAsset/MultipleNamespaces.php');
     $this->assertEquals('ZendTest\\Code\\TestAsset\\Baz', $tokenScanner->getClass('ZendTest\\Code\\TestAsset\\Baz')->getName());
     $this->assertEquals('Foo', $tokenScanner->getClass('Foo')->getName());
 }
Esempio n. 15
0
 /**
  * Builds and populates Action object based on the provided class name
  *
  * @param  string $className
  * @return Action
  */
 public function buildAction($className)
 {
     $classReflection = new ClassReflection($className);
     $scanner = new FileScanner($classReflection->getFileName(), $this->annotationManager);
     $classScanner = $scanner->getClass($classReflection->getName());
     $action = new Action($classScanner->getName());
     foreach ($classScanner->getMethods() as $classMethod) {
         if ($classMethod->isPublic() && $classMethod->getName() != '__construct') {
             $action->addMethod($this->buildMethod($classMethod));
         }
     }
     return $action;
 }