CodeIgniter v4.5 API

Filters
in package

Filters

Tags
see
FiltersTest

Table of Contents

Properties

$arguments  : array<string, array<int, string>|null>
Any arguments to be passed to filters.
$argumentsClass  : array<class-string, array<int, string>|null>
Any arguments to be passed to filtersClass.
$config  : Filters
The original config file
$filters  : array<string, array<string|int, mixed>>
The processed filters that will be used to check against.
$filtersClass  : array<string, array<string|int, mixed>>
The collection of filters' class names that will be used to execute in each position.
$initialized  : bool
Whether we've done initial processing on the filter lists.
$modules  : Modules
Handle to the modules config.
$request  : RequestInterface
The active IncomingRequest or CLIRequest
$response  : ResponseInterface
The active Response instance

Methods

__construct()  : mixed
Constructor.
addFilter()  : $this
Adds a new alias to the config file.
enableFilters()  : Filters
Ensures that specific filters are on and enabled for the current request.
getArguments()  : array<string, string>|string
Returns the arguments for a specified key, or all.
getFilters()  : array<string|int, mixed>
Returns the processed filters array.
getFiltersClass()  : array<string|int, mixed>
Returns the filtersClass array.
initialize()  : Filters
Runs through our list of filters provided by the configuration object to get them ready for use, including getting uri masks to proper regex, removing those we can from the possibilities based on HTTP method, etc.
reset()  : self
Restores instance to its pre-initialized state.
run()  : RequestInterface|ResponseInterface|string|null
Runs through all of the filters for the specified uri and position.
setResponse()  : void
Set the response explicitly.
processAliasesToClass()  : void
Maps filter aliases to the equivalent filter classes
processFilters()  : void
Add any applicable configured filters to the mix.
processGlobals()  : void
Add any applicable (not excluded) global filter settings to the mix.
processMethods()  : void
Add any method-specific filters to the mix.
checkExcept()  : bool
Check except paths
checkPseudoRegex()  : bool
Check the URI path as pseudo-regex
discoverFilters()  : void
If discoverFilters is enabled in Config then system will try to auto-discover custom filters files in Namespaces and allow access to the config object via the variable $filters as with the routes file
enableFilter()  : void
Ensures that a specific filter is on and enabled for the current request.
getCleanName()  : array{0: string, 1: list}
Get clean name and arguments
pathApplies()  : bool
Check paths for match for URI
registerArguments()  : void
runAfter()  : ResponseInterface
runBefore()  : RequestInterface|ResponseInterface|string
setToolbarToLast()  : array<string|int, mixed>
Set the toolbar filter to the last position to be executed.

Properties

$arguments

Any arguments to be passed to filters.

protected array<string, array<int, string>|null> $arguments = []

[name => params]

$argumentsClass

Any arguments to be passed to filtersClass.

protected array<class-string, array<int, string>|null> $argumentsClass = []

[classname => arguments]

$config

The original config file

protected Filters $config

$filters

The processed filters that will be used to check against.

protected array<string, array<string|int, mixed>> $filters = ['before' => [], 'after' => []]

This does not include "Required Filters".

$filtersClass

The collection of filters' class names that will be used to execute in each position.

protected array<string, array<string|int, mixed>> $filtersClass = ['before' => [], 'after' => []]

This does not include "Required Filters".

$initialized

Whether we've done initial processing on the filter lists.

protected bool $initialized = false

$modules

Handle to the modules config.

protected Modules $modules

Methods

addFilter()

Adds a new alias to the config file.

public addFilter(string $class[, string|null $alias = null ][, string $when = 'before' ][, string $section = 'globals' ]) : $this

MUST be called prior to initialize(); Intended for use within routes files.

Parameters
$class : string
$alias : string|null = null
$when : string = 'before'
$section : string = 'globals'
Return values
$this

enableFilters()

Ensures that specific filters are on and enabled for the current request.

public enableFilters(array<string|int, mixed> $names[, string $when = 'before' ]) : Filters

Filters can have "arguments". This is done by placing a colon immediately after the filter name, followed by a comma-separated list of arguments that are passed to the filter when executed.

Parameters
$names : array<string|int, mixed>
$when : string = 'before'
Tags
params

array $names filter_name or filter_name:arguments like 'role:admin,manager'

Return values
Filters

getArguments()

