Class Phalcon\Cli\Console
Source on GitHub
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
/**
* @var array
*/
protected arguments;
/**
* @var array
*/
protected options;
Methods
public function handle( array $arguments = null );
Handle the whole command-line tasks
public function setArgument( array $arguments = null, bool $str = bool, bool $shift = bool ): Console;
Set an specific argument
Class Phalcon\Cli\Console\Exception
Source on GitHub
Namespace |
Phalcon\Cli\Console |
Extends |
\Phalcon\Application\Exception |
Exceptions thrown in Phalcon\Cli\Console will use this class
Class Phalcon\Cli\Dispatcher
Source on GitHub
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\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
//
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;
Calls the action method.
public function getActiveTask(): TaskInterface;
Returns the active task in the dispatcher
public function getLastTask(): TaskInterface;
Returns the latest dispatched controller
public function getOption( mixed $option, mixed $filters = null, mixed $defaultValue = null ): mixed;
Gets an option by its name or numeric index
public function getOptions(): array;
Get dispatched options
public function getTaskName(): string;
Gets last dispatched task name
public function getTaskSuffix(): string;
Gets the default task suffix
public function hasOption( mixed $option ): bool;
Check if an option exists
public function setDefaultTask( string $taskName ): void;
Sets the default task name
public function setOptions( array $options ): void;
Set the options to be dispatched
public function setTaskName( string $taskName ): void;
Sets the task name to be dispatched
public function setTaskSuffix( string $taskSuffix ): void;
Sets the default task suffix
protected function handleException( \Exception $exception );
Handles a user exception
protected function throwDispatchException( string $message, int $exceptionCode = int );
Throws an internal exception
Class Phalcon\Cli\Dispatcher\Exception
Source on GitHub
Namespace |
Phalcon\Cli\Dispatcher |
Extends |
\Phalcon\Dispatcher\Exception |
Exceptions thrown in Phalcon\Cli\Dispatcher will use this class
Interface Phalcon\Cli\DispatcherInterface
Source on GitHub
Namespace |
Phalcon\Cli |
Uses |
Phalcon\Dispatcher\DispatcherInterface |
Extends |
DispatcherInterfaceBase |
Interface for Phalcon\Cli\Dispatcher
Methods
public function getActiveTask(): TaskInterface;
Returns the active task in the dispatcher
public function getLastTask(): TaskInterface;
Returns the latest dispatched controller
public function getOptions(): array;
Get dispatched options
public function getTaskName(): string;
Gets last dispatched task name
public function getTaskSuffix(): string;
Gets default task suffix
public function setDefaultTask( string $taskName ): void;
Sets the default task name
public function setOptions( array $options ): void;
Set the options to be dispatched
public function setTaskName( string $taskName ): void;
Sets the task name to be dispatched
public function setTaskSuffix( string $taskSuffix ): void;
Sets the default task suffix
Class Phalcon\Cli\Router
Source on GitHub
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
/**
* @var string|null
*/
protected action;
/**
* @var string|null
*/
protected defaultAction;
/**
* @var string
*/
protected defaultModule = "";
/**
* @var array
*/
protected defaultParams;
/**
* @var string|null
*/
protected defaultTask;
/**
* @var RouteInterface|null
*/
protected matchedRoute;
/**
* @var array
*/
protected matches;
/**
* @var string
*/
protected module = "";
/**
* @var array
*/
protected params;
/**
* @var array
*/
protected routes;
/**
* @var string|null
*/
protected task;
/**
* @var bool
*/
protected wasMatched = false;
Methods
public function __construct( bool $defaultRoutes = bool );
Phalcon\Cli\Router constructor
public function add( string $pattern, mixed $paths = null ): RouteInterface;
Adds a route to the router
$router->add("/about", "About::main");
public function getActionName(): string;
Returns processed action name
public function getMatchedRoute(): RouteInterface | null;
Returns the route that matches the handled URI
public function getMatches(): array;
Returns the sub expressions in the regular expression matched
public function getModuleName(): string;
Returns processed module name
public function getParameters(): array;
Returns processed extra params
public function getParams(): array;
Returns processed extra params
@todo deprecate this in future versions
public function getRouteById( mixed $id ): RouteInterface | bool;
Returns a route object by its id
public function getRouteByName( string $name ): RouteInterface | bool;
Returns a route object by its name
public function getRoutes(): Route[];
Returns all the routes defined in the router
public function getTaskName(): string;
Returns processed task name
public function handle( mixed $arguments = null );
Handles routing information received from command-line arguments
public function setDefaultAction( string $actionName );
Sets the default action name
public function setDefaultModule( string $moduleName );
Sets the name of the default module
public function setDefaultTask( string $taskName ): void;
Sets the default controller name
public function setDefaults( array $defaults ): Router;
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
$router->setDefaults(
[
"module" => "common",
"action" => "index",
]
);
public function wasMatched(): bool;
Checks if the router matches any of the defined routes
Class Phalcon\Cli\Router\Exception
Source on GitHub
Namespace |
Phalcon\Cli\Router |
Extends |
\Exception |
Exceptions thrown in Phalcon\Cli\Router will use this class
Class Phalcon\Cli\Router\Route
Source on GitHub
Namespace |
Phalcon\Cli\Router |
Implements |
RouteInterface |
This class represents every route added to the router
Constants
const DEFAULT_DELIMITER = ;
Properties
/**
* @var mixed|null
*/
protected beforeMatch;
/**
* @var string|null
*/
protected compiledPattern;
/**
* @var array
*/
protected converters;
/**
* @var string
*/
protected delimiter;
/**
* @var string
*/
protected static delimiterPath;
/**
* @var string|null
*/
protected description;
/**
* @var string
*/
protected routeId;
/**
* @var string
*/
protected name;
/**
* @var array
*/
protected paths;
/**
* @var string
*/
protected pattern;
/**
* @var int|string
*/
protected static uniqueId = 0;
Methods
public function __construct( string $pattern, mixed $paths = null );
public function beforeMatch( mixed $callback ): RouteInterface;
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
public function compilePattern( string $pattern ): string;
Replaces placeholders from pattern returning a valid PCRE regular
expression
public function convert( string $name, mixed $converter ): RouteInterface;
Adds a converter to perform an additional transformation for certain
parameter
public static function delimiter( string $delimiter = null ): void;
Set the routing delimiter
public function extractNamedParams( string $pattern ): array | bool;
Extracts parameters from a string
public function getBeforeMatch(): mixed;
Returns the ‘before match’ callback if any
public function getCompiledPattern(): string;
Returns the route’s compiled pattern
public function getConverters(): array;
Returns the router converter
public static function getDelimiter(): string;
Get routing delimiter
public function getDescription(): string;
Returns the route’s description
public function getName(): string;
Returns the route’s name
public function getPaths(): array;
Returns the paths
public function getPattern(): string;
Returns the route’s pattern
public function getReversedPaths(): array;
Returns the paths using positions as keys and names as values
public function getRouteId(): string;
Returns the route’s id
public function reConfigure( string $pattern, mixed $paths = null ): void;
Reconfigure the route adding a new pattern and a set of paths
public static function reset(): void;
Resets the internal route id generator
public function setDescription( string $description ): RouteInterface;
Sets the route’s description
public function setName( string $name ): RouteInterface;
Sets the route’s name
$router->add(
"/about",
[
"controller" => "about",
]
)->setName("about");
Interface Phalcon\Cli\Router\RouteInterface
Source on GitHub
Namespace |
Phalcon\Cli\Router |
Interface for Phalcon\Cli\Router\Route
Methods
public function compilePattern( string $pattern ): string;
Replaces placeholders from pattern returning a valid PCRE regular
expression
public static function delimiter( string $delimiter = null );
Set the routing delimiter
public function getCompiledPattern(): string;
Returns the route’s pattern
public static function getDelimiter(): string;
Get routing delimiter
public function getDescription(): string;
Returns the route’s description
public function getName(): string;
Returns the route’s name
public function getPaths(): array;
Returns the paths
public function getPattern(): string;
Returns the route’s pattern
public function getReversedPaths(): array;
Returns the paths using positions as keys and names as values
public function getRouteId(): string;
Returns the route’s id
public function reConfigure( string $pattern, mixed $paths = null ): void;
Reconfigure the route adding a new pattern and a set of paths
public static function reset(): void;
Resets the internal route id generator
public function setDescription( string $description ): RouteInterface;
Sets the route’s description
public function setName( string $name ): RouteInterface;
Sets the route’s name
Interface Phalcon\Cli\RouterInterface
Source on GitHub
Namespace |
Phalcon\Cli |
Uses |
Phalcon\Cli\Router\RouteInterface |
Interface for Phalcon\Cli\Router
Methods
public function add( string $pattern, mixed $paths = null ): RouteInterface;
Adds a route to the router on any HTTP method
public function getActionName(): string;
Returns processed action name
public function getMatchedRoute(): RouteInterface | null;
Returns the route that matches the handled URI
public function getMatches(): array;
Return the sub expressions in the regular expression matched
public function getModuleName(): string;
Returns processed module name
public function getParameters(): array;
Returns processed extra params
public function getParams(): array;
Returns processed extra params
@todo deprecate this in the future
public function getRouteById( mixed $id ): RouteInterface;
Returns a route object by its id
public function getRouteByName( string $name ): RouteInterface;
Returns a route object by its name
public function getRoutes(): RouteInterface[];
Return all the routes defined in the router
public function getTaskName(): string;
Returns processed task name
public function handle( mixed $arguments = null );
Handles routing information received from the rewrite engine
public function setDefaultAction( string $actionName ): void;
Sets the default action name
public function setDefaultModule( string $moduleName ): void;
Sets the name of the default module
public function setDefaultTask( string $taskName ): void;
Sets the default task name
public function setDefaults( array $defaults ): void;
Sets an array of default paths
public function wasMatched(): bool;
Check if the router matches any of the defined routes
Class Phalcon\Cli\Task
Source on GitHub
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
/**
* @var ManagerInterface
*/
protected eventsManager;
Methods
final public function __construct();
Phalcon\Cli\Task constructor
public function getEventsManager(): ManagerInterface | null;
Returns the internal event manager
public function setEventsManager( ManagerInterface $eventsManager ): void;
Sets the events manager
Interface Phalcon\Cli\TaskInterface
Source on GitHub
Interface for task handlers