- Phalcon\Cli\Console
- Phalcon\Cli\Console\Exception
- Phalcon\Cli\Dispatcher
- Phalcon\Cli\Dispatcher\Exception
- Phalcon\Cli\DispatcherInterface
- Phalcon\Cli\Router
- Phalcon\Cli\Router\Exception
- Phalcon\Cli\Router\Route
- Phalcon\Cli\Router\RouteInterface
- Phalcon\Cli\RouterInterface
- Phalcon\Cli\Task
- Phalcon\Cli\TaskInterface
Class Phalcon\Cli\Console
| Namespace | Phalcon\Cli | | Uses | Phalcon\Application\AbstractApplication, Phalcon\Cli\Router\Route, Phalcon\Cli\Console\Exception, Phalcon\Di\DiInterface, Phalcon\Events\ManagerInterface | | Extends | AbstractApplication |
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;
Class Phalcon\Cli\Console\Exception
| Namespace | Phalcon\Cli\Console | | Extends | \Phalcon\Application\Exception |
Exceptions thrown in Phalcon\Cli\Console will use this class
Class Phalcon\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;
Class Phalcon\Cli\Dispatcher\Exception
| Namespace | Phalcon\Cli\Dispatcher | | Extends | \Phalcon\Dispatcher\Exception |
Exceptions thrown in Phalcon\Cli\Dispatcher will use this class
Interface Phalcon\Cli\DispatcherInterface
| Namespace | Phalcon\Cli | | Uses | Phalcon\Dispatcher\DispatcherInterface | | Extends | DispatcherInterfaceBase |
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 suffixClass Phalcon\Cli\Router
| Namespace | Phalcon\Cli | | Uses | Phalcon\Di\DiInterface, Phalcon\Di\AbstractInjectionAware, Phalcon\Cli\Router\Route, Phalcon\Cli\Router\Exception, Phalcon\Cli\Router\RouteInterface | | Extends | AbstractInjectionAware |
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 routesClass Phalcon\Cli\Router\Exception
| Namespace | Phalcon\Cli\Router | | Extends | \Phalcon\Exception |
Exceptions thrown in Phalcon\Cli\Router will use this class
Class Phalcon\Cli\Router\Route
| Namespace | Phalcon\Cli\Router | | 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 nameInterface Phalcon\Cli\Router\RouteInterface
| Namespace | Phalcon\Cli\Router |
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 nameInterface Phalcon\Cli\RouterInterface
| Namespace | Phalcon\Cli | | Uses | Phalcon\Cli\Router\RouteInterface |
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 routesClass Phalcon\Cli\Task
| Namespace | Phalcon\Cli | | Uses | Phalcon\Di\Injectable, Phalcon\Events\EventsAwareInterface, Phalcon\Events\ManagerInterface | | Extends | Injectable | | Implements | TaskInterface, EventsAwareInterface |
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 managerInterface Phalcon\Cli\TaskInterface
| Namespace | Phalcon\Cli |
Interface for task handlers