Returns the arguments for a specified key, or all.

public getArguments([string|null $key = null ]) : array<string, string>|string
Parameters
$key : string|null = null
Return values
array<string, string>|string

getFilters()

Returns the processed filters array.

public getFilters() : array<string|int, mixed>

This does not include "Required Filters".

Return values
array<string|int, mixed>

getFiltersClass()

Returns the filtersClass array.

public getFiltersClass() : array<string|int, mixed>

This does not include "Required Filters".

Return values
array<string|int, mixed>

initialize()

Runs through our list of filters provided by the configuration object to get them ready for use, including getting uri masks to proper regex, removing those we can from the possibilities based on HTTP method, etc.

public initialize([string|null $uri = null ]) : Filters

The resulting $this->filters is an array of only filters that should be applied to this request.

We go ahead and process the entire tree because we'll need to run through both a before and after and don't want to double process the rows.

Parameters
$uri : string|null = null

URI path relative to baseURL (all lowercase)

Tags
TODO

We don't need to accept null as $uri.

Return values
Filters

reset()

Restores instance to its pre-initialized state.

public reset() : self

Most useful for testing so the service can be re-initialized to a different path.

Return values
self

processAliasesToClass()

Maps filter aliases to the equivalent filter classes

protected processAliasesToClass(string $position) : void
Parameters
$position : string
Tags
throws
FilterException

processFilters()

Add any applicable configured filters to the mix.

protected processFilters([string|null $uri = null ]) : void
Parameters
$uri : string|null = null

URI path relative to baseURL (all lowercase)

processGlobals()

Add any applicable (not excluded) global filter settings to the mix.

protected processGlobals([string|null $uri = null ]) : void
Parameters
$uri : string|null = null

URI path relative to baseURL (all lowercase)

processMethods()

Add any method-specific filters to the mix.

protected processMethods() : void

checkExcept()

Check except paths

private checkExcept(string $uri, array<string|int, mixed>|string $paths) : bool
Parameters
$uri : string

URI path relative to baseURL (all lowercase)

$paths : array<string|int, mixed>|string

The except path patterns

Return values
bool

True if the URI matches except paths.

checkPseudoRegex()

Check the URI path as pseudo-regex

private checkPseudoRegex(string $uri, array<string|int, mixed> $paths) : bool
Parameters
$uri : string

URI path relative to baseURL (all lowercase, URL-decoded)

$paths : array<string|int, mixed>

The except path patterns

Return values
bool

discoverFilters()

If discoverFilters is enabled in Config then system will try to auto-discover custom filters files in Namespaces and allow access to the config object via the variable $filters as with the routes file

private discoverFilters() : void

Use Registrar instead.

Sample : $filters->aliases['custom-auth'] = \Acme\Blob\Filters\BlobAuth::class;

enableFilter()

Ensures that a specific filter is on and enabled for the current request.

private enableFilter(string $name[, string $when = 'before' ]) : void

Filters can have "arguments". This is done by placing a colon immediately after the filter name, followed by a comma-separated list of arguments that are passed to the filter when executed.

Parameters
$name : string

filter_name or filter_name:arguments like 'role:admin,manager'

$when : string = 'before'

getCleanName()

Get clean name and arguments

private getCleanName(string $name) : array{0: string, 1: list}
Parameters
$name : string

filter_name or filter_name:arguments like 'role:admin,manager'

Return values
array{0: string, 1: list}

[name, arguments]

pathApplies()

Check paths for match for URI

private pathApplies(string $uri, array<string|int, mixed>|string $paths) : bool
Parameters
$uri : string

URI to test against

$paths : array<string|int, mixed>|string

The path patterns to test

Return values
bool

True if any of the paths apply to the URI

registerArguments()

private registerArguments(string $name, array<string|int, mixed> $arguments[, bool $check = true ]) : void
Parameters
$name : string

filter alias

$arguments : array<string|int, mixed>

filter arguments

$check : bool = true

if true, check if already defined

setToolbarToLast()

Set the toolbar filter to the last position to be executed.

private setToolbarToLast(array<int, string> $filters[, bool $remove = false ]) : array<string|int, mixed>
Parameters
$filters : array<int, string>

after filter array

$remove : bool = false

if true, remove toolbar filter

Return values
array<string|int, mixed>

        
On this page

Search results