vendor/doctrine-common/UPGRADE_TO_2_1
author ymh <ymh.work@gmail.com>
Sun, 06 Nov 2011 23:44:37 +0100
changeset 27 1df556b2c0f9
parent 0 7f95f8617b0b
permissions -rwxr-xr-x
Correct memory problem
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
This document details all the possible changes that you should investigate when updating
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
your project from Doctrine Common 2.0.x to 2.1
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
## AnnotationReader changes
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
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:
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
    $reader = new \Doctrine\Common\Annotations\AnnotationReader();
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
    $reader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
    // new code necessary starting here
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
    $reader->setIgnoreNotImportedAnnotations(true);
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
    $reader->setEnableParsePhpImports(false);
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
    $reader = new \Doctrine\Common\Annotations\CachedReader(
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
        new \Doctrine\Common\Annotations\IndexedReader($reader), new ArrayCache()
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
    );
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
## Annotation Base class or @Annotation
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
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.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
## Removed methods on AnnotationReader
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
* AnnotationReader::setAutoloadAnnotations()
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
* AnnotationReader::getAutoloadAnnotations()
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
* AnnotationReader::isAutoloadAnnotations()
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
## AnnotationRegistry
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
Autoloading through the PHP autoloader is removed from the 2.1 AnnotationReader. Instead you have to use the global AnnotationRegistry for loading purposes:
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    \Doctrine\Common\Annotations\AnnotationRegistry::registerFile($fileWithAnnotations);
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespace($namespace, $dirs = null);
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
    \Doctrine\Common\Annotations\AnnotationRegistry::registerAutoloadNamespaces($namespaces);
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
    \Doctrine\Common\Annotations\AnnotationRegistry::registerLoader($callable);
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
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.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
The registerAutoloadNamespace function registers a PSR-0 compatible silent autoloader for all classes with the given namespace in the given directories.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
If null is passed as directory the include path will be used.
7f95f8617b0b first commit
ymh <ymh.work@gmail.com>
parents:
diff changeset
    39