Decorator Classes and Traits
This chapter will describe all the available classes and traits in this package.
Ready-to-use Decorator Classes
The package ships with ready-to-use decorator classes for common use cases:
ExtraLazyCollection: Prevent collection loading in extra-lazy associations.LazyMatchingCollection: Chained matching optimization, if you need to callmatching()on the result of anothermatching().
Decorator Classes
All of our classes come in four flavors:
- Those that implement
Collection - Those that implement
ReadableCollection - Those that implement
CollectionandSelectable - Those that implement
ReadableCollectionandSelectable
Most people probably want to extend one of the high-level decorator classes. These will simply forward all method calls to the wrapped collection.
CollectionDecoratorReadableCollectionDecoratorSelectableCollectionDecoratorSelectableReadableCollectionDecorator
Also available the 'reject' decorator classes, which will throw an exception when any of the methods is called:
CollectionRejectDecoratorReadableCollectionRejectDecoratorSelectableCollectionRejectDecoratorSelectableReadableCollectionRejectDecorator
Abstract Decorator Classes
Also available are abstract classes for Collection and ReadableCollection,
with and without Selectable, if you prefer a slightly low-level approach:
AbstractCollectionDecoratorAbstractReadableCollectionDecoratorAbstractSelectableCollectionDecoratorAbstractSelectableReadableCollectionDecorator
And the 'reject' flavors:
AbstractCollectionRejectDecoratorAbstractReadableCollectionRejectDecoratorAbstractSelectableCollectionRejectDecoratorAbstractSelectableReadableCollectionRejectDecorator
Decorator Traits
There are traits for each of the involved interfaces:
ArrayAccessDecoratorTraitIteratorAggregateDecoratorTraitCountableDecoratorTraitReadableCollectionDecoratorTraitCollectionDecoratorTraitSelectableDecoratorTrait
And the 'reject' traits that will throw BadMethodCallException when any of the
methods is called.
ArrayAccessRejectDecoratorTraitIteratorAggregateRejectDecoratorTraitCountableRejectDecoratorTraitReadableCollectionRejectDecoratorTraitCollectionRejectDecoratorTraitSelectableRejectDecoratorTrait
All traits require the method getWrapped() which returns the wrapped
collection.
Convenience Trait
There is one convenience trait ArrayAccessDecoratorDxTrait which forwards
ArrayAccess methods not to the wrapped collection, but to other methods of the
decorator.
The idea is that you only need to override containsKey(), get(), set(),
and remove(); and the methods offsetExists(), offsetGet(), offsetSet(),
and offsetUnset() will forward calls to the aforementioned methods.