简体   繁体   中英

Doctrine 2. Auto generating proxies

I have a strange problem. I want to turn off the auto generating of my proxies in Doctrine 2. I found this line of code that should do (and does) the trick:

$config->setProxyDir(APPPATHSYSTEM."/proxies");
$config->setProxyNamespace('Proxies');

// Auto generate proxies for development
$config->setAutoGenerateProxyClasses(DEVELOPMENT);

On my test environment the proxies are located at application/proxies . ie:

application/proxies/BaseUserProxy.php

When I'm on the live environment my code suddenly searches for the proxies at application/proxies/Proxies which is not the actual location.

I do understand it has something to do with the namespace, but I don't understand why it behaves differently when using the setAutoGenerateProxy method.

Any ideas?

edit

I did generate the new proxies using the:

orm:generate-proxies

option.

Which gave me this output:

php doctrine.php orm:generate-proxies
Processing entity "Base\Element"
Processing entity "Base\Page"
...
Processing entity "Base\Site"

Proxy classes generated to "/var/www/application/proxies"

Looking at the last line, the proxies are generated in /var/www/application/proxies. The directory listing looks like this:

BaseElementProxy.php
BasePageProxy.php
...
BaseSiteProxy.php

So there is no extra Proxies directory. But when I refresh my webpage it thinks there is, it gives me the following error:

Warning: require(/var/www/application//proxies/Proxies/BaseUserProxy.php) 
[function.require]: failed to open stream: 
No such file or directory in /var/www/library/Doctrine/Common/ClassLoader.php on line 148

Why is the extra Proxies directory added? If I do generate the proxies on each request it does not look in the extra Proxies directory. Anybody?

@Bryan M. : That is not a solution, but a workaround. Besides, it does not work. When generating the proxies they will, if applying your suggestion, be generated in APPPATHSYSTEM and my webapp will try to load them from APPPATHSYSTEM."Proxies". The problem is that the system looks for the proxies on different locations if I use:

$config->setAutoGenerateProxyClasses(DEVELOPMENT);

If DEVELOPMENT is true, it will look at APPPATHSYSTEM. If DEVELOPMENT set to false, it will look at APPPATHSYSTEM."Proxies". Just switching the DEVELOPMENT constance breaks my application, what theoretically should not be possible.

Are you developing on OS X and deploying to Linux? OS X's filesystem is case insensitive . So I'll often run into a problem where I mistype the case of a class, and it runs and passes just fine in the local environment, but chokes on our server.

So in this case, in OS X, the namespace "Proxies" is able to resolve to "/proxies", but in production, it can't find the class folder, and creates it under "/proxies/Proxies".

I don't think AutoGenerated proxies care.

Instead of pushing autogenerated proxies to production, you should probably doctrine orm:generate-proxies , which I suspect will put them in the place your production code is configured to look for them.

If you rename the folder to something called "/temp" you will realize the difference between path and namespace.

The path is the absolute path to the directory the proxies are getting generated into. The namespace is necessary to allow you to configure how an autoloader picks up these entities.

The path in your case has to be something like "proxies/Proxies" and the namespace is then "Proxies". Your autoloader has to be configured to listen to namespace prefix "Proxies" at directory "proxies/".

This is all mood with Doctrine 2 RC1 though, we found a way to explicitly load a proxy path without help of an autoloader at no additional cost. The Proxy Namespace configuratino is therefore only necessary to make sure no other classes are in the same namespace as the proxies.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM