/** * Enables an addon and saves the provided options * @param string $name The name of the addon * @param array $options The options of the addon * @throws \InvalidArgumentException * @throws \Exception * @return boolean TRUE if successfully loaded. FALSE otherwise. */ public function add($name, $options = []) { if (!is_string($name)) { throw new \InvalidArgumentException(''); } if (!is_array($options)) { throw new \InvalidArgumentException(''); } if (isset($this->data[$name])) { return false; } $addonDefinitionOptions = \BearFramework\Addons::getOptions($name); if (isset($addonDefinitionOptions['require']) && is_array($addonDefinitionOptions['require'])) { foreach ($addonDefinitionOptions['require'] as $requiredAddonName) { if (is_string($requiredAddonName)) { $this->add($requiredAddonName); } } } $pathname = \BearFramework\Addons::getDir($name); $pathname = rtrim($pathname, '/\\') . '/'; $this->data[$name] = ['pathname' => $pathname, 'options' => $options]; $__indexFilename = realpath($pathname . 'index.php'); if ($__indexFilename !== false) { $app =& App::$instance; // Needed for the index file $context = new App\AddonContext($pathname); $context->options = $options; unset($name); // Hide this variable from the file scope unset($pathname); // Hide this variable from the file scope unset($options); // Hide this variable from the file scope unset($addonDefinitionOptions); // Hide this variable from the file scope include_once $__indexFilename; return true; } else { throw new \Exception('Addon index file not found'); } }
/** * * @param string $directory * @param string $id * @throws \Exception * @throws \InvalidArgumentException */ public function update($directory, $id) { if (!is_string($directory)) { throw new \InvalidArgumentException(''); } if (!is_string($id)) { throw new \InvalidArgumentException(''); } if (\BearFramework\Addons::exists($id)) { $options = \BearFramework\Addons::getOptions($id); if (isset($options['releasesUrl'])) { $this->install($directory, $options['releasesUrl']); } } else { throw new \Exception('Addon does not exists'); } }