Symfony 的自动加载供应商文件似乎不起作用
我正在构建一个 Symfony 1.4 项目,并尝试使用 PEAR 的 Crypt_RSA 包。不幸的是,该软件包已经有一段时间没有更新了,因此我不想从命令行执行简单的 pear install
,而是想将其包含到我的 lib/vendor
项目中路径,以便我可以修改 PHP5 中使用的各种代码。 (它目前会导致一些警告和严格错误,并且我不想禁用严格错误检查)。
我在 config
路径中创建了一个 autoload.yml
文件,该文件现在包含以下内容:
autoload:
Crypt_RSA:
path: %SF_LIB_DIR%/vendor/Crypt
recursive: true
然后我尝试利用 Crypt_RSA_KeyPair 类 (source) 的方式如下:
$keyPair = new Crypt_RSA_KeyPair(128);
这会导致以下错误:
警告:require_once(Crypt/RSA/ErrorHandler.php) [function.require-once]:无法打开流:/app_path/lib/vendor/Crypt/RSA/KeyPair.php 线上没有此类文件或目录 <强>28
致命错误:require_once() [函数。 require]:无法在 /app_path/lib/vendor/Crypt/RSA/ 中打开所需的 'Crypt/RSA/ErrorHandler.php' (include_path='.:/opt/local/lib/php') KeyPair.php 上线 28
查看 Crypt/RSA.php 文件 (source),它对 Crypt/RSA/ErrorHandler.php、Crypt/RSA/MathLoader.php、Crypt/RSA 有 require_once 调用/Key.php 和 Crypt/RSA/KeyPair.php,所以我想我不希望 symfony 自动加载所有内容(即:不递归自动加载)——只是 RSA.php 文件。但是,require_once 调用都是特定于包含 Crypt 文件夹的文件夹,这意味着自动加载需要确保加载 RSA.php 时,它从正确的路径加载它,以便可以正确加载每个文件。
考虑到这一点,我尝试了一些不同的设置,但没有成功:
autoload:
Crypt_RSA:
path: %SF_LIB_DIR%/vendor
files: [Crypt/RSA.php]
recursive: false
并且:
# moved "Crypt" folder into a subfolder named "pear"
autoload:
Crypt_RSA:
path: %SF_LIB_DIR%/vendor/pear
recursive: false
这些新尝试中的每一个都会导致不同的错误,即根本没有完全找到 Crypt_RSA_KeyPair 类。
致命错误:在/app_path/lib/model/doctrine/sfDoctrineGuardPlugin/sfGuardUser.class.php第70<行中找不到类“Crypt_RSA_KeyPair” /strong>
我尝试过深入研究文档,但我的大多数 Google 搜索都指向 1.0 而不是 1.4 的 Symfony 文档,并且所有文档在自动加载供应商文件方面通常都含糊其辞。
我想另一个选择是手动 require_once 我需要的 RSA.php 文件,但我猜这会打破 Symfony 约定,并且可能会做一些比我应该做的更难的事情(尽管这个自动加载的事情似乎比它更难)应该也是)。
I'm building a Symfony 1.4 project, and I'm attempting to use PEAR's Crypt_RSA package. Unfortunately, the package hasn't been updated in awhile, so instead of doing a simple pear install
from the command line, I want to include it into my lib/vendor
project path so that I can modify various pieces of code for use in PHP5. (It currently causes some warnings and strict errors, and I don't want to disable strict error checking).
I created an autoload.yml
file in my config
path that now contains the following:
autoload:
Crypt_RSA:
path: %SF_LIB_DIR%/vendor/Crypt
recursive: true
I then attempt to utilize the Crypt_RSA_KeyPair class (source) in the following manner:
$keyPair = new Crypt_RSA_KeyPair(128);
This results in the following error:
Warning: require_once(Crypt/RSA/ErrorHandler.php) [function.require-once]: failed to open stream: No such file or directory in /app_path/lib/vendor/Crypt/RSA/KeyPair.php on line 28
Fatal error: require_once() [function.require]: Failed opening required 'Crypt/RSA/ErrorHandler.php' (include_path='.:/opt/local/lib/php') in /app_path/lib/vendor/Crypt/RSA/KeyPair.php on line 28
Looking into the Crypt/RSA.php file (source), it has require_once calls for Crypt/RSA/ErrorHandler.php, Crypt/RSA/MathLoader.php, Crypt/RSA/Key.php, and Crypt/RSA/KeyPair.php, so I'm thinking I don't want symfony to autoload everything (i.e.: not autoload recursively) -- just the RSA.php file. However, the require_once calls are all specific to the folder containing the Crypt folder, meaning that the autoload needs to make sure that when RSA.php is loaded, it loads it from the proper path such that each of those files can be loaded correctly.
With this in mind, I tried a few different settings with no luck:
autoload:
Crypt_RSA:
path: %SF_LIB_DIR%/vendor
files: [Crypt/RSA.php]
recursive: false
and:
# moved "Crypt" folder into a subfolder named "pear"
autoload:
Crypt_RSA:
path: %SF_LIB_DIR%/vendor/pear
recursive: false
Each of these new attempts resulted in a different error whereby the Crypt_RSA_KeyPair class was simply not found altogether.
Fatal error: Class 'Crypt_RSA_KeyPair' not found in /app_path/lib/model/doctrine/sfDoctrineGuardPlugin/sfGuardUser.class.php on line 70
I've tried digging through the docs, but most of my Google searches point to Symfony docs for 1.0 rather than 1.4, and all of the docs are generally vague on autoloading vendor files.
I suppose another option would be to manually require_once the RSA.php file I need, but I'm guessing that would be breaking Symfony convention, and probably doing something harder than I should be (even though this autoloading thing seems to be harder than it should be too).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以尝试为 Crypt_RSA 供应商包创建自定义自动加载器,并将其注册到 ProjectConfiguration 中,因为它们 Jobeet 文档中提供(使用 Zend Lucene 时)。
You might try to create your custom autoloader for the Crypt_RSA vendor package and register it in the ProjectConfiguration, as they presented in the Jobeet documentation (when using Zend Lucene).