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: * {@inheritDoc}
27: */
28: public function create($className)
29: {
30: $command = new $className();
31: if (!($command instanceof Command) && !($command instanceof Shell)) {
32: $valid = implode('` or `', [Shell::class, Command::class]);
33: $message = sprintf('Class `%s` must be an instance of `%s`.', $className, $valid);
34: throw new InvalidArgumentException($message);
35: }
36:
37: return $command;
38: }
39: }
40: