CakePHP
  • Documentation
    • Book
    • API
    • Videos
    • Reporting Security Issues
    • Privacy Policy
    • Logos & Trademarks
  • Business Solutions
  • Swag
  • Road Trip
  • Team
  • Community
    • Community
    • Get Involved
    • Issues (Github)
    • Bakery
    • Featured Resources
    • Training
    • Meetups
    • My CakePHP
    • CakeFest
    • Newsletter
    • Linkedin
    • YouTube
    • Facebook
    • Twitter
    • Mastodon
    • Help & Support
    • Forum
    • Stack Overflow
    • IRC
    • Slack
    • Paid Support
CakePHP

C CakePHP 6.0 API

  • Project:
    • CakePHP
      • CakePHP
      • Authentication
      • Authorization
      • Chronos
      • Elastic Search
      • Queue
  • Version:
    • 6.0
      • 6.0
      • 5.4
      • 5.3
      • 5.2
      • 5.1
      • 5.0
      • 4.6
      • 4.5
      • 4.4
      • 4.3
      • 4.2
      • 4.1
      • 4.0
      • 3.10
      • 3.9
      • 3.8
      • 3.7
      • 3.6
      • 3.5
      • 3.4
      • 3.3
      • 3.2
      • 3.1
      • 3.0
      • 2.10
      • 2.9
      • 2.8
      • 2.7
      • 2.6
      • 2.5
      • 2.4
      • 2.3
      • 2.2
      • 2.1
      • 2.0
      • 1.3
      • 1.2

Namespaces

  • Global
  • Cake
    • AttributeResolver
      • ValueObject
    • Cache
    • Collection
    • Command
    • Console
    • Container
    • Controller
    • Core
    • Database
    • Datasource
    • Error
    • Event
    • Form
    • Http
    • I18n
    • Lock
    • Log
    • Mailer
    • Network
    • ORM
    • Routing
    • TestSuite
    • Utility
    • Validation
    • View

Class AttributeResolver

Attribute Resolver

Main entry point for attribute resolution. Scans source files for PHP attributes and provides a fluent collection interface for filtering and querying discovered attributes.

Namespace: Cake\AttributeResolver

Property Summary

  • $collections protected static
    array<string, \Cake\AttributeResolver\AttributeCollection>

    In-memory cache of resolved collections per config name

  • $config protected static
    array<string|int, array<string, mixed>>

    Configuration sets.

  • $dsnClassMap protected static
    array<string, class-string>|null

    Map of short class name to fully qualified class name for DSN parsing.

Method Summary

  • __callStatic() public static

    Forward method calls to the default collection

    Enables convenient access to collection methods on the default config: $routes = AttributeResolver::withAttribute(Route::class);

  • clear() public static

    Clear cached attributes for a configuration

  • collection() public static

    Get attribute collection for configured paths

  • configured() public static

    Returns an array containing the named configurations

  • drop() public static

    Drop a configuration and clear its in-memory cache

  • getCache() protected static

    Get cache instance for a configuration

  • getConfig() public static

    Reads existing configuration.

  • getConfigOrFail() public static

    Reads existing configuration for a specific key.

    The config value for this key must exist, it can never be null.

  • getDsnClassMap() public static

    Returns the DSN class map for this class.

  • initDsnClassMap() protected static

    Returns the default DSN class map.

    Override this method in implementing classes to provide a class-specific map.

  • parseDsn() public static

    Parses a DSN into a valid connection configuration

    This method allows setting a DSN using formatting similar to that used by PEAR::DB. The following is an example of its usage:

    $dsn = 'mysql://user:pass@localhost/database?';
    $config = ConnectionManager::parseDsn($dsn);
    
    $dsn = 'Cake\Log\Engine\FileLog://?types=notice,info,debug&file=debug&path=LOGS';
    $config = Log::parseDsn($dsn);
    
    $dsn = 'smtp://user:secret@localhost:25?timeout=30&client=null&tls=null';
    $config = Email::parseDsn($dsn);
    
    $dsn = 'file:///?className=\My\Cache\Engine\FileEngine';
    $config = Cache::parseDsn($dsn);
    
    $dsn = 'File://?prefix=myapp_cake_translations_&serialize=true&duration=+2 minutes&path=/tmp/persistent/';
    $config = Cache::parseDsn($dsn);

    For all classes, the value of scheme is set as the value of both the className unless they have been otherwise specified.

    Note that querystring arguments are also parsed and set as values in the returned configuration.

  • setConfig() public static

    This method can be used to define configuration adapters for an application.

    To change an adapter's configuration at runtime, first drop the adapter and then reconfigure it.

    Adapters will not be constructed until the first operation is done.

    Usage

    Assuming that the class' name is Cache the following scenarios are supported:

    Setting a cache engine up.

    Cache::setConfig('default', $settings);

    Injecting a constructed adapter in:

    Cache::setConfig('default', $instance);

    Configure multiple adapters at once:

    Cache::setConfig($arrayOfConfig);
  • setDsnClassMap() public static

    Updates the DSN class map for this class.

  • warm() public static

    Build cache for a configuration

Method Detail

__callStatic() ¶ public static

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

Forward method calls to the default collection

Enables convenient access to collection methods on the default config: $routes = AttributeResolver::withAttribute(Route::class);

Parameters
string $method

Method name

array $arguments

Method arguments

Returns
mixed

clear() ¶ public static

clear(string $name = 'default'): bool

Clear cached attributes for a configuration

Parameters
string $name optional

Configuration name

