因此,莫扎特还不支持字段自动加载,但有一个分支支持自动加载(可能会在某个时候合并到莫扎特大师中)
这是我用来管理碳场的composer文件(还有Eric Mann的Sessionz和WP Session Manager):
"type": "wordpress-plugin",
"scripts": {
"lint": [
"phpcs --extensions=php src *.php"
],
"fix": ["phpcbf --extensions=php src *.php"],
"post-install-cmd": [
"\\"vendor/bin/mozart\\" compose"
],
"post-update-cmd": [
"\\"vendor/bin/mozart\\" compose"
]
},
"require": {
"php": ">=7.1",
"ericmann/sessionz": "^0.3",
"ericmann/wp-session-manager": "*",
"htmlburger/carbon-fields": "*"
},
"repositories": [
{
"url": "https://github.com/brianhenryie/mozart",
"type": "git"
},
{
"url": "https://github.com/ericmann/wp-session-manager",
"type": "git"
}
],
"require-dev":{
"coenjacobs/mozart": "dev-rewrite",
"squizlabs/php_codesniffer": "*",
"wp-coding-standards/wpcs": "*"
},
"autoload": {
"psr-4": {
"MZoo\\\\MzMboAccess\\\\": "src"
}
},
"extra": {
"mozart":{
"dep_namespace": "MZoo\\\\MzMboAccess\\\\Dependencies\\\\",
"dep_directory": "/src/Mozart/",
"packages": [
"htmlburger/carbon-fields",
"ericmann/wp-session-manager",
"ericmann/sessionz"
],
"delete_vendor_directories": false,
"override_autoload": {
"htmlburger/carbon-fields": {
"psr-4": {
"Carbon_Fields\\\\": "core/"
},
"files": [
"config.php",
"templates",
"assets",
"build"
]
}
}
}
}
然后,与作曲家自动加载一起,我需要莫扎特特定的自动加载:
/**
* Autoload Classes
*/
$wp_mbo_access_autoload = NS\\PLUGIN_NAME_DIR . \'/vendor/autoload.php\';
if ( file_exists( $wp_mbo_access_autoload ) ) {
include_once $wp_mbo_access_autoload;
}
// Mozart-managed dependencies
$wp_mbo_access_mozart_autoload = NS\\PLUGIN_NAME_DIR . \'/src/Mozart/autoload.php\';
if ( file_exists( $wp_mbo_access_mozart_autoload ) ) {
include_once $wp_mbo_access_mozart_autoload;
}