RouterConfig
in package
The router config.
Table of Contents
Constants
- EXTRACT_KEYWORDS : mixed = ['namespaces' => \karmabunny\router\Router::EXT...
- String forms for the 'extract' bitmask.
Properties
- $attrs : int
- Attribute extraction mode.
- $case_insensitive : bool
- Case sensitivity. By default - insensitive.
- $chunk_size : int
- (In chunked mode) - how many routes to jam into one regex.
- $edit_namespace_rule : callable|null
- Use this the alter or clean the namespace rules.
- $extract : int
- Extract mode - to source routes from namespaces, attributes, both or none.
- $methods : array<int, string>
- Permitted methods.
- $mode : string
- Which router implementation to use.
- $_extract : string
- Doesn't do anything, just good for debugging in vardump().
Methods
- __construct() : mixed
- Build a config.
- editNamespaceRule() : string
- Default namespace rule cleaner method.
- parseExtract() : int
- Convert the a string form 'extract' into a bitmask that matches the `Router::EXTRACT` flags.
Constants
EXTRACT_KEYWORDS
String forms for the 'extract' bitmask.
public
mixed
EXTRACT_KEYWORDS
= ['namespaces' => \karmabunny\router\Router::EXTRACT_NAMESPACES, 'attributes' => \karmabunny\router\Router::EXTRACT_ATTRIBUTES, 'all' => \karmabunny\router\Router::EXTRACT_ALL, 'convert' => \karmabunny\router\Router::EXTRACT_CONVERT_REGEX, 'prefixes' => \karmabunny\router\Router::EXTRACT_WITH_PREFIXES, 'short' => \karmabunny\router\Router::EXTRACT_SHORT_NAMESPACES, 'nested' => \karmabunny\router\Router::EXTRACT_NESTED_PREFIXES, 'sort' => \karmabunny\router\Router::EXTRACT_SORT_ATTRIBUTES, 'none' => \karmabunny\router\Router::EXTRACT_NONE]
Properties
$attrs
Attribute extraction mode.
public
int
$attrs
= \karmabunny\router\Router::ATTR_ALL
- 'all' (3) - extract all attribute routes
- 'attributes' (1) - extract PHP8 attributes
- 'docs' (2) - extract @route doc comments
$case_insensitive
Case sensitivity. By default - insensitive.
public
bool
$case_insensitive
= true
$chunk_size
(In chunked mode) - how many routes to jam into one regex.
public
int
$chunk_size
= 10
$edit_namespace_rule
Use this the alter or clean the namespace rules.
public
callable|null
$edit_namespace_rule
= [self::class, 'editNamespaceRule']
$extract
Extract mode - to source routes from namespaces, attributes, both or none.
public
int
$extract
= 0 | \karmabunny\router\Router::EXTRACT_ATTRIBUTES | \karmabunny\router\Router::EXTRACT_WITH_PREFIXES | \karmabunny\router\Router::EXTRACT_SORT_ATTRIBUTES
- 'none' (0)
- 'namespaces' (1) - convert 'ns\controller\method' into rule names
- 'attributes' (2) - extract PHP8 attributes and @route comments
- 'all' (3) - extract all routes
Additional flags:
- 'convert' (128) convert extracted rule patterns to regex
- 'prefixes' (256) add prefixes to extracted routes
- 'short' (512) only use controller/method in the rule path
- 'nested' (256 + 1024) permit multiple controllers per prefix
- 'sort' (2048) sort attributes by priority
$methods
Permitted methods.
public
array<int, string>
$methods
= \karmabunny\router\Router::METHODS
$mode
Which router implementation to use.
public
string
$mode
= \karmabunny\router\Router::MODE_CHUNKED
$_extract
Doesn't do anything, just good for debugging in vardump().
protected
string
$_extract
= '|'
Methods
__construct()
Build a config.
public
__construct(array<string, mixed> $config) : mixed
Parameters
- $config : array<string, mixed>
editNamespaceRule()
Default namespace rule cleaner method.
public
static editNamespaceRule(string $rule) : string
Parameters
- $rule : string
Return values
stringparseExtract()
Convert the a string form 'extract' into a bitmask that matches the `Router::EXTRACT` flags.
public
static parseExtract(string $extract) : int
E.g. 'attributes|convert' => 2 + 128 = 130
Parameters
- $extract : string