\CodeIgniter\ConfigServices

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.

Summary

Methods
Properties
Constants
autoloader()
locator()
__callStatic()
reset()
injectMock()
cache()
clirequest()
curlrequest()
email()
encrypter()
exceptions()
filters()
honeypot()
image()
iterator()
language()
logger()
migrations()
negotiator()
pager()
parser()
renderer()
request()
response()
redirectResponse()
routes()
router()
security()
session()
throttler()
timer()
toolbar()
uri()
validation()
viewcell()
typography()
No public properties found
No constants found
getSharedInstance()
discoverServices()
$instances
$mocks
$discovered
$services
N/A
No private methods found
No private properties found
N/A

Properties

$instances

$instances : array

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

Type

array

$mocks

$mocks : array

Mock objects for testing which are returned if exist.

Type

array

$discovered

$discovered : boolean

Have we already discovered other Services?

Type

boolean

$services

$services : array

A cache of other service classes we've found.

Type

array

Methods

autoloader()

autoloader(boolean  $getShared = true) : \CodeIgniter\Autoloader\Autoloader

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

Parameters

boolean $getShared

Returns

\CodeIgniter\Autoloader\Autoloader

locator()

locator(boolean  $getShared = true) : \CodeIgniter\Autoloader\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'.

Parameters

boolean $getShared

Returns

\CodeIgniter\Autoloader\FileLocator

__callStatic()

__callStatic(string  $name, array  $arguments) : mixed

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

Parameters

string $name
array $arguments

Returns

mixed

reset()

reset(boolean  $init_autoloader = false) 

Reset shared instances and mocks for testing.

Parameters

boolean $init_autoloader

Initializes autoloader instance

injectMock()

injectMock(string  $name,   $mock) 

Inject mock object for testing.

Parameters

string $name
$mock

cache()

cache(\Config\Cache  $config = null, boolean  $getShared = true) : \CodeIgniter\Cache\CacheInterface

The cache class provides a simple way to store and retrieve complex data for later.

Parameters

\Config\Cache $config
boolean $getShared

Returns

\CodeIgniter\Cache\CacheInterface

clirequest()

clirequest(\Config\App  $config = null, boolean  $getShared = true) : \CodeIgniter\HTTP\CLIRequest

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

Parameters

\Config\App $config
boolean $getShared

Returns

\CodeIgniter\HTTP\CLIRequest

curlrequest()

curlrequest(array  $options = array(), \CodeIgniter\HTTP\ResponseInterface  $response = null, \Config\App  $config = null, boolean  $getShared = true) : \CodeIgniter\HTTP\CURLRequest

The CURL Request class acts as a simple HTTP client for interacting with other servers, typically through APIs.

Parameters

array $options
\CodeIgniter\HTTP\ResponseInterface $response
\Config\App $config
boolean $getShared

Returns

\CodeIgniter\HTTP\CURLRequest

email()

email(null  $config = null, boolean  $getShared = true) : \CodeIgniter\Email\Email|mixed

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

Parameters

null $config
boolean $getShared

Returns

\CodeIgniter\Email\Email|mixed

encrypter()

encrypter(mixed  $config = null, boolean  $getShared = false) : \CodeIgniter\Encryption\EncrypterInterface

The Encryption class provides two-way encryption.

Parameters

mixed $config
boolean $getShared

Returns

\CodeIgniter\Encryption\EncrypterInterface

Encryption handler

exceptions()

exceptions(\Config\Exceptions  $config = null, \CodeIgniter\HTTP\IncomingRequest  $request = null, \CodeIgniter\HTTP\Response  $response = null, boolean  $getShared = true) : \CodeIgniter\Debug\Exceptions

The Exceptions class holds the methods that handle:

  • set_exception_handler
    • set_error_handler
    • register_shutdown_function

Parameters

\Config\Exceptions $config
\CodeIgniter\HTTP\IncomingRequest $request
\CodeIgniter\HTTP\Response $response
boolean $getShared

