Class TableLocator
Provides a default registry/factory for Table objects.
Property Summary
- 
        $_config protectedarrayConfiguration for aliases. 
- 
        $_fallbacked protectedCake\ORM\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 protectedboolWhether fallback class should be used if a table class could not be found. 
- 
        $fallbackClassName protectedstringFallback class to use 
- 
        $instances protectedarray<string, \Cake\ORM\Table>Instances that belong to the registry. 
- 
        $locations protectedarrayContains a list of locations where table classes should be looked for. 
- 
        $options protectedarrayContains a list of options that were passed to get() method. 
Method Summary
- 
          __construct() publicConstructor. 
- 
          _create() protectedWrapper for creating table instances 
- 
          _getClassName() protectedGets the table class name. 
- 
          addLocation() publicAdds a location where tables should be looked for. 
- 
          allowFallbackClass() publicSet if fallback class should be used. 
- 
          clear() publicClears the registry of configuration and instances. 
- 
          createInstance() protectedCreate an instance of a given classname. 
- 
          exists() publicCheck to see if an instance exists in the registry. 
- 
          genericInstances() publicReturns 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() publicGet a table instance from the registry. 
- 
          getConfig() publicReturns configuration for an alias or the full configuration array for all aliases. 
- 
          remove() publicRemoves an repository instance from the registry. 
- 
          set() publicSet a Table instance. 
- 
          setConfig() publicStores a list of options to be used when instantiating an object with a matching alias. 
- 
          setFallbackClassName() publicSet fallback class name. 
Method Detail
__construct() ¶ public
__construct(array|null $locations = null)Constructor.
Parameters
- 
                array|null$locations optional
- Locations where tables should be looked for. If none provided, the default - Model\Tableunder your app's namespace is used.
_create() ¶ protected
_create(array $options): Cake\ORM\TableWrapper for creating table instances
Parameters
- 
                array$options
- The alias to check for. 
Returns
Cake\ORM\Table_getClassName() ¶ protected
_getClassName(string $alias, array $options = []): string|nullGets the table class name.
Parameters
- 
                string$alias
- The alias name you want to get. Should be in CamelCase format. 
- 
                array$options optional
- Table options array. 
Returns
string|nulladdLocation() ¶ public
addLocation(string $location): $thisAdds a location where tables should be looked for.
Parameters
- 
                string$location
- Location to add. 
Returns
$thisallowFallbackClass() ¶ public
allowFallbackClass(bool $allow): $thisSet if fallback class should be used.
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
- 
                bool$allow
- Flag to enable or disable fallback 
Returns
$thiscreateInstance() ¶ protected
createInstance(string $alias, array $options): Cake\Datasource\RepositoryInterfaceCreate an instance of a given classname.
Parameters
- 
                string$alias
- 
                array$options
Returns
Cake\Datasource\RepositoryInterfaceexists() ¶ public
exists(string $alias): boolCheck to see if an instance exists in the registry.
Parameters
- 
                string$alias
Returns
boolgenericInstances() ¶ public
genericInstances(): Cake\ORM\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.
Returns
Cake\ORM\Table[]get() ¶ public
get(string $alias, array $options = []): Cake\ORM\TableGet a table instance from the registry.
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 Cake\ORM\Table::__construct(), but the
className key is also recognized.
Options
- classNameDefine the specific class name to use. If undefined, CakePHP will generate the class name based on the alias. For example 'Users' would result in- App\Model\Table\UsersTablebeing used. If this class does not exist, then the default- Cake\ORM\Tableclass will be used. By setting the- classNameoption you can define the specific class to use. The className option supports plugin short class references {@link \Cake\Core\App::shortName()}.
- tableDefine the table name to use. If undefined, this option will default to the underscored version of the alias name.
- connectionInject the specific connection object to use. If this option and- connectionNameare undefined, The table class'- defaultConnectionName()method will be invoked to fetch the connection name.
- connectionNameDefine the connection name to use. The named connection will be fetched from {@link \Cake\Datasource\ConnectionManager}.
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
- 
                string$alias
- The alias name you want to get. Should be in CamelCase format. 
- 
                array$options optional
- The options you want to build the table with. If a table has already been loaded the options will be ignored. 
Returns
Cake\ORM\TableThrows
RuntimeExceptionWhen you try to configure an alias that already exists.
getConfig() ¶ public
getConfig(string|null $alias = null): arrayReturns configuration for an alias or the full configuration array for all aliases.
Parameters
- 
                string|null$alias optional
Returns
arrayremove() ¶ public
remove(string $alias): voidRemoves an repository instance from the registry.
Parameters
- 
                string$alias
Returns
voidset() ¶ public
set(string $alias, Cake\Datasource\RepositoryInterface $repository): Cake\ORM\TableSet a Table instance.
Parameters
- 
                string$alias
- The alias to set. 
- 
                Cake\Datasource\RepositoryInterface$repository
- The Table to set. 
Returns
Cake\ORM\TablesetConfig() ¶ public
setConfig(string|array $alias, array|null $options = null): $thisStores a list of options to be used when instantiating an object with a matching alias.
Parameters
- 
                string|array$alias
- 
                array|null$options optional
Returns
$thissetFallbackClassName() ¶ public
setFallbackClassName(string $className): $thisSet fallback class name.
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
- 
                string$className
- Fallback class name 
Returns
$thisProperty Detail
$_fallbacked ¶ protected
Contains a list of Table objects that were created out of the built-in Table class. The list is indexed by table alias
Type
Cake\ORM\Table[]$allowFallbackClass ¶ protected
Whether fallback class should be used if a table class could not be found.
Type
bool$locations ¶ protected
Contains a list of locations where table classes should be looked for.
Type
array