CodeIgniter v4.5 API

BaseService
in package

Services Configuration file.

Services are simply other classes/libraries that the system uses to do its job. This is used by CodeIgniter to allow the core of the framework to be swapped out easily without affecting the usage within the rest of your application.

This is used in place of a Dependency Injection container primarily due to its simplicity, which allows a better long-term maintenance of the applications built on top of CodeIgniter. A bonus side-effect is that IDEs are able to determine what class you are calling whereas with DI Containers there usually isn't a way for them to do this.

Warning: To allow overrides by service providers do not use static calls, instead call out to \Config\Services (imported as AppServices).

Tags
see
http://blog.ircmaxell.com/2015/11/simple-easy-risk-and-change.html
see
http://www.infoq.com/presentations/Simple-Made-Easy

Table of Contents

Properties

$discovered  : bool
Have we already discovered other Services?
$factories  : array<string, callable(mixed ...$params): object>
Factory method list.
$instances  : array<string, object>
Cache for instance of any services that have been requested as a "shared" instance.
$mocks  : array<string, object>
Mock objects for testing which are returned if exist.
$services  : array<string|int, mixed>
A cache of other service classes we've found.
$serviceNames  : array<int, string>
A cache of the names of services classes found.

Methods

__callStatic()  : object|null
Provides the ability to perform case-insensitive calling of service names.
autoloader()  : Autoloader
The Autoloader class is the central class that handles our spl_autoload_register method, and helper methods.
cache()  : CacheInterface
clirequest()  : CLIRequest
codeigniter()  : CodeIgniter
commands()  : Commands
createRequest()  : void
csp()  : ContentSecurityPolicy
curlrequest()  : CURLRequest
email()  : Email
encrypter()  : EncrypterInterface
exceptions()  : Exceptions
filters()  : Filters
format()  : Format
get()  : object|null
Simple method to get an entry fast.
honeypot()  : Honeypot
image()  : BaseHandler
incomingrequest()  : IncomingRequest
injectMock()  : void
Inject mock object for testing.
iterator()  : Iterator
language()  : Language
locator()  : FileLocatorInterface
The file locator provides utility methods for looking for non-classes within namespaced folders, as well as convenience methods for loading 'helpers', and 'libraries'.
logger()  : Logger
migrations()  : MigrationRunner
negotiator()  : Negotiate
override()  : void
Overrides an existing entry.
pager()  : Pager
parser()  : Parser
redirectresponse()  : RedirectResponse
renderer()  : View
request()  : IncomingRequest|CLIRequest
reset()  : void
Reset shared instances and mocks for testing.
resetSingle()  : void
Resets any mock and shared instances for a single service.
response()  : ResponseInterface
responsecache()  : ResponseCache
router()  : Router
routes()  : RouteCollection
security()  : Security
serviceExists()  : string|null
Check if the requested service is defined and return the declaring class. Return null if not found.
session()  : Session
set()  : void
Sets an entry.
siteurifactory()  : SiteURIFactory
superglobals()  : Superglobals
throttler()  : Throttler
timer()  : Timer
toolbar()  : Toolbar
typography()  : Typography
uri()  : URI
validation()  : ValidationInterface
viewcell()  : Cell
buildServicesCache()  : void
getSharedInstance()  : object
Returns a shared instance of any of the class' services.

Properties

$discovered

Have we already discovered other Services?

protected static bool $discovered = false

$factories

Factory method list.

protected static array<string, callable(mixed ...$params): object> $factories = []

[key => callable]

$instances

Cache for instance of any services that have been requested as a "shared" instance.

protected static array<string, object> $instances = []

Keys should be lowercase service names.

[key => instance]

$mocks

Mock objects for testing which are returned if exist.

protected static array<string, object> $mocks = []

[key => instance]

$services

A cache of other service classes we've found.

No longer used.

protected static array<string|int, mixed> $services = []

$serviceNames

A cache of the names of services classes found.

private static array<int, string> $serviceNames = []

Methods

__callStatic()

Provides the ability to perform case-insensitive calling of service names.

public static __callStatic(string $name, array<string|int, mixed> $arguments) : object|null
Parameters
$name : string
$arguments : array<string|int, mixed>
Return values
object|null

autoloader()

The Autoloader class is the central class that handles our spl_autoload_register method, and helper methods.

public static autoloader([bool $getShared = true ]) : Autoloader
Parameters
$getShared : bool = true
Return values
Autoloader

clirequest()

public static clirequest([App $config = null ][, mixed $getShared = true ]) : CLIRequest
Parameters
$config : App = null
$getShared : mixed = true
Return values
CLIRequest

codeigniter()

public static codeigniter([App $config = null ][, mixed $getShared = true ]) : CodeIgniter
Parameters
$config : App = null
$getShared : mixed = true
Return values
CodeIgniter

commands()

public static commands([mixed $getShared = true ]) : Commands
Parameters
$getShared : mixed = true
Return values
Commands

createRequest()

public static createRequest([App $config = ][, bool $isCli = false ]) : void
Parameters
$config : App =
$isCli : bool = false

email()

public static email([mixed $config = null ][, mixed $getShared = true ]) : Email
Parameters
$config : mixed = null
$getShared : mixed = true
Return values
Email

exceptions()

