Doctrine\OXM\Configuration::newDefaultAnnotationDriver PHP Method

newDefaultAnnotationDriver() public method

Add a new default annotation driver with a correctly configured annotation reader.
public newDefaultAnnotationDriver ( array $paths = [] ) : AnnotationDriver
$paths array
return Doctrine\OXM\Mapping\Driver\AnnotationDriver
    public function newDefaultAnnotationDriver($paths = array())
    {
        if (version_compare(\Doctrine\Common\Version::VERSION, '3.0.0-DEV', '>=')) {
            // Register the ORM Annotations in the AnnotationRegistry
            AnnotationRegistry::registerFile(__DIR__ . '/Mapping/Driver/DoctrineAnnotations.php');
            $reader = new AnnotationReader();
            $reader = new \Doctrine\Common\Annotations\CachedReader($reader, new ArrayCache());
        } else {
            if (version_compare(\Doctrine\Common\Version::VERSION, '2.1.0-DEV', '>=')) {
                // Register the ORM Annotations in the AnnotationRegistry
                AnnotationRegistry::registerFile(__DIR__ . '/Mapping/Driver/DoctrineAnnotations.php');
                $reader = new AnnotationReader();
                $reader->setDefaultAnnotationNamespace('Doctrine\\OXM\\Mapping\\');
                $reader->setIgnoreNotImportedAnnotations(true);
                $reader->setEnableParsePhpImports(false);
                $reader = new \Doctrine\Common\Annotations\CachedReader(new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache());
            } else {
                $reader = new AnnotationReader();
                $reader->setDefaultAnnotationNamespace('Doctrine\\OXM\\Mapping\\');
            }
        }
        return new AnnotationDriver($reader, (array) $paths);
    }

Usage Example

Example #1
0
 public function setUp()
 {
     $config = new Configuration();
     $config->setMetadataDriverImpl($config->newDefaultAnnotationDriver("tests/Doctrine/Tests/OXM/Entities"));
     $config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache());
     $this->metadataFactory = new ClassMetadataFactory($config);
     $this->marshaller = new XmlMarshaller($this->metadataFactory);
 }