Services
extends 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.
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.
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
- The cache class provides a simple way to store and retrieve complex data for later.
- clirequest() : CLIRequest
- codeigniter() : CodeIgniter
- CodeIgniter, the core of the framework.
- commands() : Commands
- The commands utility for running and working with CLI commands.
- createRequest() : void
- csp() : ContentSecurityPolicy
- Content Security Policy
- curlrequest() : CURLRequest
- The CURL Request class acts as a simple HTTP client for interacting with other servers, typically through APIs.
- email() : Email
- The Email class allows you to send email via mail, sendmail, SMTP.
- encrypter() : EncrypterInterface
- The Encryption class provides two-way encryption.
- exceptions() : Exceptions
- The Exceptions class holds the methods that handle:
- filters() : Filters
- Filters allow you to run tasks before and/or after a controller is executed. During before filters, the request can be modified, and actions taken based on the request, while after filters can act on or modify the response itself before it is sent to the client.
- format() : Format
- The Format class is a convenient place to create Formatters.
- get() : object|null
- Simple method to get an entry fast.
- honeypot() : Honeypot
- The Honeypot provides a secret input on forms that bots should NOT fill in, providing an additional safeguard when accepting user input.
- image() : BaseHandler
- Acts as a factory for ImageHandler classes and returns an instance of the handler. Used like service('image')->withFile($path)->rotate(90)->save();
- incomingrequest() : IncomingRequest
- injectMock() : void
- Inject mock object for testing.
- iterator() : Iterator
- The Iterator class provides a simple way of looping over a function and timing the results and memory usage. Used when debugging and optimizing applications.
- language() : Language
- Responsible for loading the language string translations.
- 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
- The Logger class is a PSR-3 compatible Logging class that supports multiple handlers that process the actual logging.
- migrations() : MigrationRunner
- Return the appropriate Migration runner.
- negotiator() : Negotiate
- The Negotiate class provides the content negotiation features for working the request to determine correct language, encoding, charset, and more.
- override() : void
- Overrides an existing entry.
- pager() : Pager
- Return the appropriate pagination handler.
- parser() : Parser
- The Parser is a simple template parser.
- redirectresponse() : RedirectResponse
- The Redirect class provides nice way of working with redirects.
- renderer() : View
- The Renderer class is the class that actually displays a file to the user.
- request() : CLIRequest|IncomingRequest
- Returns the current Request object.
- reset() : void
- Reset shared instances and mocks for testing.
- resetServicesCache() : void
- Resets the service cache.
- resetSingle() : void
- Resets any mock and shared instances for a single service.
- response() : ResponseInterface
- The Response class models an HTTP response.
- responsecache() : ResponseCache
- Return the ResponseCache.
- router() : Router
- The Router class uses a RouteCollection's array of routes, and determines the correct Controller and Method to execute.
- routes() : RouteCollection
- The Routes service is a class that allows for easily building a collection of routes.
- security() : Security
- The Security class provides a few handy tools for keeping the site secure, most notably the CSRF protection tools.
- serviceExists() : string|null
- Check if the requested service is defined and return the declaring class. Return null if not found.
- session() : Session
- Return the session manager.
- set() : void
- Sets an entry.
- siteurifactory() : SiteURIFactory
- The Factory for SiteURI.
- superglobals() : Superglobals
- Superglobals.
- throttler() : Throttler
- The Throttler class provides a simple method for implementing rate limiting in your applications.
- timer() : Timer
- The Timer class provides a simple way to Benchmark portions of your application.
- toolbar() : Toolbar
- Return the debug toolbar.
- typography() : Typography
- The Typography class provides a way to format text in semantically relevant ways.
- uri() : URI
- The URI class provides a way to model and manipulate URIs.
- validation() : ValidationInterface
- The Validation class provides tools for validating input data.
- viewcell() : Cell
- View cells are intended to let you insert HTML into view that has been generated by any callable in the system.
- 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
= []
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()
The cache class provides a simple way to store and retrieve complex data for later.
public
static cache([Cache|null $config = null ][, bool $getShared = true ]) : CacheInterface
Parameters
- $config : Cache|null = null
- $getShared : bool = true
Return values
CacheInterfaceclirequest()
public
static clirequest([App $config = = 'null' ][, mixed $getShared = = 'true' ]) : CLIRequest
Parameters
- $config : App = = 'null'
- $getShared : mixed = = 'true'
Return values
CLIRequestcodeigniter()
CodeIgniter, the core of the framework.
public
static codeigniter([App|null $config = null ][, bool $getShared = true ]) : CodeIgniter
Parameters
- $config : App|null = null
- $getShared : bool = true
Return values
CodeIgnitercommands()
The commands utility for running and working with CLI commands.
public
static commands([bool $getShared = true ]) : Commands
Parameters
- $getShared : bool = true
Return values
CommandscreateRequest()
public
static createRequest(App $config[, bool $isCli = = 'false' ]) : void
Parameters
- $config : App
- $isCli : bool = = 'false'
csp()
Content Security Policy
public
static csp([ContentSecurityPolicy|null $config = null ][, bool $getShared = true ]) : ContentSecurityPolicy
Parameters
- $config : ContentSecurityPolicy|null = null
- $getShared : bool = true
Return values
ContentSecurityPolicycurlrequest()
The CURL Request class acts as a simple HTTP client for interacting with other servers, typically through APIs.
public
static curlrequest([array<string|int, mixed> $options = [] ][, ResponseInterface|null $response = null ][, App|null $config = null ][, bool $getShared = true ]) : CURLRequest
Parameters
- $options : array<string|int, mixed> = []
- $response : ResponseInterface|null = null
- $config : App|null = null
- $getShared : bool = true
Return values
CURLRequestemail()
The Email class allows you to send email via mail, sendmail, SMTP.
public
static email([array<string|int, mixed>|Email|null $config = null ][, bool $getShared = true ]) : Email
Parameters
- $config : array<string|int, mixed>|Email|null = null
- $getShared : bool = true
Return values
Emailencrypter()
The Encryption class provides two-way encryption.
public
static encrypter([Encryption|null $config = null ][, bool $getShared = false ]) : EncrypterInterface
Parameters
- $config : Encryption|null = null
- $getShared : bool = false
Return values
EncrypterInterface —Encryption handler
exceptions()
The Exceptions class holds the methods that handle:
public
static exceptions([Exceptions|null $config = null ][, bool $getShared = true ]) : Exceptions
- set_exception_handler
- set_error_handler
- register_shutdown_function
Parameters
- $config : Exceptions|null = null
- $getShared : bool = true
Return values
Exceptionsfilters()
Filters allow you to run tasks before and/or after a controller is executed. During before filters, the request can be modified, and actions taken based on the request, while after filters can act on or modify the response itself before it is sent to the client.
public
static filters([Filters|null $config = null ][, bool $getShared = true ]) : Filters
Parameters
- $config : Filters|null = null
- $getShared : bool = true
Return values
Filtersformat()
The Format class is a convenient place to create Formatters.
public
static format([Format|null $config = null ][, bool $getShared = true ]) : Format
Parameters
- $config : Format|null = null
- $getShared : bool = 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()
The Honeypot provides a secret input on forms that bots should NOT fill in, providing an additional safeguard when accepting user input.
public
static honeypot([Honeypot|null $config = null ][, bool $getShared = true ]) : Honeypot
Parameters
- $config : Honeypot|null = null
- $getShared : bool = true
Return values
Honeypotimage()
Acts as a factory for ImageHandler classes and returns an instance of the handler. Used like service('image')->withFile($path)->rotate(90)->save();
public
static image([string|null $handler = null ][, Images|null $config = null ][, bool $getShared = true ]) : BaseHandler
Parameters
- $handler : string|null = null
- $config : Images|null = null
- $getShared : bool = 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()
The Iterator class provides a simple way of looping over a function and timing the results and memory usage. Used when debugging and optimizing applications.
public
static iterator([bool $getShared = true ]) : Iterator
Parameters
- $getShared : bool = true
Return values
Iteratorlanguage()
Responsible for loading the language string translations.
public
static language([string|null $locale = null ][, bool $getShared = true ]) : Language
Parameters
- $locale : string|null = null
- $getShared : bool = 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()
The Logger class is a PSR-3 compatible Logging class that supports multiple handlers that process the actual logging.
public
static logger([bool $getShared = true ]) : Logger
Parameters
- $getShared : bool = true
Return values
Loggermigrations()
Return the appropriate Migration runner.
public
static migrations([Migrations|null $config = null ][, ConnectionInterface|null $db = null ][, bool $getShared = true ]) : MigrationRunner
Parameters
- $config : Migrations|null = null
- $db : ConnectionInterface|null = null
- $getShared : bool = true
Return values
MigrationRunnernegotiator()
The Negotiate class provides the content negotiation features for working the request to determine correct language, encoding, charset, and more.
public
static negotiator([RequestInterface|null $request = null ][, bool $getShared = true ]) : Negotiate
Parameters
- $request : RequestInterface|null = null
- $getShared : bool = 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()
Return the appropriate pagination handler.
public
static pager([Pager|null $config = null ][, RendererInterface|null $view = null ][, bool $getShared = true ]) : Pager
Parameters
- $config : Pager|null = null
- $view : RendererInterface|null = null
- $getShared : bool = true
Return values
Pagerparser()
The Parser is a simple template parser.
public
static parser([string|null $viewPath = null ][, View|null $config = null ][, bool $getShared = true ]) : Parser
Parameters
- $viewPath : string|null = null
- $config : View|null = null
- $getShared : bool = true
Return values
Parserredirectresponse()
The Redirect class provides nice way of working with redirects.
public
static redirectresponse([App|null $config = null ][, bool $getShared = true ]) : RedirectResponse
Parameters
- $config : App|null = null
- $getShared : bool = true
Return values
RedirectResponserenderer()
The Renderer class is the class that actually displays a file to the user.
public
static renderer([string|null $viewPath = null ][, View|null $config = null ][, bool $getShared = true ]) : View
The default View class within CodeIgniter is intentionally simple, but this service could easily be replaced by a template engine if the user needed to.
Parameters
- $viewPath : string|null = null
- $config : View|null = null
- $getShared : bool = true
Return values
Viewrequest()
Returns the current Request object.
public
static request([App|null $config = null ][, bool $getShared = true ]) : CLIRequest|IncomingRequest
The parameter $config and $getShared are deprecated.
createRequest() injects IncomingRequest or CLIRequest.
Parameters
- $config : App|null = null
- $getShared : bool = true
Return values
CLIRequest|IncomingRequestreset()
Reset shared instances and mocks for testing.
public
static reset([bool $initAutoloader = true ]) : void
Parameters
- $initAutoloader : bool = true
Tags
resetServicesCache()
Resets the service cache.
public
static resetServicesCache() : void
resetSingle()
Resets any mock and shared instances for a single service.
public
static resetSingle(string $name) : void
Parameters
- $name : string
Tags
response()
The Response class models an HTTP response.
public
static response([App|null $config = null ][, bool $getShared = true ]) : ResponseInterface
Parameters
- $config : App|null = null
- $getShared : bool = true
Return values
ResponseInterfaceresponsecache()
Return the ResponseCache.
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()
The Router class uses a RouteCollection's array of routes, and determines the correct Controller and Method to execute.
public
static router([RouteCollectionInterface|null $routes = null ][, Request|null $request = null ][, bool $getShared = true ]) : Router
Parameters
- $routes : RouteCollectionInterface|null = null
- $request : Request|null = null
- $getShared : bool = true
Return values
Routerroutes()
The Routes service is a class that allows for easily building a collection of routes.
public
static routes([bool $getShared = true ]) : RouteCollection
Parameters
- $getShared : bool = true
Return values
RouteCollectionsecurity()
The Security class provides a few handy tools for keeping the site secure, most notably the CSRF protection tools.
public
static security([Security|null $config = null ][, bool $getShared = true ]) : Security
Parameters
- $config : Security|null = null
- $getShared : bool = 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()
Return the session manager.
public
static session([Session|null $config = null ][, bool $getShared = true ]) : Session
Parameters
- $config : Session|null = null
- $getShared : bool = 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()
The Factory for SiteURI.
public
static siteurifactory([App|null $config = null ][, Superglobals|null $superglobals = null ][, bool $getShared = true ]) : SiteURIFactory
Parameters
- $config : App|null = null
- $superglobals : Superglobals|null = null
- $getShared : bool = true
Return values
SiteURIFactorysuperglobals()
Superglobals.
public
static superglobals([array<string|int, mixed>|null $server = null ][, array<string|int, mixed>|null $get = null ][, bool $getShared = true ]) : Superglobals
Parameters
- $server : array<string|int, mixed>|null = null
- $get : array<string|int, mixed>|null = null
- $getShared : bool = true
Return values
Superglobalsthrottler()
The Throttler class provides a simple method for implementing rate limiting in your applications.
public
static throttler([bool $getShared = true ]) : Throttler
Parameters
- $getShared : bool = true
Return values
Throttlertimer()
The Timer class provides a simple way to Benchmark portions of your application.
public
static timer([bool $getShared = true ]) : Timer
Parameters
- $getShared : bool = true
Return values
Timertoolbar()
Return the debug toolbar.
public
static toolbar([Toolbar|null $config = null ][, bool $getShared = true ]) : Toolbar
Parameters
- $config : Toolbar|null = null
- $getShared : bool = true
Return values
Toolbartypography()
The Typography class provides a way to format text in semantically relevant ways.
public
static typography([bool $getShared = true ]) : Typography
Parameters
- $getShared : bool = true
Return values
Typographyuri()
The URI class provides a way to model and manipulate URIs.
public
static uri([string|null $uri = null ][, bool $getShared = true ]) : URI
Parameters
- $uri : string|null = null
-
The URI string
- $getShared : bool = true
Return values
URI —The current URI if $uri is null.
validation()
The Validation class provides tools for validating input data.
public
static validation([Validation|null $config = null ][, bool $getShared = true ]) : ValidationInterface
Parameters
- $config : Validation|null = null
- $getShared : bool = true
Return values
ValidationInterfaceviewcell()
View cells are intended to let you insert HTML into view that has been generated by any callable in the system.
public
static viewcell([bool $getShared = true ]) : Cell
Parameters
- $getShared : bool = 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