這家最近進行了討論,並記錄在案here:
myController::extend(function($controller) {
// Implement the relation controller if it doesn't exist already
if (!$controller->isClassExtendedWith('Backend.Behaviors.RelationController')) {
$controller->implement[] = 'Backend.Behaviors.RelationController';
}
// Implement the relationConfig property with our custom config if it doesn't exist already
$myConfigPath = '~/plugins/path/languages/config_relation.yaml';
if (!isset($controller->relationConfig)) {
$controller->addDynamicProperty('relationConfig', $myConfigPath);
}
else {
// Ensure that we have an instantiated config object to work with
$config = $controller->makeConfig($controller->relationConfig);
// Instantiate our custom config object to work with
$myConfig = $controller->makeConfig($myConfigPath);
// Merge the above two
$controller->relationConfig = (object) array_merge((array) $config, (array) $myConfig);
}
}
以下功能new,目前在develop
分支:
因此,在未來,後
public function mergeConfig($configA, $configB)
{
$configA = $this->makeConfig($configA);
$configB = $this->makeConfig($configB);
return (object) array_merge((array) $configA, (array) $configB);
}
develop
分支合併爲master
,你將能夠使用以下代碼來合併配置:
UsersController::extend(function($controller) {
// Implement behavior if not already implemented
if (!$controller->isClassExtendedWith('Backend.Behaviors.RelationController')) {
$controller->implement[] = 'Backend.Behaviors.RelationController';
}
// Define property if not already defined
if (!isset($controller->relationConfig)) {
$controller->addDynamicProperty('relationConfig');
}
// Splice in configuration safely
$myConfigPath = '$/myvendor/myplugin/controllers/users/config_relation.yaml';
$controller->relationConfig = $controller->mergeConfig(
$controller->relationConfig,
$myConfigPath
);
}
真棒坦克@meysam –
@TahaAzzabi文檔已更新,代碼略有更改:https://github.com/octobercms/docs/blob/master/services-behaviors.md#detecting-utilized-extensions – Meysam