1: <?php
2: /**
3: * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
4: * Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
5: * Licensed under The MIT License
6: * For full copyright and license information, please see the LICENSE.txt
7: * Redistributions of files must retain the above copyright notice.
8: *
9: * @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
10: * @link http://cakephp.org CakePHP(tm) Project
11: * @license http://www.opensource.org/licenses/mit-license.php MIT License
12: */
13: namespace Cake\Console;
14:
15: use InvalidArgumentException;
16:
17: /**
18: * This is a factory for creating Command and Shell instances.
19: *
20: * This factory can be replaced or extended if you need to customize building
21: * your command and shell objects.
22: */
23: class CommandFactory implements CommandFactoryInterface
24: {
25:
26: /**
27: * {@inheritDoc}
28: */
29: public function create($className)
30: {
31: $command = new $className();
32: if (!($command instanceof Command) && !($command instanceof Shell)) {
33: $valid = implode('` or `', [Shell::class, Command::class]);
34: $message = sprintf('Class `%s` must be an instance of `%s`.', $className, $valid);
35: throw new InvalidArgumentException($message);
36: }
37:
38: return $command;
39: }
40: }
41: