Documentation

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
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

$discovered  : bool
Have we already discovered other Services?
$instances  : array<string|int, mixed>
Cache for instance of any services that have been requested as a "shared" instance.
$mocks  : array<string|int, mixed>
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<string|int, string>
A cache of the names of services classes found.
__callStatic()  : mixed
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()  :
cache()  : CacheInterface
The cache class provides a simple way to store and retrieve complex data for later.
clirequest()  :
clirequest()  : CLIRequest
The CLI Request class provides for ways to interact with a command line request.
codeigniter()  :
codeigniter()  : CodeIgniter
CodeIgniter, the core of the framework.
commands()  :
commands()  : Commands
The commands utility for running and working with CLI commands.
curlrequest()  :
curlrequest()  : CURLRequest
The CURL Request class acts as a simple HTTP client for interacting with other servers, typically through APIs.
email()  :
email()  : Email
The Email class allows you to send email via mail, sendmail, SMTP.
encrypter()  :
encrypter()  : EncrypterInterface
The Encryption class provides two-way encryption.
exceptions()  :
exceptions()  : Exceptions
The Exceptions class holds the methods that handle:
filters()  :
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()  : Format
The Format class is a convenient place to create Formatters.
honeypot()  :
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()  :
image()  : BaseHandler
Acts as a factory for ImageHandler classes and returns an instance of the handler. Used like Services::image()->withFile($path)->rotate(90)->save();
injectMock()  : mixed
Inject mock object for testing.
iterator()  :
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()  : Language
Responsible for loading the language string translations.
locator()  : FileLocator
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()  : Logger
The Logger class is a PSR-3 compatible Logging class that supports multiple handlers that process the actual logging.
migrations()  :
migrations()  : MigrationRunner
Return the appropriate Migration runner.
negotiator()  :
negotiator()  : Negotiate
The Negotiate class provides the content negotiation features for working the request to determine correct language, encoding, charset, and more.
pager()  :
pager()  : Pager
Return the appropriate pagination handler.
parser()  :
parser()  : Parser
The Parser is a simple template parser.
redirectresponse()  :
redirectresponse()  : RedirectResponse
The Redirect class provides nice way of working with redirects.
renderer()  :
renderer()  : View
The Renderer class is the class that actually displays a file to the user.
request()  :
request()  : IncomingRequest
The Request class models an HTTP request.
reset()  : mixed
Reset shared instances and mocks for testing.
resetSingle()  : mixed
Resets any mock and shared instances for a single service.
response()  :
response()  : Response
The Response class models an HTTP response.
router()  :
router()  : Router
The Router class uses a RouteCollection's array of routes, and determines the correct Controller and Method to execute.
routes()  :
routes()  : RouteCollection
The Routes service is a class that allows for easily building a collection of routes.
security()  :
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()  : Session
Return the session manager.
throttler()  :
throttler()  : Throttler
The Throttler class provides a simple method for implementing rate limiting in your applications.
timer()  :
timer()  : Timer
The Timer class provides a simple way to Benchmark portions of your application.
toolbar()  :
toolbar()  : Toolbar
Return the debug toolbar.
typography()  :
typography()  : Typography
The Typography class provides a way to format text in semantically relevant ways.
uri()  :
uri()  : URI
The URI class provides a way to model and manipulate URIs.
validation()  :
validation()  : Validation
The Validation class provides tools for validating input data.
viewcell()  :
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
discoverServices()  : mixed
Will scan all psr4 namespaces registered with system to look for new Config\Services files. Caches a copy of each one, then looks for the service method in each, returning an instance of the service, if available.
getSharedInstance()  : mixed
Returns a shared instance of any of the class' services.

Properties

$discovered

Have we already discovered other Services?

protected static bool $discovered = false

$instances

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

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

Keys should be lowercase service names.

$mocks

Mock objects for testing which are returned if exist.

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

$services

A cache of other service classes we've found.

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

$serviceNames

A cache of the names of services classes found.

private static array<string|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) : mixed
Parameters
$name : string
$arguments : array<string|int, mixed>
Return values
mixed

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

cache()

public static cache(Cache $config = null, mixed $getShared) :
Parameters
$config = null : Cache
$getShared : mixed
Return values

cache()

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
CacheInterface

clirequest()

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

clirequest()

The CLI Request class provides for ways to interact with a command line request.

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

codeigniter()

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

codeigniter()

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
CodeIgniter

commands()

public static commands(mixed $getShared) :
Parameters
$getShared : mixed
Return values

commands()

The commands utility for running and working with CLI commands.

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

curlrequest()

public static curlrequest(mixed $options, ResponseInterface $response = null, App $config = null, mixed $getShared) :
Parameters
$options : mixed
$response = null : ResponseInterface
$config = null : App
$getShared : mixed
Return values

curlrequest()

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
CURLRequest

email()

public static email(mixed $config, mixed $getShared) :
Parameters
$config : mixed
$getShared : mixed
Return values

email()

The Email class allows you to send email via mail, sendmail, SMTP.

