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
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|nullautoloader()
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
Autoloadercache()
public
static cache([Cache $config = null ][, mixed $getShared = true ]) : CacheInterface
Parameters
- $config : Cache = null
- $getShared : mixed = true
Return values
CacheInterfaceclirequest()
public
static clirequest([App $config = null ][, mixed $getShared = true ]) : CLIRequest
Parameters
- $config : App = null
- $getShared : mixed = true
Return values
CLIRequestcodeigniter()
public
static codeigniter([App $config = null ][, mixed $getShared = true ]) : CodeIgniter
Parameters
- $config : App = null
- $getShared : mixed = true
Return values
CodeIgnitercommands()
public
static commands([mixed $getShared = true ]) : Commands
Parameters
- $getShared : mixed = true
Return values
CommandscreateRequest()
public
static createRequest([App $config = ][, bool $isCli = false ]) : void
Parameters
- $config : App =
- $isCli : bool = false
csp()
public
static csp([ContentSecurityPolicy $config = null ][, mixed $getShared = true ]) : ContentSecurityPolicy
Parameters
- $config : ContentSecurityPolicy = null
- $getShared : mixed = true
Return values
ContentSecurityPolicycurlrequest()
public
static curlrequest([mixed $options = [] ][, ResponseInterface $response = null ][, App $config = null ][, mixed $getShared = true ]) : CURLRequest
Parameters
- $options : mixed = []
- $response : ResponseInterface = null
- $config : App = null
- $getShared : mixed = true
Return values
CURLRequestemail()
public
static email([mixed $config = null ][, mixed $getShared = true ]) : Email
Parameters
- $config : mixed = null
- $getShared : mixed = true
Return values
Emailencrypter()
public
static encrypter([Encryption $config = null ][, mixed $getShared = false ]) : EncrypterInterface
Parameters
- $config : Encryption = null
- $getShared : mixed = false
Return values
EncrypterInterfaceexceptions()
public
static exceptions([Exceptions $config = null ][, mixed $getShared = true ]) : Exceptions
Parameters
- $config : Exceptions = null
- $getShared : mixed = true
Return values
Exceptionsfilters()
public
static filters([Filters $config = null ][, mixed $getShared = true ]) : Filters
Parameters
- $config : Filters = null
- $getShared : mixed = true
Return values
Filtersformat()
public
static format([Format $config = null ][, mixed $getShared = true ]) : Format
Parameters
- $config : Format = null
- $getShared : mixed = true
Return values
Formatget()
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
Honeypotimage()
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
BaseHandlerincomingrequest()
public
static incomingrequest([App|null $config = null ][, bool $getShared = true ]) : IncomingRequest
Parameters
- $config : App|null = null
- $getShared : bool = true
Return values
IncomingRequestinjectMock()
Inject mock object for testing.
public
static injectMock(string $name, object $mock) : void
Parameters
- $name : string
- $mock : object
Tags
iterator()
public
static iterator([mixed $getShared = true ]) : Iterator
Parameters
- $getShared : mixed = true
Return values
Iteratorlanguage()
public
static language([mixed $locale = null ][, mixed $getShared = true ]) : Language
Parameters
- $locale : mixed = null
- $getShared : mixed = true
Return values
Languagelocator()
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
FileLocatorInterfacelogger()
public
static logger([mixed $getShared = true ]) : Logger
Parameters
- $getShared : mixed = true
Return values
Loggermigrations()
public
static migrations([Migrations $config = null ][, ConnectionInterface $db = null ][, mixed $getShared = true ]) : MigrationRunner
Parameters
- $config : Migrations = null
- $db : ConnectionInterface = null
- $getShared : mixed = true
Return values
MigrationRunnernegotiator()
public
static negotiator([RequestInterface $request = null ][, mixed $getShared = true ]) : Negotiate
Parameters
- $request : RequestInterface = null
- $getShared : mixed = true
Return values
Negotiateoverride()
Overrides an existing entry.
public
static override(string $key, object $value) : void
Parameters
- $key : string
-
Identifier of the entry.
- $value : object
pager()
public
static pager([Pager $config = null ][, RendererInterface $view = null ][, mixed $getShared = true ]) : Pager
Parameters
- $config : Pager = null
- $view : RendererInterface = null
- $getShared : mixed = true
Return values
Pagerparser()
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
Parserredirectresponse()
public
static redirectresponse([App $config = null ][, mixed $getShared = true ]) : RedirectResponse
Parameters
- $config : App = null
- $getShared : mixed = true
Return values
RedirectResponserenderer()
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
Viewrequest()
public
static request([App $config = null ][, mixed $getShared = true ]) : IncomingRequest|CLIRequest
Parameters
- $config : App = null
- $getShared : mixed = true
Return values
IncomingRequest|CLIRequestreset()
Reset shared instances and mocks for testing.
public
static reset([bool $initAutoloader = true ]) : void
Parameters
- $initAutoloader : bool = true
Tags
resetSingle()
Resets any mock and shared instances for a single service.
public
static resetSingle(string $name) : void
Parameters
- $name : string
Tags
response()
public
static response([App $config = null ][, mixed $getShared = true ]) : ResponseInterface
Parameters
- $config : App = null
- $getShared : mixed = true
Return values
ResponseInterfaceresponsecache()
public
static responsecache([Cache|null $config = null ][, CacheInterface|null $cache = null ][, bool $getShared = true ]) : ResponseCache
Parameters
- $config : Cache|null = null
- $cache : CacheInterface|null = null
- $getShared : bool = true
Return values
ResponseCacherouter()
public
static router([RouteCollectionInterface $routes = null ][, Request $request = null ][, mixed $getShared = true ]) : Router
Parameters
- $routes : RouteCollectionInterface = null
- $request : Request = null
- $getShared : mixed = true
Return values
Routerroutes()
public
static routes([mixed $getShared = true ]) : RouteCollection
Parameters
- $getShared : mixed = true
Return values
RouteCollectionsecurity()
public
static security([App $config = null ][, mixed $getShared = true ]) : Security
Parameters
- $config : App = null
- $getShared : mixed = true
Return values
SecurityserviceExists()
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|nullsession()
public
static session([Session $config = null ][, mixed $getShared = true ]) : Session
Parameters
- $config : Session = null
- $getShared : mixed = true
Return values
Sessionset()
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
SiteURIFactorysuperglobals()
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
Superglobalsthrottler()
public
static throttler([mixed $getShared = true ]) : Throttler
Parameters
- $getShared : mixed = true
Return values
Throttlertimer()
public
static timer([mixed $getShared = true ]) : Timer
Parameters
- $getShared : mixed = true
Return values
Timertoolbar()
public
static toolbar([Toolbar $config = null ][, mixed $getShared = true ]) : Toolbar
Parameters
- $config : Toolbar = null
- $getShared : mixed = true
Return values
Toolbartypography()
public
static typography([mixed $getShared = true ]) : Typography
Parameters
- $getShared : mixed = true
Return values
Typographyuri()
public
static uri([mixed $uri = null ][, mixed $getShared = true ]) : URI
Parameters
- $uri : mixed = null
- $getShared : mixed = true
Return values
URIvalidation()
public
static validation([Validation $config = null ][, mixed $getShared = true ]) : ValidationInterface
Parameters
- $config : Validation = null
- $getShared : mixed = true
Return values
ValidationInterfaceviewcell()
public
static viewcell([mixed $getShared = true ]) : Cell
Parameters
- $getShared : mixed = true
Return values
CellbuildServicesCache()
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