Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
4.17% |
1 / 24 |
|
20.00% |
1 / 5 |
CRAP | |
0.00% |
0 / 1 |
| common_ext_ExtensionHandler | |
4.17% |
1 / 24 |
|
20.00% |
1 / 5 |
117.50 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getExtension | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| runExtensionScript | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
30 | |||
| getServiceManager | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| log | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| 1 | <?php |
| 2 | |
| 3 | use Zend\ServiceManager\ServiceLocatorAwareInterface; |
| 4 | use oat\oatbox\service\ServiceManager; |
| 5 | |
| 6 | /** |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License |
| 9 | * as published by the Free Software Foundation; under version 2 |
| 10 | * of the License (non-upgradable). |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 20 | * |
| 21 | * Copyright (c) 2008-2010 (original work) Deutsche Institut für Internationale Pädagogische Forschung |
| 22 | * (under the project TAO-TRANSFER); |
| 23 | * 2009-2012 (update and modification) Public Research Centre Henri Tudor |
| 24 | * (under the project TAO-SUSTAIN & TAO-DEV); |
| 25 | * |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * EXtension Wrapper |
| 30 | * |
| 31 | * @abstract |
| 32 | * @access public |
| 33 | * @author lionel.lecaque@tudor.lu |
| 34 | * @package generis |
| 35 | * @see @license GNU General Public (GPL) Version 2 http://www.opensource.org/licenses/gpl-2.0.php |
| 36 | |
| 37 | */ |
| 38 | abstract class common_ext_ExtensionHandler |
| 39 | { |
| 40 | // Adding container and logger. |
| 41 | use \oat\oatbox\log\ContainerLoggerTrait; |
| 42 | |
| 43 | /** |
| 44 | * @var common_ext_Extension |
| 45 | */ |
| 46 | public $extension = null; |
| 47 | |
| 48 | |
| 49 | /** |
| 50 | * Initialise the extension handler |
| 51 | * |
| 52 | * @access public |
| 53 | * @author Joel Bout, <joel.bout@tudor.lu> |
| 54 | * @param common_ext_Extension $extension |
| 55 | */ |
| 56 | public function __construct(common_ext_Extension $extension) |
| 57 | { |
| 58 | $this->extension = $extension; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * @return common_ext_Extension |
| 63 | */ |
| 64 | protected function getExtension() |
| 65 | { |
| 66 | return $this->extension; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Run Extension Script |
| 71 | * |
| 72 | * @param string $script |
| 73 | * @param array $arguments (optional) |
| 74 | * @throws common_ext_InstallationException |
| 75 | */ |
| 76 | protected function runExtensionScript($script, array $arguments = []) |
| 77 | { |
| 78 | $this->log( |
| 79 | 'd', |
| 80 | 'Running custom extension script ' . $script . ' for extension ' . $this->getExtension()->getId() |
| 81 | ); |
| 82 | if (file_exists($script)) { |
| 83 | require_once $script; |
| 84 | } elseif (class_exists($script) && is_subclass_of($script, \oat\oatbox\action\Action::class)) { |
| 85 | $action = new $script(); |
| 86 | |
| 87 | if ($action instanceof ServiceLocatorAwareInterface) { |
| 88 | $action->setServiceLocator($this->getServiceManager()); |
| 89 | } |
| 90 | |
| 91 | call_user_func($action, $arguments); |
| 92 | } else { |
| 93 | $error = new common_ext_InstallationException('Unable to run install script ' . $script); |
| 94 | $error->setExtensionId($this->getExtension()->getId()); |
| 95 | |
| 96 | throw $error; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | protected function getServiceManager() |
| 101 | { |
| 102 | return ServiceManager::getServiceManager(); |
| 103 | } |
| 104 | |
| 105 | /** |
| 106 | * Log message |
| 107 | * |
| 108 | * @see common_Logger class |
| 109 | * |
| 110 | * @param string $logLevel |
| 111 | * <ul> |
| 112 | * <li>'w' - warning</li> |
| 113 | * <li>'t' - trace</li> |
| 114 | * <li>'d' - debug</li> |
| 115 | * <li>'i' - info</li> |
| 116 | * <li>'e' - error</li> |
| 117 | * <li>'f' - fatal</li> |
| 118 | * </ul> |
| 119 | * @param string $message |
| 120 | * @param array $tags |
| 121 | */ |
| 122 | public function log($logLevel, $message, $tags = []) |
| 123 | { |
| 124 | if ($this->getLogger() instanceof \Psr\Log\LoggerInterface) { |
| 125 | $this->getLogger()->log( |
| 126 | common_log_Logger2Psr::getPsrLevelFromCommon($logLevel), |
| 127 | $message |
| 128 | ); |
| 129 | } |
| 130 | if (method_exists('common_Logger', $logLevel)) { |
| 131 | call_user_func('common_Logger::' . $logLevel, $message, $tags); |
| 132 | } |
| 133 | } |
| 134 | } |