Returns

\CodeIgniter\Debug\Exceptions

filters()

filters(mixed  $config = null, boolean  $getShared = true) : \CodeIgniter\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.

Parameters

mixed $config
boolean $getShared

Returns

\CodeIgniter\Filters\Filters

honeypot()

honeypot(\CodeIgniter\Config\BaseConfig|null  $config = null, boolean  $getShared = true) : \CodeIgniter\Honeypot\Honeypot|mixed

The Honeypot provides a secret input on forms that bots should NOT fill in, providing an additional safeguard when accepting user input.

Parameters

\CodeIgniter\Config\BaseConfig|null $config
boolean $getShared

Returns

\CodeIgniter\Honeypot\Honeypot|mixed

image()

image(string  $handler = null, mixed  $config = null, boolean  $getShared = true) : \CodeIgniter\Images\Handlers\BaseHandler

Acts as a factory for ImageHandler classes and returns an instance of the handler. Used like Services::image()->withFile($path)->rotate(90)->save();

Parameters

string $handler
mixed $config
boolean $getShared

Returns

\CodeIgniter\Images\Handlers\BaseHandler

iterator()

iterator(boolean  $getShared = true) : \CodeIgniter\Debug\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.

Parameters

boolean $getShared

Returns

\CodeIgniter\Debug\Iterator

language()

language(string  $locale = null, boolean  $getShared = true) : \CodeIgniter\Language\Language

Responsible for loading the language string translations.

Parameters

string $locale
boolean $getShared

Returns

\CodeIgniter\Language\Language

logger()

logger(boolean  $getShared = true) : \CodeIgniter\Log\Logger

The Logger class is a PSR-3 compatible Logging class that supports multiple handlers that process the actual logging.

Parameters

boolean $getShared

Returns

\CodeIgniter\Log\Logger

migrations()

migrations(\CodeIgniter\Config\BaseConfig  $config = null, \CodeIgniter\Database\ConnectionInterface  $db = null, boolean  $getShared = true) : \CodeIgniter\Database\MigrationRunner

Return the appropriate igration runner.

Parameters

\CodeIgniter\Config\BaseConfig $config
\CodeIgniter\Database\ConnectionInterface $db
boolean $getShared

Returns

\CodeIgniter\Database\MigrationRunner

negotiator()

negotiator(\CodeIgniter\HTTP\RequestInterface  $request = null, boolean  $getShared = true) : \CodeIgniter\HTTP\Negotiate

The Negotiate class provides the content negotiation features for working the request to determine correct language, encoding, charset, and more.

Parameters

\CodeIgniter\HTTP\RequestInterface $request
boolean $getShared

Returns

\CodeIgniter\HTTP\Negotiate

pager()

pager(mixed  $config = null, \CodeIgniter\View\RendererInterface  $view = null, boolean  $getShared = true) : \CodeIgniter\Pager\Pager

Return the appropriate pagination handler.

Parameters

mixed $config
\CodeIgniter\View\RendererInterface $view
boolean $getShared

Returns

\CodeIgniter\Pager\Pager

parser()

parser(string  $viewPath = null, mixed  $config = null, boolean  $getShared = true) : \CodeIgniter\View\Parser

The Parser is a simple template parser.

Parameters

string $viewPath
mixed $config
boolean $getShared

Returns

\CodeIgniter\View\Parser

renderer()

renderer(string  $viewPath = null, mixed  $config = null, boolean  $getShared = true) : \CodeIgniter\View\View

The Renderer class is the class that actually displays a file to the user.

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

string $viewPath
mixed $config
boolean $getShared

Returns

\CodeIgniter\View\View

request()

request(\Config\App  $config = null, boolean  $getShared = true) : \CodeIgniter\HTTP\IncomingRequest

The Request class models an HTTP request.

Parameters

\Config\App $config
boolean $getShared

