Documentation

Locator extends AbstractManager
in package

Service locator class

Tags
category

Pop

author

Nick Sagona, III dev@noladev.com

copyright

Copyright (c) 2009-2026 NOLA Interactive, LLC.

license

https://www.popphp.org/license New BSD License

version
4.4.0

Table of Contents

Properties

$items  : array<string|int, mixed>
Manager items
$loaded  : array<string|int, mixed>
Services that are loaded/instantiated
$called  : array<string|int, mixed>
Recursion called service name tracker
$depth  : int
Recursion depth level tracker

Methods

__construct()  : mixed
Constructor
__get()  : mixed
Get a service
__isset()  : bool
Determine if a service is available
__set()  : void
Set a service
__unset()  : void
Unset a service
addItem()  : static
Add an item
addItems()  : static
Add items
addParameter()  : static
Add to a service's parameters
count()  : int
Return count
get()  : mixed
Get/load a service
getCallable()  : mixed
Get a service's callable string or object
getItem()  : mixed
Get an item
getItems()  : array<string|int, mixed>
Get items
getIterator()  : ArrayIterator
Get iterator
getParameters()  : mixed
Get a service's parameters
hasItem()  : bool
Determine whether the manager has an item
hasItems()  : bool
Determine whether the manager has items
hasParameter()  : bool
Check if a service has parameters
isAvailable()  : bool
Determine of a service object is available (but not loaded)
isLoaded()  : bool
Determine of a service object is loaded
offsetExists()  : bool
Determine if a service is available
offsetGet()  : mixed
Get a service
offsetSet()  : void
Set a service
offsetUnset()  : void
Unset a service
reload()  : mixed
Re-load a service object
remove()  : static
Remove a service
removeItem()  : static
Remove an item
removeParameters()  : static
Remove a service's parameters
set()  : static
Set a service. It will overwrite any previous service with the same name.
setCallable()  : static
Set a service's callable string or object
setItems()  : static
Set items
setParameters()  : static
Set a service's parameters
setServices()  : static
Set service objects from an array of services

Properties

$loaded

Services that are loaded/instantiated

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

$called

Recursion called service name tracker

private static array<string|int, mixed> $called = []

$depth

Recursion depth level tracker

private static int $depth = 0

Methods

__construct()

Constructor

public __construct([array<string|int, mixed>|null $services = null ][, bool $default = true ]) : mixed

Instantiate the service locator object.

Parameters
$services : array<string|int, mixed>|null = null
$default : bool = true
Tags
throws
Exception

__get()

Get a service

public __get(string $name) : mixed
Parameters
$name : string
Tags
throws
Exception

__isset()

Determine if a service is available

public __isset(string $name) : bool
Parameters
$name : string
Return values
bool

__set()

Set a service

public __set(string $name, mixed $value) : void
Parameters
$name : string
$value : mixed
Tags
throws
Exception

__unset()

Unset a service

public __unset(string $name) : void
Parameters
$name : string

addItem()

Add an item

public addItem(mixed $item[, mixed $name = null ]) : static
Parameters
$item : mixed
$name : mixed = null
Return values
static

addItems()

Add items

public addItems(array<string|int, mixed> $items) : static
Parameters
$items : array<string|int, mixed>
Return values
static

addParameter()

Add to a service's parameters

public addParameter(string $name, mixed $param[, mixed $key = null ]) : static
Parameters
$name : string
$param : mixed
$key : mixed = null
Return values
static

get()

Get/load a service

public get(string $name) : mixed
Parameters
$name : string
Tags
throws
Exception

getCallable()

Get a service's callable string or object

public getCallable(string $name) : mixed
Parameters
$name : string

getItem()

Get an item

public getItem(mixed $name) : mixed
Parameters
$name : mixed

getItems()

Get items

public getItems() : array<string|int, mixed>
Return values
array<string|int, mixed>

getIterator()

Get iterator

public getIterator() : ArrayIterator
Return values
ArrayIterator

getParameters()

Get a service's parameters

public getParameters(string $name) : mixed
Parameters
$name : string

hasItem()

Determine whether the manager has an item

public hasItem(string $name) : bool
Parameters
$name : string
Return values
bool

hasItems()

Determine whether the manager has items

public hasItems() : bool
Return values
bool

hasParameter()

Check if a service has parameters

public hasParameter(string $name) : bool
Parameters
$name : string
Return values
bool

isAvailable()

Determine of a service object is available (but not loaded)

public isAvailable(string $name) : bool
Parameters
$name : string
Return values
bool

isLoaded()

Determine of a service object is loaded

public isLoaded(string $name) : bool
Parameters
$name : string
Return values
bool

offsetExists()

Determine if a service is available

public offsetExists(mixed $offset) : bool
Parameters
$offset : mixed
Return values
bool

offsetGet()

Get a service

public offsetGet(mixed $offset) : mixed
Parameters
$offset : mixed
Tags
throws
Exception

offsetSet()

Set a service

public offsetSet(mixed $offset, mixed $value) : void
Parameters
$offset : mixed
$value : mixed
Tags
throws
Exception

offsetUnset()

Unset a service

public offsetUnset(mixed $offset) : void
Parameters
$offset : mixed

reload()

Re-load a service object

public reload(string $name) : mixed
Parameters
$name : string

remove()

Remove a service

public remove(string $name) : static
Parameters
$name : string
Return values
static

removeItem()

Remove an item

public removeItem(mixed $name) : static
Parameters
$name : mixed
Return values
static

removeParameters()

Remove a service's parameters

public removeParameters(string $name, mixed $param[, mixed $key = null ]) : static
Parameters
$name : string
$param : mixed
$key : mixed = null
Return values
static

set()

Set a service. It will overwrite any previous service with the same name.

public set(string $name, mixed $service) : static

A service can be a CallableObject, callable string, or an array that contains a 'call' key and an optional 'params' key. Valid callable strings are:

'someFunction'
'SomeClass'
'SomeClass->foo'
'SomeClass::bar'
Parameters
$name : string
$service : mixed
Tags
throws
Exception
Return values
static

setCallable()

Set a service's callable string or object

public setCallable(string $name, mixed $call) : static
Parameters
$name : string
$call : mixed
Return values
static

setItems()

Set items

public setItems(array<string|int, mixed> $items) : static
Parameters
$items : array<string|int, mixed>
Return values
static

setParameters()

Set a service's parameters

public setParameters(string $name, mixed $params) : static
Parameters
$name : string
$params : mixed
Return values
static

setServices()

Set service objects from an array of services

public setServices(array<string|int, mixed> $services) : static
Parameters
$services : array<string|int, mixed>
Tags
throws
Exception
Return values
static

        
On this page

Search results