Source of file CommandFactory.php
Size: 1,212 Bytes - Last Modified: 2021-12-23T10:28:55+00:00
/var/www/docs.ssmods.com/process/src/code/CommandFactory.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344 | <?php /** * @package commands * @subpackage code * @author Rainer Spittel (rainer at silverstripe dot com) * * The command factory class provides a method to initiate a command object. * The factory class checks for all available ICommand implementations * (@see ICommand) and initiate the command object. If the requested command * name is not available, the factory class will throw an exception. */ class CommandFactory extends Object { static $baseclass = 'ICommand'; /** * @param String $commandName * @param Controller $controller * * @return ControllerCommand * @throws CommandFactory_Exception */ static function get_command($commandName, $controller=null, $params = null) { $command = null; $className = $commandName . "Command"; if (ClassInfo::exists($className) && is_subclass_of($className,'ICommand')) { $command = new $className($controller); $command->setParameters($params); } else { throw new CommandFactory_Exception("Command '$className' not found."); } return $command; } } /** * Customised exception class, thrown by the command factory class only. * * @link CommandFactory */ class CommandFactory_Exception extends Exception {} |