Last active
December 19, 2015 03:29
-
-
Save enumag/5890464 to your computer and use it in GitHub Desktop.
Doctrine Annotations Extension
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| /** | |
| * This file is part of the Kdyby (http://www.kdyby.org) | |
| * | |
| * Copyright (c) 2008 Filip Procházka (filip@prochazka.su) | |
| * | |
| * For the full copyright and license information, please view the file license.txt that was distributed with this source code. | |
| */ | |
| namespace Kdyby\Annotations\DI; | |
| use Doctrine; | |
| use Kdyby; | |
| use Nette; | |
| use Nette\PhpGenerator as Code; | |
| use Nette\Utils\Validators; | |
| if (!class_exists('Nette\DI\CompilerExtension')) { | |
| class_alias('Nette\Config\CompilerExtension', 'Nette\DI\CompilerExtension'); | |
| class_alias('Nette\Config\Configurator', 'Nette\Configurator'); | |
| class_alias('Nette\Config\Compiler', 'Nette\DI\Compiler'); | |
| class_alias('Nette\Config\Helpers', 'Nette\DI\Config\Helpers'); | |
| } | |
| /** | |
| * @author Filip Procházka <filip@prochazka.su> | |
| * @author Jáchym Toušek <enumag@gmail.com> | |
| */ | |
| class AnnotationsExtension extends Nette\DI\CompilerExtension | |
| { | |
| /** @var array */ | |
| public $defaults = array( | |
| 'ignored' => array( | |
| 'persistent', | |
| 'serializationVersion', | |
| ), | |
| 'debug' = '%debugMode%', | |
| ); | |
| public function loadConfiguration() | |
| { | |
| $builder = $this->getContainerBuilder(); | |
| $config = $this->getConfig($this->defaults); | |
| $builder->addDefinition($this->prefix('annotation.reflectionReader')) | |
| ->setClass('Doctrine\Common\Annotations\AnnotationReader') | |
| ->setAutowired(FALSE); | |
| Validators::assertField($config, 'ignored', 'array'); | |
| foreach ($config['ignored'] as $annotationName) { | |
| $builder->getDefinition($this->prefix('annotation.reflectionReader')) | |
| ->addSetup('addGlobalIgnoredName', array($annotationName)); | |
| } | |
| $builder->addDefinition($this->prefix('annotation.reader')) | |
| ->setClass('Doctrine\Common\Annotations\Reader') | |
| ->setFactory('Doctrine\Common\Annotations\CachedReader', array( | |
| new Nette\DI\Statement('Doctrine\Common\Annotations\IndexedReader', array($this->prefix('@annotation.reflectionReader'))), | |
| new Nette\DI\Statement('Kdyby\Doctrine\Cache', array( | |
| '@Nette\Caching\IStorage', | |
| 'Doctrine.Annotations', | |
| $config['debug'] | |
| )), | |
| $config['debug'] | |
| )) | |
| ->setInject(FALSE); | |
| } | |
| public function afterCompile(Code\ClassType $class) | |
| { | |
| $init = $class->methods['initialize']; | |
| $init->addBody('Doctrine\Common\Annotations\AnnotationRegistry::registerLoader("class_exists");'); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #dříve | |
| extensions: | |
| kdyby.console: Kdyby\Console\DI\ConsoleExtension | |
| kdyby.events: Kdyby\Events\DI\EventsExtension | |
| kdyby.doctrine: Kdyby\Doctrine\DI\OrmExtension | |
| parameters: | |
| kdyby.doctrine.debug: no | |
| kdyby.doctrine: | |
| ignoredAnnotations: | |
| - myannotation | |
| #nyní | |
| extensions: | |
| kdyby.console: Kdyby\Console\DI\ConsoleExtension | |
| kdyby.events: Kdyby\Events\DI\EventsExtension | |
| kdyby.annotations: Kdyby\Annotations\DI\AnnotationsExtension | |
| kdyby.doctrine: Kdyby\Doctrine\DI\OrmExtension | |
| kdyby.annotations: | |
| debug: no | |
| ignored: | |
| - myannotation |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment