带有句点的目录会破坏基于 Zend Framework 中命名空间的自动加载解析吗?
我的库文件夹中有一个以我的网站命名的文件夹。文件夹路径类似于:
~\www\library\myWebsite.com
如果我使用 Zend 自动加载器加载库路径中所有内容的命名空间,那么从该文件中自动加载具有如下命名空间的类时是否会遇到任何问题:
\myWebsite.com\myClass::myFunction();
我在网上查找了这方面的文档,但找不到任何有关以这种方式使用句点的信息。
I have a folder in my library folder which is named after my website. The folder path is like:
~\www\library\myWebsite.com
If I'm using Zend autoloader to load the namespace of everything in the library path, will I have any trouble autoloading a class from that file with a namespace like this:
\myWebsite.com\myClass::myFunction();
I have looked online for documentation on this and I can't find any info about using periods in this way.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我试过了,复杂的是PHP。我认为 Zend 正在注册命名空间,因为当我调用 \Zend_Load_Autoloader::getRegisteredNamespaces() 时,它显示它已注册。但是当我从完全限定的命名空间调用静态方法时,php 给出了这样的错误:
似乎 PHP 在解析期间正在终止命名空间标识符。 (句点字符)。这令人失望,因为对我来说,拥有一个以网站命名的库对我的设计很重要。
我会将目录重命名为 myWebsitecom,或者可能将 .com 设为自己的子目录,如
myWebsite\com 并将其合并到我的命名空间树中,如: \MyNamespace\Com\MyClass::myFunction();
I tried it and the complication is in PHP. I think Zend is registering the namespace fine, because when I call \Zend_Load_Autoloader::getRegisteredNamespaces() it shows that it's registered. but when I call the static method from the fully qualified namespace, php gives an error of this:
It seems like PHP is terminating the namespace identifier, during parsing, at the . (period character). This is dissapointing because to me having a library named after the website was important to my design.
I will rename the directory to myWebsitecom or possibly make the .com it's own sub directory like
myWebsite\com and incorporate that into my namespace tree like: \MyNamespace\Com\MyClass::myFunction();
找出答案的最简单方法就是尝试一下。
如果它不起作用,您始终可以编写一个自定义自动加载器来使其起作用。我对 php 命名空间没有太多经验,但是自动加载器看起来像这样(我想你必须稍微修改一下才能确定给定类名的正确文件路径):
然后将其放入引导程序中:
如果这个类必须位于 myWebsite.com 目录中,您也可以作弊并在其中添加一个 require :
The easiest way to find out is to try it.
If it doesn't work, you could always write a custom autoloader to make it work. I don't have much experience with php namespaces, but the autoloader would look something like this (I imagine you'll have to tinker with it a bit to determine the correct file path given the class name):
then put this in your bootstrap:
and if this class must be in that myWebsite.com directory, you could just cheat and throw in a require in there too: