| @@ 95-105 (lines=11) @@ | ||
| 92 | * @throws \phpbu\App\Exception |
|
| 93 | * @return mixed |
|
| 94 | */ |
|
| 95 | protected function create($type, $alias) |
|
| 96 | { |
|
| 97 | self::checkType($type); |
|
| 98 | $alias = strtolower($alias); |
|
| 99 | ||
| 100 | if (!isset(self::$classMap[$type][$alias])) { |
|
| 101 | throw new Exception(sprintf('unknown %s: %s', $type, $alias)); |
|
| 102 | } |
|
| 103 | $class = self::$classMap[$type][$alias]; |
|
| 104 | return new $class(); |
|
| 105 | } |
|
| 106 | ||
| 107 | /** |
|
| 108 | * Runner Factory. |
|
| @@ 268-277 (lines=10) @@ | ||
| 265 | * @param boolean $force Overwrite already registered class |
|
| 266 | * @throws \phpbu\App\Exception |
|
| 267 | */ |
|
| 268 | public static function register($type, $alias, $fqcn, $force = false) |
|
| 269 | { |
|
| 270 | self::checkType($type); |
|
| 271 | $alias = strtolower($alias); |
|
| 272 | ||
| 273 | if (!$force && isset(self::$classMap[$type][$alias])) { |
|
| 274 | throw new Exception(sprintf('%s is already registered use force parameter to overwrite', $type)); |
|
| 275 | } |
|
| 276 | self::$classMap[$type][$alias] = $fqcn; |
|
| 277 | } |
|
| 278 | ||
| 279 | /** |
|
| 280 | * Throws an exception if type is invalid. |
|