public static exceptions([Exceptions $config = null ][, mixed $getShared = true ]) : Exceptions
Parameters
$config : Exceptions = null
$getShared : mixed = true
Return values
Exceptions

filters()

public static filters([Filters $config = null ][, mixed $getShared = true ]) : Filters
Parameters
$config : Filters = null
$getShared : mixed = true
Return values
Filters

format()

public static format([Format $config = null ][, mixed $getShared = true ]) : Format
Parameters
$config : Format = null
$getShared : mixed = true
Return values
Format

get()

Simple method to get an entry fast.

public static get(string $key) : object|null
Parameters
$key : string

Identifier of the entry to look for.

Return values
object|null

Entry.

honeypot()

public static honeypot([Honeypot $config = null ][, mixed $getShared = true ]) : Honeypot
Parameters
$config : Honeypot = null
$getShared : mixed = true
Return values
Honeypot

image()

public static image([mixed $handler = null ][, Images $config = null ][, mixed $getShared = true ]) : BaseHandler
Parameters
$handler : mixed = null
$config : Images = null
$getShared : mixed = true
Return values
BaseHandler

incomingrequest()

public static incomingrequest([App|null $config = null ][, bool $getShared = true ]) : IncomingRequest
Parameters
$config : App|null = null
$getShared : bool = true
Return values
IncomingRequest

injectMock()

Inject mock object for testing.

public static injectMock(string $name, object $mock) : void
Parameters
$name : string
$mock : object
Tags
testTag

only available to test code

iterator()

public static iterator([mixed $getShared = true ]) : Iterator
Parameters
$getShared : mixed = true
Return values
Iterator

language()

public static language([mixed $locale = null ][, mixed $getShared = true ]) : Language
Parameters
$locale : mixed = null
$getShared : mixed = true
Return values
Language

locator()

The file locator provides utility methods for looking for non-classes within namespaced folders, as well as convenience methods for loading 'helpers', and 'libraries'.

public static locator([bool $getShared = true ]) : FileLocatorInterface
Parameters
$getShared : bool = true
Return values
FileLocatorInterface

logger()

public static logger([mixed $getShared = true ]) : Logger
Parameters
$getShared : mixed = true
Return values
Logger

override()

Overrides an existing entry.

public static override(string $key, object $value) : void
Parameters
$key : string

Identifier of the entry.

$value : object

parser()

public static parser([mixed $viewPath = null ][, View $config = null ][, mixed $getShared = true ]) : Parser
Parameters
$viewPath : mixed = null
$config : View = null
$getShared : mixed = true
Return values
Parser

renderer()

public static renderer([mixed $viewPath = null ][, View $config = null ][, mixed $getShared = true ]) : View
Parameters
$viewPath : mixed = null
$config : View = null
$getShared : mixed = true
Return values
View

reset()

Reset shared instances and mocks for testing.

public static reset([bool $initAutoloader = true ]) : void
Parameters
$initAutoloader : bool = true
Tags
testTag

only available to test code

resetSingle()

Resets any mock and shared instances for a single service.

public static resetSingle(string $name) : void
Parameters
$name : string
Tags
testTag

only available to test code

security()

public static security([App $config = null ][, mixed $getShared = true ]) : Security
Parameters
$config : App = null
$getShared : mixed = true
Return values
Security

serviceExists()

Check if the requested service is defined and return the declaring class. Return null if not found.

public static serviceExists(string $name) : string|null
Parameters
$name : string
Return values
string|null

session()

public static session([Session $config = null ][, mixed $getShared = true ]) : Session
Parameters
$config : Session = null
$getShared : mixed = true
Return values
Session

set()

Sets an entry.

public static set(string $key, object $value) : void
Parameters
$key : string

Identifier of the entry.

$value : object

siteurifactory()

public static siteurifactory([App $config = null ][, Superglobals $superglobals = null ][, mixed $getShared = true ]) : SiteURIFactory
Parameters
$config : App = null
$superglobals : Superglobals = null
$getShared : mixed = true
Return values
SiteURIFactory

superglobals()

public static superglobals([array<string|int, mixed> $server = null ][, array<string|int, mixed> $get = null ][, bool $getShared = true ]) : Superglobals
Parameters
$server : array<string|int, mixed> = null
$get : array<string|int, mixed> = null
$getShared : bool = true
Return values
Superglobals

timer()

public static timer([mixed $getShared = true ]) : Timer
Parameters
$getShared : mixed = true
Return values
Timer

toolbar()

public static toolbar([Toolbar $config = null ][, mixed $getShared = true ]) : Toolbar
Parameters
$config : Toolbar = null
$getShared : mixed = true
Return values
Toolbar

uri()

public static uri([mixed $uri = null ][, mixed $getShared = true ]) : URI
Parameters
$uri : mixed = null
$getShared : mixed = true
Return values
URI

viewcell()

public static viewcell([mixed $getShared = true ]) : Cell
Parameters
$getShared : mixed = true
Return values
Cell

buildServicesCache()

protected static buildServicesCache() : void

getSharedInstance()

Returns a shared instance of any of the class' services.

protected static getSharedInstance(string $key, array<string|int, mixed>|bool|float|int|object|string|null ...$params) : object

$key must be a name matching a service.

Parameters
$key : string
$params : array<string|int, mixed>|bool|float|int|object|string|null
Return values
object

        
On this page

Search results