UPATED 7/21/2011 Guilherme Blanco has updated Bisna. It now works with Doctrine 2.1.0. Just download it from github. It now incorporates the changes mentioned below as of 7/21/2011.
The Bisna library integrates Zend Framework version 1.x and the Doctrine 2 ORM; however, it dids not work properly with version 2.1.0 of the DoctrineCommon package. This article shows how to get it to work.
(actually, this article is now obsolete because Bisna now works with Doctrine 2.1.0)
Bisna can be downloaded from github. To check your version of DoctrineCommon issue this command from the command line
sudo pear list -c pear.doctrine-project.org
If the version of pear.doctrine-project.org/DoctrineCommon is 2.1.0 (or higher), then you will need to change the startORMMetadata method in library/Bisna/Application/Container/DoctrineContainer.php.
Add the four lines of code mentioned by Ben Eberlei at https://github.com/doctrine/doctrine2/blob/master/UPGRADE_TO_2_1. Modify this section of startORMMetadata()
// snip...
// only the relevent section of startORMMetadata is shown here
if ($reflClass->getName() == 'Doctrine\ORM\Mapping\Driver\AnnotationDriver'
|| $reflClass->isSubclassOf('Doctrine\ORM\Mapping\Driver\AnnotationDriver')) {
$annotationReaderClass = $driver['annotationReaderClass'];
$annotationReader = new annotationReaderClass($this->getCacheInstance($driver['annotationReaderCache']));
$annotationReader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
foreach ($driver['annotationReaderNamespaces'] as $alias => $namespace) {
$annotationReader->setAnnotationNamespaceAlias($namespace, $alias);
}
to look like this
if ($reflClass->getName() == 'Doctrine\ORM\Mapping\Driver\AnnotationDriver' ||
$reflClass->isSubclassOf('Doctrine\ORM\Mapping\Driver\AnnotationDriver')) {
// For 2.1 add this line
\Doctrine\Common\Annotations\AnnotationRegistry::registerFile('Doctrine/ORM/Mapping/Driver/DoctrineAnnotations.php');
$annotationReaderClass = $driver['annotationReaderClass'];
$annotationReader = new annotationReaderClass($this->getCacheInstance($driver['annotationReaderCache']));
$annotationReader->setDefaultAnnotationNamespace('Doctrine\ORM\Mapping\\');
// For 2.1 add the following three lines:
$annotationReader->setIgnoreNotImportedAnnotations(true);
$annotationReader->setEnableParsePhpImports(false);
$annotationReader = new \Doctrine\Common\Annotations\CachedReader(
new \Doctrine\Common\Annotations\IndexedReader($annotationReader),
new \Doctrine\Common\Cache\ArrayCache());
foreach ($driver['annotationReaderNamespaces'] as $alias => $namespace) {
$annotationReader->setAnnotationNamespaceAlias($namespace, $alias);
}
Thanks so much for this!
So, in a production environment, would it be smart to swap line 18 in the second snippet with this?:
new \Doctrine\Common\Cache\ApcCache());
Comment by Matthew — July 20, 2011 @ 5:00 pm |
You are quite welcome for the article. Thank you for your comment. No, line 18 has nothing to do with the overall caching policy of the ORM. In Bisna the caching policy is controlled by this entry in the configs/application.ini:
resources.doctrine.cache.instances.default.adapterClass = “Doctrine\Common\Cache\ArrayCache”
In a production environment you do want to change this line. If you have APC installed, then it should be:
resources.doctrine.cache.instances.default.adapterClass = “Doctrine\Common\Cache\ApcCache”
You, of course, will also need to change this line
resources.doctrine.orm.entityManagers.default.proxy.autoGenerateClasses = true
It needs to be false, in a production environment. Line 18 involves the annotations reader, which is only used when proxies are auto-generated or when the doctrine command line tool is used to generate the proxies. In a production environment you should have already manually generated your proxies by running the doctrine command line tool. Bisna has its own
version of the command line tool, doctrine.php. Thus, you should have already done
# php scripts/doctrine.php orm:generate-proxies
If you have repositories annotated in your entities, you will also need to
# php scripts/doctrine.php orm:generate-repositories library/
The line above depends on the directory from which you execute the command. If you are in the script directory already, then
# php ./doctrine.php orm:generate-repositories ../library/
is what you want. Also be sure to do:
# php scripts/doctrine.php orm:ensure-production-settings
I believe the author of Bisna intends to soon update library on Github. I don’t know if that has been done already? Also the article I wrote about “Using Custom Types” and “Using Custom Types with Bisna” doesn’t work with Doctrine 2.1 (because, I believe, of a bug in Doctrine 2.1).
Comment by kkruecke — July 20, 2011 @ 6:10 pm |
I have corrected the article Create Doctrine 2.1 custom types for MySQL enums. It includes a small sample program.
Comment by kkruecke — July 20, 2011 @ 11:08 pm |
If you having a very strange error saying:
Warning: require(Bisna/Doctrine/Container.php): failed to open stream: No such file or directory in /…/…/library/Doctrine/Common/ClassLoader.php
It looks like the file doesn’t exist while it does, but in my case the permissions of the Doctrine directory in library/Bisna/Doctrine were wrong. Changing this to 775 with chmod solved the problem.
Cheers!
Comment by Kees Schepers — October 21, 2011 @ 9:28 am |
i had been wrestling with an “Annotation Not Found” exception, and i didn’t know where exactly where to put that snippet of code.
thanks a million!
Comment by Jeremias — December 30, 2011 @ 7:26 am |
Glad it helped you.
Comment by kkruecke — December 30, 2011 @ 9:34 am |