StandaloneRouter
in package
The StandaloneRouter allows you to run CiviCRM's "Standalone" UF with the PHP built-in server.
It is intended for local development.
Ex: php -S localhost:8000 -t srv/web/ tools/standalone/router.php
Table of Contents
Constants
- ALLOW_VIRTUAL_FILES = ';\.(jpg|png|css|js|html|txt|json|yml|xml|md|woff2)$;'
Properties
- $routes : mixed
Methods
- __construct() : mixed
- addRoute() : void
- Register another route.
- findCore() : string
- findPackages() : string
- findSettingsPhp() : string
- findVendor() : string
- invoke() : bool
- Invoke a civicrm route.
- main() : bool
- Receive a request through the PHP built-in HTTP server. Decide how to process it.
- runSetup() : bool
- sendDirect() : string
- sendError() : bool
- sendFileFromFolder() : bool
- sendRedirect() : mixed
- findFile() : string|null
Constants
ALLOW_VIRTUAL_FILES
private
mixed
ALLOW_VIRTUAL_FILES
= ';\.(jpg|png|css|js|html|txt|json|yml|xml|md|woff2)$;'
Properties
$routes
private
mixed
$routes
= []
Methods
__construct()
public
__construct() : mixed
addRoute()
Register another route.
public
addRoute(string $regex, callable $handler) : void
Parameters
- $regex : string
-
Regular expression to run against the request-path. Ex: ';^/foobar/(.*);'
- $handler : callable
-
Function to call when routing the match. Receives the regex-matches as input. Ex: fn($m) => $this->sendError(500, 'This path is foobared: ' . $m[1]); The handler should return TRUE (if handled), FALSE (if skipped), or selected string constants.
findCore()
public
findCore() : string
Return values
stringfindPackages()
public
findPackages() : string
Return values
stringfindSettingsPhp()
public
findSettingsPhp() : string
Return values
stringfindVendor()
public
findVendor() : string
Return values
stringinvoke()
Invoke a civicrm route.
public
invoke(string $path) : bool
Parameters
- $path : string
-
Ex: 'civicrm/admin/foobar'
Tags
Return values
boolmain()
Receive a request through the PHP built-in HTTP server. Decide how to process it.
public
main() : bool
Tags
Return values
bool —TRUE if the request has been handled. FALSE if the request has not been handled.
runSetup()
public
runSetup() : bool
Return values
boolsendDirect()
public
sendDirect() : string
Return values
stringsendError()
public
sendError(int $code, string $message) : bool
Parameters
- $code : int
- $message : string
Return values
boolsendFileFromFolder()
public
sendFileFromFolder(string $basePath, string $relPath) : bool
Parameters
- $basePath : string
- $relPath : string
Return values
boolsendRedirect()
public
sendRedirect(mixed $path) : mixed
Parameters
- $path : mixed
findFile()
private
findFile(string $basePath, string $relPath) : string|null
Parameters
- $basePath : string
- $relPath : string
Return values
string|null —If file exists, then return the combined (absolute) path. If file does not exist, then return NULL.