Phalcon cli
NOTE
All classes are prefixed with Phalcon
Cli\Console¶
-
Namespace
Phalcon\Cli
-
Uses
Phalcon\Application\AbstractApplication
Phalcon\Cli\Console\Exception
Phalcon\Cli\Router\Route
Phalcon\Di\DiInterface
Phalcon\Events\ManagerInterface
-
Extends
AbstractApplication
-
Implements
This component allows to create CLI applications using Phalcon
Properties¶
Methods¶
Handle the whole command-line taskspublic function setArgument( array $arguments = null, bool $str = bool, bool $shift = bool ): Console;
Cli\Console\Exception¶
-
Namespace
Phalcon\Cli\Console
-
Uses
-
Extends
\Phalcon\Application\Exception
-
Implements
Exceptions thrown in Phalcon\Cli\Console will use this class
Cli\Dispatcher¶
-
Namespace
Phalcon\Cli
-
Uses
Phalcon\Cli\Dispatcher\Exception
Phalcon\Dispatcher\AbstractDispatcher
Phalcon\Events\ManagerInterface
Phalcon\Filter\FilterInterface
-
Extends
CliDispatcher
-
Implements
DispatcherInterface
Dispatching is the process of taking the command-line arguments, extracting the module name, task name, action name, and optional parameters contained in it, and then instantiating a task and calling an action on it.
use Phalcon\Di;
use Phalcon\Cli\Dispatcher;
$di = new Di();
$dispatcher = new Dispatcher();
$dispatcher->setDi($di);
$dispatcher->setTaskName("posts");
$dispatcher->setActionName("index");
$dispatcher->setParams([]);
$handle = $dispatcher->dispatch();
Properties¶
/**
* @var string
*/
protected $defaultHandler = main;
/**
* @var string
*/
protected $defaultAction = main;
/**
* @var string
*/
protected $handlerSuffix = Task;
/**
* @var array
*/
protected $options;
Methods¶
public function callActionMethod( mixed $handler, string $actionMethod, array $params = [] ): mixed;
public function getOption( mixed $option, mixed $filters = null, mixed $defaultValue = null ): mixed;
Cli\Dispatcher\Exception¶
-
Namespace
Phalcon\Cli\Dispatcher
-
Uses
-
Extends
\Phalcon\Dispatcher\Exception
-
Implements
Exceptions thrown in Phalcon\Cli\Dispatcher will use this class
Cli\DispatcherInterface ¶
-
Namespace
Phalcon\Cli
-
Uses
Phalcon\Dispatcher\DispatcherInterface
-
Extends
DispatcherInterfaceBase
-
Implements
Interface for Phalcon\Cli\Dispatcher
Methods¶
Returns the active task in the dispatcher Returns the latest dispatched controller Get dispatched options Gets last dispatched task name Gets default task suffix Sets the default task name Set the options to be dispatched Sets the task name to be dispatched Sets the default task suffixCli\Router¶
-
Namespace
Phalcon\Cli
-
Uses
Phalcon\Cli\Router\Exception
Phalcon\Cli\Router\Route
Phalcon\Cli\Router\RouteInterface
Phalcon\Di\AbstractInjectionAware
Phalcon\Di\DiInterface
-
Extends
AbstractInjectionAware
-
Implements
Phalcon\Cli\Router is the standard framework router. Routing is the process of taking a command-line arguments and decomposing it into parameters to determine which module, task, and action of that task should receive the request.
$router = new \Phalcon\Cli\Router();
$router->handle(
[
"module" => "main",
"task" => "videos",
"action" => "process",
]
);
echo $router->getTaskName();
Properties¶
//
protected $action;
//
protected $defaultAction;
//
protected $defaultModule;
/**
* @var array
*/
protected $defaultParams;
//
protected $defaultTask;
//
protected $matchedRoute;
//
protected $matches;
//
protected $module;
/**
* @var array
*/
protected $params;
//
protected $routes;
//
protected $task;
//
protected $wasMatched = false;
Methods¶
Phalcon\Cli\Router constructor Adds a route to the router Returns processed action name Returns the route that matches the handled URI Returns the sub expressions in the regular expression matched Returns processed module name Returns processed extra params Returns a route object by its id Returns a route object by its name Returns all the routes defined in the router Returns processed task name Handles routing information received from command-line arguments Sets the default action name Sets the name of the default module Sets the default controller name Sets an array of default paths. If a route is missing a path the router will use the defined here. This method must not be used to set a 404 route Checks if the router matches any of the defined routesCli\Router\Exception¶
-
Namespace
Phalcon\Cli\Router
-
Uses
-
Extends
\Exception
-
Implements
Exceptions thrown in Phalcon\Cli\Router will use this class
Cli\Router\Route¶
-
Namespace
Phalcon\Cli\Router
-
Uses
-
Extends
-
Implements
RouteInterface
This class represents every route added to the router
Constants¶
Properties¶
//
protected $beforeMatch;
//
protected $compiledPattern;
//
protected $converters;
//
protected $delimiter;
//
protected $static $delimiterPath;
//
protected $description;
//
protected $id;
//
protected $name;
//
protected $paths;
//
protected $pattern;
//
protected $static $uniqueId = 0;
Methods¶
Sets a callback that is called if the route is matched. The developer can implement any arbitrary conditions here If the callback returns false the route is treated as not matched Replaces placeholders from pattern returning a valid PCRE regular expression Adds a converter to perform an additional transformation for certain parameter Set the routing delimiter Extracts parameters from a string Returns the 'before match' callback if any Returns the route's compiled pattern Returns the router converter Get routing delimiter Returns the route's description Returns the route's name Returns the paths Returns the route's pattern Returns the paths using positions as keys and names as values Returns the route's id Reconfigure the route adding a new pattern and a set of paths Resets the internal route id generator Sets the route's description Sets the route's nameCli\Router\RouteInterface ¶
-
Namespace
Phalcon\Cli\Router
-
Uses
-
Extends
-
Implements
Interface for Phalcon\Cli\Router\Route
Methods¶
Replaces placeholders from pattern returning a valid PCRE regular expression Set the routing delimiter Returns the route's pattern Get routing delimiter Returns the route's description Returns the route's name Returns the paths Returns the route's pattern Returns the paths using positions as keys and names as values Returns the route's id Reconfigure the route adding a new pattern and a set of paths Resets the internal route id generator Sets the route's description Sets the route's nameCli\RouterInterface ¶
-
Namespace
Phalcon\Cli
-
Uses
Phalcon\Cli\Router\RouteInterface
-
Extends
-
Implements
Interface for Phalcon\Cli\Router
Methods¶
Adds a route to the router on any HTTP method Returns processed action name Returns the route that matches the handled URI Return the sub expressions in the regular expression matched Returns processed module name Returns processed extra params Returns a route object by its id Returns a route object by its name Return all the routes defined in the router Returns processed task name Handles routing information received from the rewrite engine Sets the default action name Sets the name of the default module Sets the default task name Sets an array of default paths Check if the router matches any of the defined routesCli\Task¶
-
Namespace
Phalcon\Cli
-
Uses
Phalcon\Di\Injectable
Phalcon\Events\EventsAwareInterface
Phalcon\Events\ManagerInterface
-
Extends
Injectable
-
Implements
EventsAwareInterface
TaskInterface
Every command-line task should extend this class that encapsulates all the task functionality
A task can be used to run "tasks" such as migrations, cronjobs, unit-tests, or anything that you want. The Task class should at least have a "mainAction" method.
class HelloTask extends \Phalcon\Cli\Task
{
// This action will be executed by default
public function mainAction()
{
}
public function findAction()
{
}
}
Properties¶
Methods¶
Phalcon\Cli\Task constructor Returns the internal event manager Sets the events managerCli\TaskInterface ¶
-
Namespace
Phalcon\Cli
-
Uses
-
Extends
-
Implements
Interface for task handlers