TableLocator
extends AbstractLocator
in package
implements
LocatorInterface
Provides a default registry/factory for Table objects.
Table of Contents
Interfaces
- LocatorInterface
- Registries for Table objects should implement this interface.
Properties
- $_config : array<string, array<string|int, mixed>|null>
- Configuration for aliases.
- $_fallbacked : array<string|int, Table>
- Contains a list of Table objects that were created out of the built-in Table class. The list is indexed by table alias
- $allowFallbackClass : bool
- Whether fallback class should be used if a table class could not be found.
- $fallbackClassName : string
- Fallback class to use
- $instances : array<string, Table>
- Instances that belong to the registry.
- $locations : array<string|int, string>
- Contains a list of locations where table classes should be looked for.
- $options : array<string, array<string|int, mixed>>
- Contains a list of options that were passed to get() method.
Methods
- __construct() : mixed
- Constructor.
- addLocation() : $this
- Adds a location where tables should be looked for.
- allowFallbackClass() : $this
- Set if fallback class should be used.
- clear() : void
- Clears the registry of configuration and instances.
- exists() : bool
- Check to see if an instance exists in the registry.
- genericInstances() : array<string|int, Table>
- Returns the list of tables that were created by this registry that could not be instantiated from a specific subclass. This method is useful for debugging common mistakes when setting up associations or created new table classes.
- get() : Table
- Get a table instance from the registry.
- getConfig() : array<string|int, mixed>
- Returns configuration for an alias or the full configuration array for all aliases.
- remove() : void
- Removes an repository instance from the registry.
- set() : Table
- Set a Table instance.
- setConfig() : $this
- Stores a list of options to be used when instantiating an object with a matching alias.
- setFallbackClassName() : $this
- Set fallback class name.
- _create() : Table
- Wrapper for creating table instances
- _getClassName() : string|null
- Gets the table class name.
- createInstance() : RepositoryInterface
- Create an instance of a given classname.
Properties
$_config
Configuration for aliases.
protected
array<string, array<string|int, mixed>|null>
$_config
= []
$_fallbacked
Contains a list of Table objects that were created out of the built-in Table class. The list is indexed by table alias
protected
array<string|int, Table>
$_fallbacked
= []
$allowFallbackClass
Whether fallback class should be used if a table class could not be found.
protected
bool
$allowFallbackClass
= true
$fallbackClassName
Fallback class to use
protected
string
$fallbackClassName
= \Cake\ORM\Table::class
Tags
$instances
Instances that belong to the registry.
protected
array<string, Table>
$instances
= []
$locations
Contains a list of locations where table classes should be looked for.
protected
array<string|int, string>
$locations
= []
$options
Contains a list of options that were passed to get() method.
protected
array<string, array<string|int, mixed>>
$options
= []
Methods
__construct()
Constructor.
public
__construct([array<string|int, string>|null $locations = null ]) : mixed
Parameters
- $locations : array<string|int, string>|null = null
-
Locations where tables should be looked for. If none provided, the default
Model\Table
under your app's namespace is used.
addLocation()
Adds a location where tables should be looked for.
public
addLocation(string $location) : $this
Parameters
- $location : string
-
Location to add.
Tags
Return values
$thisallowFallbackClass()
Set if fallback class should be used.
public
allowFallbackClass(bool $allow) : $this
Controls whether a fallback class should be used to create a table
instance if a concrete class for alias used in get()
could not be found.
Parameters
- $allow : bool
-
Flag to enable or disable fallback
Return values
$thisclear()
Clears the registry of configuration and instances.
public
clear() : void
Tags
exists()
Check to see if an instance exists in the registry.
public
exists(string $alias) : bool
Parameters
- $alias : string
-
The alias to check for.
Tags
Return values
boolgenericInstances()
Returns the list of tables that were created by this registry that could not be instantiated from a specific subclass. This method is useful for debugging common mistakes when setting up associations or created new table classes.
public
genericInstances() : array<string|int, Table>
Return values
array<string|int, Table>get()
Get a table instance from the registry.
public
get(string $alias[, array<string, mixed> $options = [] ]) : Table
Tables are only created once until the registry is flushed. This means that aliases must be unique across your application. This is important because table associations are resolved at runtime and cyclic references need to be handled correctly.
The options that can be passed are the same as in , but the
className
key is also recognized.
Options
-
className
Define the specific class name to use. If undefined, CakePHP will generate the class name based on the alias. For example 'Users' would result inApp\Model\Table\UsersTable
being used. If this class does not exist, then the defaultCake\ORM\Table
class will be used. By setting theclassName
option you can define the specific class to use. The className option supports plugin short class references . -
table
Define the table name to use. If undefined, this option will default to the underscored version of the alias name. -
connection
Inject the specific connection object to use. If this option andconnectionName
are undefined, The table class'defaultConnectionName()
method will be invoked to fetch the connection name. -
connectionName
Define the connection name to use. The named connection will be fetched from .
Note If your $alias
uses plugin syntax only the name part will be used as
key in the registry. This means that if two plugins, or a plugin and app provide
the same alias, the registry will only store the first instance.
Parameters
- $alias : string
-
The alias name you want to get. Should be in CamelCase format.
- $options : array<string, mixed> = []
-
The options you want to build the table with. If a table has already been loaded the options will be ignored.
Tags
Return values
TablegetConfig()
Returns configuration for an alias or the full configuration array for all aliases.
public
getConfig([string|null $alias = null ]) : array<string|int, mixed>
Parameters
- $alias : string|null = null
-
Alias to get config for, null for complete config.
Tags
Return values
array<string|int, mixed> —The config data.
remove()
Removes an repository instance from the registry.
public
remove(string $alias) : void
Parameters
- $alias : string
-
The alias to remove.
Tags
set()
Set a Table instance.
public
set(string $alias, Table $repository) : Table
Parameters
- $alias : string
-
The alias to set.
- $repository : Table
-
The Table to set.
Tags
Return values
TablesetConfig()
Stores a list of options to be used when instantiating an object with a matching alias.
public
setConfig(mixed $alias[, mixed $options = null ]) : $this
Parameters
- $alias : mixed
-
Name of the alias or array to completely overwrite current config.
- $options : mixed = null
-
list of options for the alias
Tags
Return values
$thissetFallbackClassName()
Set fallback class name.
public
setFallbackClassName(string $className) : $this
The class that should be used to create a table instance if a concrete
class for alias used in get()
could not be found. Defaults to
Cake\ORM\Table
.
Parameters
- $className : string
-
Fallback class name
Tags
Return values
$this_create()
Wrapper for creating table instances
protected
_create(array<string, mixed> $options) : Table
Parameters
- $options : array<string, mixed>
-
The alias to check for.
Return values
Table_getClassName()
Gets the table class name.
protected
_getClassName(string $alias[, array<string, mixed> $options = [] ]) : string|null
Parameters
- $alias : string
-
The alias name you want to get. Should be in CamelCase format.
- $options : array<string, mixed> = []
-
Table options array.
Return values
string|nullcreateInstance()
Create an instance of a given classname.
protected
createInstance(string $alias, array<string|int, mixed> $options) : RepositoryInterface
Parameters
- $alias : string
-
Repository alias.
- $options : array<string|int, mixed>
-
The options you want to build the instance with.