\CodeIgniter\ConfigBaseService

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

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