Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. i.e.:

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.

like image 989
Rene Terstegen Avatar asked Nov 04 '10 11:11

Rene Terstegen


2 Answers

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.

like image 121
timdev Avatar answered Sep 23 '22 03:09

timdev


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".

like image 24
Bryan M. Avatar answered Sep 23 '22 03:09

Bryan M.