Skip to content

Instantly share code, notes, and snippets.

@Fi1osof
Last active December 10, 2015 16:29
Show Gist options
  • Save Fi1osof/4461649 to your computer and use it in GitHub Desktop.
Save Fi1osof/4461649 to your computer and use it in GitHub Desktop.
modX::addExtensionPackage(
<?php
public function addExtensionPackage($name,$path,array $options = array()) {
// What is it for?
// $extPackages
// It`s not using
$extPackages = $this->getOption('extension_packages');
$extPackages = !empty($extPackages) ? $extPackages : array();
$extPackages = is_array($extPackages) ? $extPackages : $this->fromJSON($extPackages);
$extPackages[$name] = $options;
$extPackages['path'] = $path;
/** @var modSystemSetting $setting */
$setting = $this->getObject('modSystemSetting',array(
'key' => 'extension_packages',
));
if (empty($setting)) {
$setting = $this->newObject('modSystemSetting');
$setting->set('key','extension_packages');
$setting->set('namespace','core');
$setting->set('xtype','textfield');
$setting->set('area','system');
}
$value = $setting->get('value');
$value = is_array($value) ? $value : $this->fromJSON($value);
if (empty($value)) {
$value = array();
$value[$name] = $options;
$value[$name]['path'] = $path;
$value = '['.$this->toJSON($value).']';
} else {
$found = false;
foreach ($value as $k => $v) {
foreach ($v as $kk => $vv) {
if ($kk == $name) {
$found = true;
}
}
}
if (!$found) {
// And this? $extPack
// It`s not defined
$extPack[$name] = $options;
$extPack[$name]['path'] = $path;
$value[] = $extPack;
}
$value = $this->toJSON($value);
}
$value = str_replace('\\','',$value);
$setting->set('value',$value);
return $setting->save();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment