且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

学说2.自动生成代理

更新时间:2022-10-14 23:13:28

如果将文件夹重命名为 / temp,您将意识到路径和命名空间之间的区别。



路径是代理生成的目录的绝对路径。命名空间是必要的,允许您配置自动装载机如何拾取这些实体。



您的案例中的路径必须像代理/代理和命名空间然后是代理。您的自动加载机必须被配置为在目录proxies /\".



上收听命名空间前缀Proxies,这是Doctrine 2 RC1的所有心情,但是我们发现了一种方式在没有自动加载机的帮助下,不需要额外的费用来显式加载代理路径。因此,代理名称空​​间配置只能确保没有其他类与代理相同的命名空间。


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.

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.