/** * * @param string $class * @param array $config * @return ClassAnnotationHolder */ public function parse($class, array $config = array()) { $annotationManager = new AnnotationManager(); $parser = new DoctrineAnnotationParser(); $parser->registerAnnotation(Route::class); $parser->registerAnnotation(Service::class); $parser->registerAnnotation(Controller::class); $parser->registerAnnotation(ControllerPlugin::class); $parser->registerAnnotation(Filter::class); $parser->registerAnnotation(FormElement::class); $parser->registerAnnotation(Hydrator::class); $parser->registerAnnotation(InputFilter::class); $parser->registerAnnotation(LogProcessor::class); $parser->registerAnnotation(LogWriter::class); $parser->registerAnnotation(Route::class); $parser->registerAnnotation(RoutePlugin::class); $parser->registerAnnotation(Serializer::class); $parser->registerAnnotation(Validator::class); $parser->registerAnnotation(ViewHelper::class); $annotationManager->attach($parser); $scanner = new DirectoryScanner('.'); $class = $scanner->getClass($class); $eventManager = new EventManager(); $parser = new ClassParser($config, $annotationManager, $eventManager); return $this->handleClassAnnotations($parser->parseClass($class), $config); }
/** * Create default annotation manager * * @return AnnotationManager */ public function createDefaultAnnotationManager() { $annotationManager = new AnnotationManager(); $parser = new GenericAnnotationParser(); $parser->registerAnnotation(new Annotation\Inject()); $annotationManager->attach($parser); return $annotationManager; }
/** * @param ServiceLocatorInterface $serviceLocator * @return AnnotationManager */ public function createService(ServiceLocatorInterface $serviceLocator) { $annotationManager = new AnnotationManager(); $parser = new DoctrineAnnotationParser(); $parser->registerAnnotation('AnnotatedRouter\\Annotation\\Route'); $annotationManager->attach($parser); return $annotationManager; }
/** * Set annotation manager to use when building form from annotations * * @param AnnotationManager $annotationManager * @return AnnotationBuilder */ public function setAnnotationManager(AnnotationManager $annotationManager) { foreach ($this->defaultAnnotations as $annotationName) { $class = __NAMESPACE__ . '\\' . $annotationName; $annotationManager->registerAnnotation(new $class()); } $this->annotationManager = $annotationManager; return $this; }
/** * Set annotation manager to use when building form from annotations * * @param AnnotationManager $annotationManager * @return AnnotationBuilder */ public function setAnnotationManager(AnnotationManager $annotationManager) { $parser = new Parser\DoctrineAnnotationParser(); foreach ($this->defaultAnnotations as $annotationName) { $class = __NAMESPACE__ . '\\' . $annotationName; $parser->registerAnnotation($class); } $annotationManager->attach($parser); $this->annotationManager = $annotationManager; return $this; }
public function testScannerWorks() { $annotationManager = new AnnotationManager(); $parser = new GenericAnnotationParser(); $parser->registerAnnotations(array($foo = new TestAsset\Annotation\Foo(), $bar = new TestAsset\Annotation\Bar())); $annotationManager->attach($parser); $docComment = '/**' . "\n" . ' * @Test\\Foo(\'anything I want()' . "\n" . ' * to be\')' . "\n" . ' * @Test\\Bar' . "\n */"; $nameInfo = new NameInformation(); $nameInfo->addUse('ZendTest\\Code\\Scanner\\TestAsset\\Annotation', 'Test'); $annotationScanner = new AnnotationScanner($annotationManager, $docComment, $nameInfo); $this->assertEquals(get_class($foo), get_class($annotationScanner[0])); $this->assertEquals("'anything I want()\n to be'", $annotationScanner[0]->getContent()); $this->assertEquals(get_class($bar), get_class($annotationScanner[1])); }
protected function scan(array $tokens) { $annotations = array(); $annotationIndex = -1; $contentEnd = false; reset($tokens); SCANNER_TOP: $token = current($tokens); switch ($token[0]) { case 'ANNOTATION_CLASS': $contentEnd = false; $annotationIndex++; $class = substr($token[1], 1); $class = $this->nameInformation->resolveName($class); $annotations[$annotationIndex] = array($class, null); goto SCANNER_CONTINUE; case 'ANNOTATION_CONTENT_START': $annotations[$annotationIndex][1] = ''; case 'ANNOTATION_CONTENT_END': case 'ANNOTATION_CONTENT': case 'ANNOTATION_WHITESPACE': case 'ANNOTATION_NEWLINE': if (!$contentEnd && isset($annotations[$annotationIndex]) && is_string($annotations[$annotationIndex][1])) { $annotations[$annotationIndex][1] .= $token[1]; } if ($token[0] === 'ANNOTATION_CONTENT_END') { $contentEnd = true; } goto SCANNER_CONTINUE; } SCANNER_CONTINUE: if (next($tokens) === false) { goto SCANNER_END; } goto SCANNER_TOP; SCANNER_END: foreach ($annotations as $annotation) { if ($this->annotationManager->hasAnnotation($annotation[0])) { $this->append( $this->annotationManager->createAnnotation($annotation[0], trim($annotation[1], '()')) ); } } }
public function testAnnotationScanningIsPossible() { $manager = new AnnotationManager(); $parser = new GenericAnnotationParser(); $parser->registerAnnotation(new TestAsset\SampleAnnotation()); $manager->attach($parser); $property = new \Zend\Code\Reflection\PropertyReflection('ZendTest\\Code\\Reflection\\TestAsset\\TestSampleClass2', '_prop2'); $annotations = $property->getAnnotations($manager); $this->assertInstanceOf('Zend\\Code\\Annotation\\AnnotationCollection', $annotations); $this->assertTrue($annotations->hasAnnotation('ZendTest\\Code\\Reflection\\TestAsset\\SampleAnnotation')); $found = false; foreach ($annotations as $key => $annotation) { if (!$annotation instanceof TestAsset\SampleAnnotation) { continue; } $this->assertEquals(get_class($annotation) . ': {"foo":"bar"}', $annotation->content); $found = true; break; } $this->assertTrue($found); }
public function getServiceConfig() { return array('factories' => array('zf2clientmoysklad_module_options' => function ($sm) { $config = $sm->get('config'); return new ModuleOptions(isset($config['zf2clientmoysklad']) ? $config['zf2clientmoysklad'] : array()); }, 'zf2clientmoysklad_metadata_collection' => function () { $directoryScanner = new DirectoryScanner(__DIR__ . '/src/Zf2ClientMoysklad/Entity'); $annotationManager = new AnnotationManager(); $annotationManager->attach(new AnnotationParser()); $collector = new EntityCollector($annotationManager, $directoryScanner); return new MetadataCollection($collector); }, 'zf2clientmoysklad_entity_manager' => function ($sm) { $mapper = new GenericMapper($sm->get('zf2clientmoysklad_generic_transport')); $metadataCollection = $sm->get('zf2clientmoysklad_metadata_collection'); return new EntityManager(new UnitOfWork($metadataCollection, $mapper), $metadataCollection); }, 'zf2clientmoysklad_generic_transport' => function ($sm) { $client = new \Zend\Http\Client(); $options = $sm->get('zf2clientmoysklad_module_options'); return new GenericTransport($options, $client); })); }
/** * @param array $tokens */ protected function scan(array $tokens) { $annotations = []; $annotationIndex = -1; $contentEnd = false; reset($tokens); SCANNER_TOP: $token = current($tokens); switch ($token[0]) { case 'ANNOTATION_CLASS': $contentEnd = false; $annotationIndex++; $class = substr($token[1], 1); $class = $this->nameInformation->resolveName($class); $annotations[$annotationIndex] = [$class, null]; goto SCANNER_CONTINUE; // goto no break needed // goto no break needed case 'ANNOTATION_CONTENT_START': $annotations[$annotationIndex][1] = ''; // fall-through // fall-through case 'ANNOTATION_CONTENT_END': case 'ANNOTATION_CONTENT': case 'ANNOTATION_WHITESPACE': case 'ANNOTATION_NEWLINE': if (!$contentEnd && isset($annotations[$annotationIndex]) && is_string($annotations[$annotationIndex][1])) { $annotations[$annotationIndex][1] .= $token[1]; } if ($token[0] === 'ANNOTATION_CONTENT_END') { $contentEnd = true; } goto SCANNER_CONTINUE; // goto no break needed } SCANNER_CONTINUE: if (next($tokens) === false) { goto SCANNER_END; } goto SCANNER_TOP; SCANNER_END: foreach ($annotations as $annotation) { $annotation[] = '@' . $annotation[0] . $annotation[1]; $annotationObject = $this->annotationManager->createAnnotation($annotation); if ($annotationObject) { $this->append($annotationObject); } } }
public function createDefaultAnnotationManager() { $annotationManager = new AnnotationManager; $annotationManager->registerAnnotation(new Annotation\Inject()); return $annotationManager; }
public function testManagerAllowsPassingArrayOfAnnotationInstancesToConstructor() { $manager = new Annotation\AnnotationManager(array(new TestAsset\Foo(), new TestAsset\Bar())); $this->assertTrue($manager->hasAnnotation(__NAMESPACE__ . '\\TestAsset\\Foo')); $this->assertTrue($manager->hasAnnotation(__NAMESPACE__ . '\\TestAsset\\Bar')); }
/** * * @param array $annotations * @return AnnotationManager */ public static function factory(array $annotations) { $manager = new AnnotationManager(); $manager->attach(DoctrineAnnotationParserFactory::factory($annotations)); return $manager; }
use KJSencha\Direct\Remoting\Api\Factory\ApiBuilder; use KJSencha\Direct\DirectManager; use KJSencha\Service\TestEchoService; use KJSencha\Frontend\Bootstrap; use Zend\Cache\StorageFactory; use Zend\Code\Annotation\AnnotationManager; use Zend\Code\Annotation\Parser\DoctrineAnnotationParser; use Zend\ServiceManager\ServiceLocatorInterface; use Zend\ServiceManager\ServiceManager; return array('factories' => array('kjsencha.api' => 'KJSencha\\Service\\ApiFactory', 'kjsencha.componentmanager' => 'KJSencha\\Service\\ComponentManagerFactory', 'kjsencha.annotationmanager' => function () { $doctrineParser = new DoctrineAnnotationParser(); $doctrineParser->registerAnnotation('KJSencha\\Annotation\\Remotable'); $doctrineParser->registerAnnotation('KJSencha\\Annotation\\Interval'); $doctrineParser->registerAnnotation('KJSencha\\Annotation\\Formhandler'); $doctrineParser->registerAnnotation('KJSencha\\Annotation\\Group'); $annotationManager = new AnnotationManager(); $annotationManager->attach($doctrineParser); return $annotationManager; }, 'kjsencha.apibuilder' => function (ServiceLocatorInterface $sl) { /* @var $annotationManager AnnotationManager */ $annotationManager = $sl->get('kjsencha.annotationmanager'); /* @var $directManager DirectManager */ $directManager = $sl->get('kjsencha.direct.manager'); return new ApiBuilder($annotationManager, $directManager); }, 'kjsencha.cache' => function (ServiceLocatorInterface $sl) { $config = $sl->get('Config'); $storage = StorageFactory::factory($config['kjsencha']['cache']); return $storage; }, 'kjsencha.bootstrap' => function (ServiceLocatorInterface $sl) { $config = $sl->get('Config'); $bootstrap = new Bootstrap($config['kjsencha']['bootstrap']['default']);