public static email([Email|array<string|int, mixed>|null $config = null ][, bool $getShared = true ]) : Email
Parameters
$config : Email|array<string|int, mixed>|null = null
$getShared : bool = true
Return values
Email

encrypter()

public static encrypter(Encryption $config = null, mixed $getShared) :
Parameters
$config = null : Encryption
$getShared : mixed
Return values

exceptions()

The Exceptions class holds the methods that handle:

public static exceptions([Exceptions|null $config = null ][, IncomingRequest|null $request = null ][, Response|null $response = null ][, bool $getShared = true ]) : Exceptions
  • set_exception_handler
  • set_error_handler
  • register_shutdown_function
Parameters
$config : Exceptions|null = null
$request : IncomingRequest|null = null
$response : Response|null = null
$getShared : bool = true
Return values
Exceptions

filters()

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

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.

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

format()

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

format()

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
Format

honeypot()

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

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
Honeypot

image()

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

image()

Acts as a factory for ImageHandler classes and returns an instance of the handler. Used like Services::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
BaseHandler

injectMock()

Inject mock object for testing.

public static injectMock(string $name, mixed $mock) : mixed
Parameters
$name : string
$mock : mixed
Return values
mixed

iterator()

public static iterator(mixed $getShared) :
Parameters
$getShared : mixed
Return values

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
Iterator

language()

public static language(mixed $locale, mixed $getShared) :
Parameters
$locale : mixed
$getShared : mixed
Return values

language()

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
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 ]) : FileLocator
Parameters
$getShared : bool = true
Return values
FileLocator

logger()

public static logger(mixed $getShared) :
Parameters
$getShared : mixed
Return values

logger()

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
Logger

negotiator()

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
Negotiate

parser()

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

parser()

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
Parser

redirectresponse()

public static redirectresponse(App $config = null, mixed $getShared) :
Parameters
$config = null : App
$getShared : mixed
Return values

redirectresponse()

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
RedirectResponse

renderer()

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

renderer()

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
View

request()

public static request(App $config = null, mixed $getShared) :
Parameters
$config = null : App
$getShared : mixed
Return values

request()

The Request class models an HTTP request.

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

reset()

Reset shared instances and mocks for testing.

public static reset([bool $initAutoloader = false ]) : mixed
Parameters
$initAutoloader : bool = false

Initializes autoloader instance

Return values
mixed

resetSingle()

Resets any mock and shared instances for a single service.

public static resetSingle(string $name) : mixed
Parameters
$name : string
Return values
mixed

response()

public static response(App $config = null, mixed $getShared) :
Parameters
$config = null : App
$getShared : mixed
Return values

response()

The Response class models an HTTP response.

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

router()

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
Router

routes()

public static routes(mixed $getShared) :
Parameters
$getShared : mixed
Return values

routes()

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
RouteCollection

security()

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

security()

The Security class provides a few handy tools for keeping the site secure, most notably the CSRF protection tools.

public static security([App|null $config = null ][, bool $getShared = true ]) : Security
Parameters
$config : App|null = null
$getShared : bool = 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(App $config = null, mixed $getShared) :
Parameters
$config = null : App
$getShared : mixed
Return values

session()

Return the session manager.

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

throttler()

public static throttler(mixed $getShared) :
Parameters
$getShared : mixed
Return values

throttler()

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
Throttler

timer()

public static timer(mixed $getShared) :
Parameters
$getShared : mixed
Return values

timer()

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
Timer

toolbar()

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

toolbar()

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
Toolbar

typography()

public static typography(mixed $getShared) :
Parameters
$getShared : mixed
Return values

typography()

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
Typography

uri()

public static uri(mixed $uri, mixed $getShared) :
Parameters
$uri : mixed
$getShared : mixed
Return values

uri()

The URI class provides a way to model and manipulate URIs.

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

validation()

public static validation(Validation $config = null, mixed $getShared) :
Parameters
$config = null : Validation
$getShared : mixed
Return values

validation()

The Validation class provides tools for validating input data.

public static validation([Validation|null $config = null ][, bool $getShared = true ]) : Validation
Parameters
$config : Validation|null = null
$getShared : bool = true
Return values
Validation

viewcell()

public static viewcell(mixed $getShared) :
Parameters
$getShared : mixed
Return values

viewcell()

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
Cell

buildServicesCache()

protected static buildServicesCache() : void
Return values
void

discoverServices()

Will scan all psr4 namespaces registered with system to look for new Config\Services files. Caches a copy of each one, then looks for the service method in each, returning an instance of the service, if available.

protected static discoverServices(string $name, array<string|int, mixed> $arguments) : mixed
Parameters
$name : string
$arguments : array<string|int, mixed>
Tags
deprecated
codeCoverageIgnore
Return values
mixed

getSharedInstance()

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

protected static getSharedInstance(string $key, mixed ...$params) : mixed

$key must be a name matching a service.

Parameters
$key : string
$params : mixed
Return values
mixed

Search results