学说2.自动生成代理 [英] Doctrine 2. Auto generating proxies

查看:124
本文介绍了学说2.自动生成代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题。我想关闭在Doctrine 2中自动生成我的代理。我发现这行代码应该做(并且)的诀窍:

 组$ config->(APPPATHSYSTEM /代理)setProxyDir; 
$ config-> setProxyNamespace('Proxies');

//自动生成代理开发
$ config-> setAutoGenerateProxyClasses(DEVELOPMENT);

在我的测试环境中,代理位于应用程序/代理。即:

  application / proxies / BaseUserProxy.php 

当我在现场环境中时,我的代码突然在应用程序/代理/代理上搜索不在实际位置的代理。



我明白它与命名空间有关,但我不明白为什么使用 setAutoGenerateProxy 方法时的行为不同。



任何想法?



编辑



我使用以下方法生成了新的代理:

  orm:generate-proxies 

选项。



哪个给了我这个输出:

  php doctrine.php orm :generate-proxies 
处理实体Base\Element
处理实体Base\Page
...
处理实体Base\Site

生成到/ var / www / application / proxies的代理类

最后一行,代理在/ var / www / application / proxy中生成。目录列表如下所示:

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

所以没有额外的Proxies目录。但是当我刷新我的网页时,它认为有,它给我以下错误:

 警告:require(/ var / www /application//proxies/Proxies/BaseUserProxy.php)
[function.require]:无法打开流:
/ var / www / library / Doctrine / Common / ClassLoader中没有这样的文件或目录。 php on line 148

为什么添加了额外的Proxies目录?如果我在每个请求上生成代理,它不会在额外的Proxies目录中查找。任何人?



@Bryan M。:这不是解决方案,而是解决方法。此外,它不行。在生成代理时,如果应用您的建议,将在APPPATHSYSTEM中生成代理,我的webapp将尝试从APPPATHSYSTEM加载它们。代理。问题是如果我使用以下方式,系统会在不同的位置查找代理:

  $ config-> setAutoGenerateProxyClasses(DEVELOPMENT) ; 

如果DEVELOPMENT为真,它将会看APPPATHSYSTEM。如果DEVELOPMENT设置为false,它将会看APPPATHSYSTEM。代理。只需切换DEVELOPMENT constance就可以打破我的应用程序,理论上应该是不可能的。

解决方案

如果将文件夹重命名为 / 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.

这篇关于学说2.自动生成代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