[英]Coexisting spl_autoload_register and composer autoload
I got a legacy app which use spl_autload
in order to load classes (they have no namespace) 我有一个遗留应用程序,它使用
spl_autload
来加载类(它们没有命名空间)
<?php
spl_autoload_extensions('.class.php,.php');
set_include_path(
$listOfDir
);
spl_autoload_register();
// require composer autoloader
// can't place that line before the call spl_autoload_register without breaking everything.
require __DIR__ . "/../vendor/autoload.php";
We recently introduced composer and Symfony container
, dependency-injection
and config
component. 我们最近介绍了composer和Symfony
container
, dependency-injection
和config
组件。
What I try to achieve is to have camelcase class loaded via composer (all new classes use camel cases to identify new vs legacy code) without causing BC breaks. 我试图实现的是通过composer加载camelcase类(所有新类使用驼峰案例来识别新旧代码)而不会导致BC中断。
Do you have clues on how to get this working ? 你有关于如何使这个工作的线索? Do new classes must have a namespace ?
新类必须具有命名空间吗?
PS: New classes will spread accross "tons" of folders. PS:新课程将在“吨”文件夹中传播。 The project size is 700k LOC.
项目规模为700k LOC。
So What I did is to put new class inside a src/
folder, add a namespace and add PSR-4
inside composer.json. 所以我做的是将新类放在
src/
文件夹中,添加命名空间并在composer.json中添加PSR-4
。
Because spl_autoload does not work with camelcase classes, i'm fine with that. 因为spl_autoload不适用于camelcase类,所以我很好。 :-)
:-)
"autoload": {
"psr-4": {
"MyNamespace\\NotLegacy\\": "src/"
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.