UPGRADE_TO_2_1 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. This document details all the possible changes that you should investigate when updating
  2. your project from Doctrine Common 2.0.x to 2.1
  3. ## AnnotationReader changes
  4. The annotation reader was heavily refactored between 2.0 and 2.1-RC1. In theory the operation of the new reader should be backwards compatible, but it has to be setup differently to work that way:
  5. $reader = new \Doctrine\Common\Annotations\AnnotationReader();
  6. $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
  7. // new code necessary starting here
  8. $reader->setIgnoreNotImportedAnnotations(true);
  9. $reader->setEnableParsePhpImports(false);
  10. $reader = new \Doctrine\Common\Annotations\CachedReader(
  11. new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache()
  12. );
  13. ## Annotation Base class or @Annotation
  14. Beginning after 2.1-RC2 you have to either extend ``Doctrine\Common\Annotations\Annotation`` or add @Annotation to your annotations class-level docblock, otherwise the class will simply be ignored.
  15. ## Removed methods on AnnotationReader
  16. * AnnotationReader::setAutoloadAnnotations()
  17. * AnnotationReader::getAutoloadAnnotations()
  18. * AnnotationReader::isAutoloadAnnotations()
  19. ## AnnotationRegistry
  20. Autoloading through the PHP autoloader is removed from the 2.1 AnnotationReader. Instead you have to use the global AnnotationRegistry for loading purposes:
  21. \Doctrine\Common\Annotations\AnnotationRegistry::registerFile($fileWithAnnotations);
  22. \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace($namespace, $dirs = null);
  23. \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespaces($namespaces);
  24. \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader($callable);
  25. The $callable for registering a loader accepts a class as first and only parameter and must try to silently autoload it. On success true has to be returned.
  26. The registerAutoloadNamespace function registers a PSR-0 compatible silent autoloader for all classes with the given namespace in the given directories.
  27. If null is passed as directory the include path will be used.