class Collection
Same name in this branch
- 11.1.x vendor/symfony/validator/Constraints/Collection.php \Symfony\Component\Validator\Constraints\Collection
- 11.1.x vendor/phpdocumentor/type-resolver/src/Types/Collection.php \phpDocumentor\Reflection\Types\Collection
A collection represents a group of objects.
Each object in the collection is of a specific, defined type.
This is a direct implementation of `CollectionInterface`, provided for the sake of convenience.
Example usage:
``` php $collection = new \Ramsey\Collection\Collection('My\\Foo'); $collection->add(new \My\Foo()); $collection->add(new \My\Foo());
foreach ($collection as $foo) { // Do something with $foo } ```
It is preferable to subclass `AbstractCollection` to create your own typed collections. For example:
``` php namespace My\Foo;
class FooCollection extends \Ramsey\Collection\AbstractCollection { public function getType() { return 'My\\Foo'; } } ```
And then use it similarly to the earlier example:
``` php $fooCollection = new \My\Foo\FooCollection(); $fooCollection->add(new \My\Foo()); $fooCollection->add(new \My\Foo());
foreach ($fooCollection as $foo) { // Do something with $foo } ```
The benefit with this approach is that you may do type-checking on the collection object:
``` php if ($collection instanceof \My\Foo\FooCollection) { // the collection is a collection of My\Foo objects } ```
@template T @extends AbstractCollection<T>
Hierarchy
- class \Ramsey\Collection\AbstractArray implements \Ramsey\Collection\ArrayInterface
- class \Ramsey\Collection\AbstractCollection extends \Ramsey\Collection\AbstractArray implements \Ramsey\Collection\CollectionInterface uses \Ramsey\Collection\Tool\TypeTrait, \Ramsey\Collection\Tool\ValueToStringTrait, \Ramsey\Collection\Tool\ValueExtractorTrait
- class \Ramsey\Collection\Collection extends \Ramsey\Collection\AbstractCollection
- class \Ramsey\Collection\AbstractCollection extends \Ramsey\Collection\AbstractArray implements \Ramsey\Collection\CollectionInterface uses \Ramsey\Collection\Tool\TypeTrait, \Ramsey\Collection\Tool\ValueToStringTrait, \Ramsey\Collection\Tool\ValueExtractorTrait
Expanded class hierarchy of Collection
46 string references to 'Collection'
- BlockContentForm::save in core/
modules/ block_content/ src/ BlockContentForm.php - Form submission handler for the 'save' action.
- BlockContentTypeForm::save in core/
modules/ block_content/ src/ BlockContentTypeForm.php - Form submission handler for the 'save' action.
- CommentTypeForm::save in core/
modules/ comment/ src/ CommentTypeForm.php - Form submission handler for the 'save' action.
- Config::query in core/
modules/ migrate_drupal/ src/ Plugin/ migrate/ source/ d8/ Config.php - Constraint::checkArray in vendor/
justinrainbow/ json-schema/ src/ JsonSchema/ Constraints/ Constraint.php - Validates an array
File
-
vendor/
ramsey/ collection/ src/ Collection.php, line 76
Namespace
Ramsey\CollectionView source
class Collection extends AbstractCollection {
/**
* Constructs a collection object of the specified type, optionally with the
* specified data.
*
* @param string $collectionType The type or class name associated with this
* collection.
* @param array<array-key, T> $data The initial items to store in the collection.
*/
public function __construct(string $collectionType, array $data = []) {
parent::__construct($data);
}
public function getType() : string {
return $this->collectionType;
}
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title | Overrides |
---|---|---|---|---|---|
AbstractArray::$data | protected | property | The items of this array. | ||
AbstractArray::clear | public | function | Removes all items from this array. | Overrides ArrayInterface::clear | |
AbstractArray::count | public | function | Returns the number of items in this array. | ||
AbstractArray::getIterator | public | function | Returns an iterator for this array. | 2 | |
AbstractArray::isEmpty | public | function | Returns `true` if this array is empty. | Overrides ArrayInterface::isEmpty | |
AbstractArray::offsetExists | public | function | Returns `true` if the given offset exists in this array. | ||
AbstractArray::offsetGet | public | function | Returns the value at the specified offset. | ||
AbstractArray::offsetUnset | public | function | Removes the given offset and its value from the array. | ||
AbstractArray::toArray | public | function | @inheritDoc | Overrides ArrayInterface::toArray | 1 |
AbstractArray::__serialize | public | function | Returns data suitable for PHP serialization. | 1 | |
AbstractArray::__unserialize | public | function | Adds unserialized data to the object. | ||
AbstractCollection::add | public | function | Overrides CollectionInterface::add | 1 | |
AbstractCollection::column | public | function | @inheritDoc | Overrides CollectionInterface::column | |
AbstractCollection::compareCollectionTypes | private | function | |||
AbstractCollection::contains | public | function | Returns `true` if this collection contains the specified element. | Overrides CollectionInterface::contains | |
AbstractCollection::diff | public | function | Overrides CollectionInterface::diff | ||
AbstractCollection::filter | public | function | Overrides CollectionInterface::filter | ||
AbstractCollection::first | public | function | Overrides CollectionInterface::first | ||
AbstractCollection::getComparator | private | function | |||
AbstractCollection::getUniformType | private | function | |||
AbstractCollection::intersect | public | function | Overrides CollectionInterface::intersect | ||
AbstractCollection::last | public | function | Overrides CollectionInterface::last | ||
AbstractCollection::map | public | function | @template TCallbackReturn | Overrides CollectionInterface::map | |
AbstractCollection::merge | public | function | Overrides CollectionInterface::merge | ||
AbstractCollection::offsetSet | public | function | Overrides AbstractArray::offsetSet | 1 | |
AbstractCollection::reduce | public | function | @template TCarry | Overrides CollectionInterface::reduce | |
AbstractCollection::remove | public | function | Removes a single instance of the specified element from this collection, if it is present. |
Overrides CollectionInterface::remove | |
AbstractCollection::sort | public | function | Overrides CollectionInterface::sort | ||
AbstractCollection::where | public | function | Overrides CollectionInterface::where | ||
Collection::getType | public | function | Returns the type associated with this collection. | Overrides CollectionInterface::getType | |
Collection::__construct | public | function | Constructs a collection object of the specified type, optionally with the specified data. |
Overrides AbstractArray::__construct | |
TypeTrait::checkType | protected | function | Returns `true` if value is of the specified type. | ||
ValueExtractorTrait::extractValue | protected | function | Extracts the value of the given property, method, or array key from the element. |
||
ValueToStringTrait::toolValueToString | protected | function | Returns a string representation of the value. |