Returns

\CodeIgniter\HTTP\IncomingRequest

response()

response(\Config\App  $config = null, boolean  $getShared = true) : \CodeIgniter\HTTP\Response

The Response class models an HTTP response.

Parameters

\Config\App $config
boolean $getShared

Returns

\CodeIgniter\HTTP\Response

redirectResponse()

redirectResponse(\Config\App  $config = null, boolean  $getShared = true) : \CodeIgniter\HTTP\Response

The Redirect class provides nice way of working with redirects.

Parameters

\Config\App $config
boolean $getShared

Returns

\CodeIgniter\HTTP\Response

routes()

routes(boolean  $getShared = true) : \CodeIgniter\Router\RouteCollection

The Routes service is a class that allows for easily building a collection of routes.

Parameters

boolean $getShared

Returns

\CodeIgniter\Router\RouteCollection

router()

router(\CodeIgniter\Router\RouteCollectionInterface  $routes = null, \CodeIgniter\HTTP\Request  $request = null, boolean  $getShared = true) : \CodeIgniter\Router\Router

The Router class uses a RouteCollection's array of routes, and determines the correct Controller and Method to execute.

Parameters

\CodeIgniter\Router\RouteCollectionInterface $routes
\CodeIgniter\HTTP\Request $request
boolean $getShared

Returns

\CodeIgniter\Router\Router

security()

security(\Config\App  $config = null, boolean  $getShared = true) : \CodeIgniter\Security\Security

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

Parameters

\Config\App $config
boolean $getShared

Returns

\CodeIgniter\Security\Security

session()

session(\Config\App  $config = null, boolean  $getShared = true) : \CodeIgniter\Session\Session

Return the session manager.

Parameters

\Config\App $config
boolean $getShared

Returns

\CodeIgniter\Session\Session

throttler()

throttler(boolean  $getShared = true) : \CodeIgniter\Throttle\Throttler

The Throttler class provides a simple method for implementing rate limiting in your applications.

Parameters

boolean $getShared

Returns

\CodeIgniter\Throttle\Throttler

timer()

timer(boolean  $getShared = true) : \CodeIgniter\Debug\Timer

The Timer class provides a simple way to Benchmark portions of your application.

Parameters

boolean $getShared

Returns

\CodeIgniter\Debug\Timer

toolbar()

toolbar(\Config\Toolbar  $config = null, boolean  $getShared = true) : \CodeIgniter\Debug\Toolbar

Return the debug toolbar.

Parameters

\Config\Toolbar $config
boolean $getShared

Returns

\CodeIgniter\Debug\Toolbar

uri()

uri(string  $uri = null, boolean  $getShared = true) : \CodeIgniter\HTTP\URI

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

Parameters

string $uri
boolean $getShared

Returns

\CodeIgniter\HTTP\URI

validation()

validation(\Config\Validation  $config = null, boolean  $getShared = true) : \CodeIgniter\Validation\Validation

The Validation class provides tools for validating input data.

Parameters

\Config\Validation $config
boolean $getShared

Returns

\CodeIgniter\Validation\Validation

viewcell()

viewcell(boolean  $getShared = true) : \CodeIgniter\View\Cell

View cells are intended to let you insert HTML into view that has been generated by any callable in the system.

Parameters

boolean $getShared

Returns

\CodeIgniter\View\Cell

typography()

typography(boolean  $getShared = true) : \CodeIgniter\Typography\Typography

The Typography class provides a way to format text in semantically relevant ways.

Parameters

boolean $getShared

Returns

\CodeIgniter\Typography\Typography

getSharedInstance()

getSharedInstance(string  $key, array  ...$params) : mixed

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

$key must be a name matching a service.

Parameters

string $key
array $params variadic

Returns

mixed

discoverServices()

discoverServices(string  $name, array  $arguments) : 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.

Parameters

string $name
array $arguments

Returns

mixed