* @param common_ext_Extension $extension */ public function __construct(common_ext_Extension $extension) { $this->extension = $extension; } /** * @return common_ext_Extension */ protected function getExtension() { return $this->extension; } /** * Run Extension Script * * @param string $script * @param array $arguments (optional) * @throws common_ext_InstallationException */ protected function runExtensionScript($script, array $arguments = []) { $this->log('d', 'Running custom extension script ' . $script . ' for extension ' . $this->getExtension()->getId()); if (file_exists($script)) { require_once $script; } elseif (class_exists($script) && is_subclass_of($script, \oat\oatbox\action\Action::class)) { $action = new $script(); if ($action instanceof ServiceLocatorAwareInterface) { $action->setServiceLocator($this->getServiceManager()); } call_user_func($action, $arguments); } else { $error = new common_ext_InstallationException('Unable to run install script ' . $script); $error->setExtensionId($this->getExtension()->getId()); throw $error; } } protected function getServiceManager() { return ServiceManager::getServiceManager(); } /** * Log message * * @see common_Logger class * * @param string $logLevel * * @param string $message * @param array $tags */ public function log($logLevel, $message, $tags = []) { if ($this->getLogger() instanceof \Psr\Log\LoggerInterface) { $this->getLogger()->log( common_log_Logger2Psr::getPsrLevelFromCommon($logLevel), $message ); } if (method_exists('common_Logger', $logLevel)) { call_user_func('common_Logger::' . $logLevel, $message, $tags); } } }