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)
Property Summary
-
$activeIds protected
array<int>|nullActive 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)
filter() ¶ public
filter(Closure $callback): static
Filter with a callback. Triggers full hydration.
Parameters
-
Closure$callback Closure to filter elements
Returns
staticfirst() ¶ public
first(): Cake\AttributeResolver\ValueObject\AttributeInfo|null
Get first item or null if empty.
Returns
Cake\AttributeResolver\ValueObject\AttributeInfo|nullgetActiveIds() ¶ 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>>>}hydrate() ¶ protected
hydrate(int $id): Cake\AttributeResolver\ValueObject\AttributeInfo
Hydrate a single item by ID.
Parameters
-
int$id Item ID
Returns
Cake\AttributeResolver\ValueObject\AttributeInfoindexItem() ¶ 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
voidintersectWithActive() ¶ protected
intersectWithActive(array<int> $matchingIds): static
Intersect matching IDs with currently active IDs.
Parameters
-
array<int>$matchingIds Matching item IDs from index
Returns
statictoArray() ¶ 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
stringRegular 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
staticwithAttribute() ¶ 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
staticwithAttributeContains() ¶ public
withAttributeContains(string $search): static
Filter by partial attribute name match (case-sensitive).
Parameters
-
string$search String to search for in attribute names
Returns
staticwithClassName() ¶ 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
staticwithClassNameContains() ¶ public
withClassNameContains(string $search): static
Filter by partial class name match (case-sensitive).
Parameters
-
string$search String to search for in class names
Returns
staticwithNamespace() ¶ 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
staticwithPlugin() ¶ 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
staticwithTargetType() ¶ 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