我为此要求制作了一个类,它与PSR-4兼容并遵循Wordpress编码标准。
您可以在这里到达:https :
//github.com/pablo-pacheco/wp-namespace-autoloader
解释就在那里,但基本上是作曲家的依赖。您只需要在项目中要求它即可:
"require": {
"pablo-pacheco/wp-namespace-autoloader": "dev-master"
}
然后叫课
<?php
new \WP_Namespace_Autoloader( array(
'directory' => __DIR__, // Directory of your project. It can be your theme or plugin. __DIR__ is probably your best bet.
'namespace' => __NAMESPACE__, // Main namespace of your project. E.g My_Project\Admin\Tests should be My_Project. Probably if you just pass the constant __NAMESPACE__ it should work
'classes_dir' => 'src', // (optional). It is where your namespaced classes are located inside your project. If your classes are in the root level, leave this empty. If they are located on 'src' folder, write 'src' here
) );