Returns
bool

Success status

collection() ¶ public static

collection(string $name = 'default'): Cake\AttributeResolver\AttributeCollection

Get attribute collection for configured paths

Parameters
string $name optional

Configuration name

Returns
Cake\AttributeResolver\AttributeCollection
Throws
InvalidArgumentException
When configuration does not exist

configured() ¶ public static

configured(): array<string>

Returns an array containing the named configurations

Returns
array<string>

Array of configurations.

drop() ¶ public static

drop(string $config): bool

Drop a configuration and clear its in-memory cache

Parameters
string $config

Configuration name to remove

Returns
bool

Success

getCache() ¶ protected static

getCache(array|null $config): Cake\AttributeResolver\AttributeCache|null

Get cache instance for a configuration

Parameters
array|null $config

Configuration array

Returns
Cake\AttributeResolver\AttributeCache|null

Returns null when cache is disabled

getConfig() ¶ public static

getConfig(string $key): mixed|null

Reads existing configuration.

Parameters
string $key

The name of the configuration.

Returns
mixed|null

Configuration data at the named key or null if the key does not exist.

getConfigOrFail() ¶ public static

getConfigOrFail(string $key): mixed

Reads existing configuration for a specific key.

The config value for this key must exist, it can never be null.

Parameters
string $key

The name of the configuration.

Returns
mixed

Configuration data at the named key.

Throws
InvalidArgumentException
If value does not exist.

getDsnClassMap() ¶ public static

getDsnClassMap(): array<string, class-string>

Returns the DSN class map for this class.

Returns
array<string, class-string>

initDsnClassMap() ¶ protected static

initDsnClassMap(): array<string, class-string>

Returns the default DSN class map.

Override this method in implementing classes to provide a class-specific map.

Returns
array<string, class-string>

parseDsn() ¶ public static

parseDsn(string $dsn): array<int|string, array|bool|string|null>

Parses a DSN into a valid connection configuration

This method allows setting a DSN using formatting similar to that used by PEAR::DB. The following is an example of its usage:

$dsn = 'mysql://user:pass@localhost/database?';
$config = ConnectionManager::parseDsn($dsn);

$dsn = 'Cake\Log\Engine\FileLog://?types=notice,info,debug&file=debug&path=LOGS';
$config = Log::parseDsn($dsn);

$dsn = 'smtp://user:secret@localhost:25?timeout=30&client=null&tls=null';
$config = Email::parseDsn($dsn);

$dsn = 'file:///?className=\My\Cache\Engine\FileEngine';
$config = Cache::parseDsn($dsn);

$dsn = 'File://?prefix=myapp_cake_translations_&serialize=true&duration=+2 minutes&path=/tmp/persistent/';
$config = Cache::parseDsn($dsn);

For all classes, the value of scheme is set as the value of both the className unless they have been otherwise specified.

Note that querystring arguments are also parsed and set as values in the returned configuration.

Parameters
string $dsn

The DSN string to convert to a configuration array

Returns
array<int|string, array|bool|string|null>

The configuration array to be stored after parsing the DSN

Throws
InvalidArgumentException
If not passed a string, or passed an invalid string

setConfig() ¶ public static

setConfig(array<string, mixed>|string $key, mixed $config = null): void

This method can be used to define configuration adapters for an application.

To change an adapter's configuration at runtime, first drop the adapter and then reconfigure it.

Adapters will not be constructed until the first operation is done.

Usage

Assuming that the class' name is Cache the following scenarios are supported:

Setting a cache engine up.

Cache::setConfig('default', $settings);

Injecting a constructed adapter in:

Cache::setConfig('default', $instance);

Configure multiple adapters at once:

Cache::setConfig($arrayOfConfig);
Parameters
array<string, mixed>|string $key

The name of the configuration, or an array of multiple configs.

mixed $config optional

Configuration value. Generally an array of name => configuration data for adapter.

Returns
void
Throws
BadMethodCallException
When trying to modify an existing config.
LogicException
When trying to store an invalid structured config array.

setDsnClassMap() ¶ public static

setDsnClassMap(array<string, class-string> $map): void

Updates the DSN class map for this class.

Parameters
array<string, class-string> $map

Additions/edits to the class map to apply.

Returns
void

warm() ¶ public static

warm(string $name = 'default'): Cake\AttributeResolver\AttributeCollection

Build cache for a configuration

Parameters
string $name optional

Configuration name

Returns
Cake\AttributeResolver\AttributeCollection

The warmed collection

Property Detail

$collections ¶ protected static

In-memory cache of resolved collections per config name

Type
array<string, \Cake\AttributeResolver\AttributeCollection>

$config ¶ protected static

Configuration sets.

Type
array<string|int, array<string, mixed>>

$dsnClassMap ¶ protected static

Map of short class name to fully qualified class name for DSN parsing.

Type
array<string, class-string>|null
OpenHub
Pingping
Linode
  • Business Solutions
  • Showcase
  • Documentation
  • Book
  • API
  • Videos
  • Reporting Security Issues
  • Privacy Policy
  • Logos & Trademarks
  • Community
  • Get Involved
  • Issues (Github)
  • Bakery
  • Featured Resources
  • Training
  • Meetups
  • My CakePHP
  • CakeFest
  • Newsletter
  • Linkedin
  • YouTube
  • Facebook
  • Twitter
  • Mastodon
  • Help & Support
  • Forum
  • Stack Overflow
  • IRC
  • Slack
  • Paid Support

Generated using CakePHP API Docs