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 AttributeCollection

Collection class for working with AttributeInfo objects.

Provides fluent filtering methods specific to attribute metadata. Supports lazy hydration from raw array data for optimal cache performance.

Data can be provided as:

  • Array of AttributeInfo objects (converted to arrays internally)
  • Raw array data with optional pre-built indexes (from cache)
Namespace: Cake\AttributeResolver

Property Summary

  • $activeIds protected
    array<int>|null

    Active item IDs after filtering (null = all items)

  • $data protected
    array<int, array<string, mixed>>

    Raw array data for all items

  • $hydrated protected
    array<int, \Cake\AttributeResolver\ValueObject\AttributeInfo>

    Cache of hydrated AttributeInfo objects

  • $indexes protected
    array<string, array<string, array<int>>>

    Pre-built indexes for fast filtering

Method Summary

  • __construct() public

    Constructor.

  • count() public
  • filter() public

    Filter with a callback. Triggers full hydration.

  • first() public

    Get first item or null if empty.

  • getActiveIds() protected

    Get the active item IDs (filtered or all).

  • getCacheData() public

    Get cache-optimized data for storage.

    Returns raw arrays and indexes suitable for cache storage. This format can be loaded directly without object construction overhead.

  • getIterator() public
  • hydrate() protected

    Hydrate a single item by ID.

  • indexItem() protected

    Add item to indexes.

  • intersectWithActive() protected

    Intersect matching IDs with currently active IDs.

  • toArray() public

    Convert collection to array of AttributeInfo objects.

  • toList() public

    Convert collection to list of AttributeInfo objects.

  • wildcardToRegex() protected

    Convert wildcard pattern to regex.

  • withActiveIds() protected

    Create a filtered clone with specific active IDs.

  • withAttribute() public

    Filter by attribute name(s). Uses index for fast lookup.

  • withAttributeContains() public

    Filter by partial attribute name match (case-sensitive).

  • withClassName() public

    Filter by class name(s). Uses index for fast lookup.

  • withClassNameContains() public

    Filter by partial class name match (case-sensitive).

  • withNamespace() public

    Filter by namespace pattern with wildcard support.

    Examples:

    • 'App\Controller\*' - matches App\Controller\UsersController
    • '\Controller\' - matches any namespace containing Controller
    • 'App\Model\Entity\User' - exact match
  • withPlugin() public

    Filter by plugin name.

  • withTargetType() public

    Filter by target type(s). Uses index for fast lookup.

Method Detail

__construct() ¶ public

__construct(iterable<Cake\AttributeResolver\ValueObject\AttributeInfo|array> $items, array<string, array<string, array<int>>>|null $indexes = null)

Constructor.

Parameters
iterable<Cake\AttributeResolver\ValueObject\AttributeInfo|array> $items

Items to populate the collection

array<string, array<string, array<int>>>|null $indexes optional

Pre-built indexes (from cache)

count() ¶ public

count(): int
Returns
int

filter() ¶ public

filter(Closure $callback): static

Filter with a callback. Triggers full hydration.

Parameters
Closure $callback

Closure to filter elements

Returns
static

first() ¶ public

first(): Cake\AttributeResolver\ValueObject\AttributeInfo|null

Get first item or null if empty.

Returns
Cake\AttributeResolver\ValueObject\AttributeInfo|null

getActiveIds() ¶ protected

getActiveIds(): array<int>

Get the active item IDs (filtered or all).

Returns
array<int>

getCacheData() ¶ public

getCacheData(): array{data: array<int, array<string, mixed>>, indexes: array<string, array<string, array<int>>>}

Get cache-optimized data for storage.

Returns raw arrays and indexes suitable for cache storage. This format can be loaded directly without object construction overhead.

Returns
array{data: array<int, array<string, mixed>>, indexes: array<string, array<string, array<int>>>}

getIterator() ¶ public

getIterator(): Traversable
Returns
Traversable

hydrate() ¶ protected

hydrate(int $id): Cake\AttributeResolver\ValueObject\AttributeInfo

Hydrate a single item by ID.

Parameters
int $id

Item ID

Returns
Cake\AttributeResolver\ValueObject\AttributeInfo

indexItem() ¶ protected

indexItem(int $id, array<string, mixed> $item): void

Add item to indexes.

Parameters
int $id

Item ID

array<string, mixed> $item

Item data

Returns
void

intersectWithActive() ¶ protected

intersectWithActive(array<int> $matchingIds): static

Intersect matching IDs with currently active IDs.

Parameters
array<int> $matchingIds

Matching item IDs from index

Returns
static

toArray() ¶ public

toArray(): array<int, \Cake\AttributeResolver\ValueObject\AttributeInfo>

Convert collection to array of AttributeInfo objects.

Returns
array<int, \Cake\AttributeResolver\ValueObject\AttributeInfo>

toList() ¶ public

toList(): array<int, \Cake\AttributeResolver\ValueObject\AttributeInfo>

Convert collection to list of AttributeInfo objects.

Returns
array<int, \Cake\AttributeResolver\ValueObject\AttributeInfo>

wildcardToRegex() ¶ protected

wildcardToRegex(string $pattern): string

Convert wildcard pattern to regex.

Parameters
string $pattern

Pattern with * wildcards

Returns
string

Regular expression pattern

withActiveIds() ¶ protected

withActiveIds(array<int> $ids): static

Create a filtered clone with specific active IDs.

Parameters
array<int> $ids

Active item IDs

Returns
static

withAttribute() ¶ public

withAttribute(array<string>|string $names): static

Filter by attribute name(s). Uses index for fast lookup.

Parameters
array<string>|string $names

Attribute class name(s) to filter by

Returns
static

withAttributeContains() ¶ public

withAttributeContains(string $search): static

Filter by partial attribute name match (case-sensitive).

Parameters
string $search

String to search for in attribute names

Returns
static

withClassName() ¶ public

withClassName(array<string>|string $names): static

Filter by class name(s). Uses index for fast lookup.

Parameters
array<string>|string $names

Class name(s) to filter by

Returns
static

withClassNameContains() ¶ public

withClassNameContains(string $search): static

Filter by partial class name match (case-sensitive).

Parameters
string $search

String to search for in class names

Returns
static

withNamespace() ¶ public

withNamespace(string $pattern): static

Filter by namespace pattern with wildcard support.

Examples:

  • 'App\Controller\*' - matches App\Controller\UsersController
  • '\Controller\' - matches any namespace containing Controller
  • 'App\Model\Entity\User' - exact match
Parameters
string $pattern

Namespace pattern with optional wildcards (*)

Returns
static

withPlugin() ¶ public

withPlugin(string|null $pluginName): static

Filter by plugin name.

Parameters
string|null $pluginName

Plugin name to filter by, or null for app-level attributes

Returns
static

withTargetType() ¶ public

withTargetType(Cake\AttributeResolver\Enum\AttributeTargetType|array<Cake\AttributeResolver\Enum\AttributeTargetType> $types): static

Filter by target type(s). Uses index for fast lookup.

Parameters
Cake\AttributeResolver\Enum\AttributeTargetType|array<Cake\AttributeResolver\Enum\AttributeTargetType> $types

Target type(s) to filter by

Returns
static

Property Detail

$activeIds ¶ protected

Active item IDs after filtering (null = all items)

Type
array<int>|null

$data ¶ protected

Raw array data for all items

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

$hydrated ¶ protected

Cache of hydrated AttributeInfo objects

Type
array<int, \Cake\AttributeResolver\ValueObject\AttributeInfo>

$indexes ¶ protected

Pre-built indexes for fast filtering

Type
array<string, array<string, array<int>>>
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