PluginProbe
Media Cloud Sync / 1.4.1
Media Cloud Sync v1.4.1
1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 All 35 releases
media-cloud-sync / includes / sdk / google / ramsey / collection / src / Collection.php

Collection.php in Media Cloud Sync 1.4.1, at includes/sdk/google/ramsey/collection/src/Collection.php

93 lines 2.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * This file is part of the ramsey/collection library
5 *
6 * For the full copyright and license information, please view the LICENSE
7 * file that was distributed with this source code.
8 *
9 * @copyright Copyright (c) Ben Ramsey <ben@benramsey.com>
10 * @license http://opensource.org/licenses/MIT MIT
11 */
12 declare (strict_types=1);
13 namespace Dudlewebs\WPMCS\GCP\Ramsey\Collection;
14
15 /**
16 * A collection represents a group of objects.
17 *
18 * Each object in the collection is of a specific, defined type.
19 *
20 * This is a direct implementation of `CollectionInterface`, provided for
21 * the sake of convenience.
22 *
23 * Example usage:
24 *
25 * ```
26 * $collection = new \Ramsey\Collection\Collection('My\\Foo');
27 * $collection->add(new \My\Foo());
28 * $collection->add(new \My\Foo());
29 *
30 * foreach ($collection as $foo) {
31 * // Do something with $foo
32 * }
33 * ```
34 *
35 * It is preferable to subclass `AbstractCollection` to create your own typed
36 * collections. For example:
37 *
38 * ```
39 * namespace My\Foo;
40 *
41 * class FooCollection extends \Ramsey\Collection\AbstractCollection
42 * {
43 * public function getType()
44 * {
45 * return 'My\\Foo';
46 * }
47 * }
48 * ```
49 *
50 * And then use it similarly to the earlier example:
51 *
52 * ```
53 * $fooCollection = new \My\Foo\FooCollection();
54 * $fooCollection->add(new \My\Foo());
55 * $fooCollection->add(new \My\Foo());
56 *
57 * foreach ($fooCollection as $foo) {
58 * // Do something with $foo
59 * }
60 * ```
61 *
62 * The benefit with this approach is that you may do type-checking on the
63 * collection object:
64 *
65 * ```
66 * if ($collection instanceof \My\Foo\FooCollection) {
67 * // the collection is a collection of My\Foo objects
68 * }
69 * ```
70 *
71 * @template T
72 * @extends AbstractCollection<T>
73 */
74 class Collection extends AbstractCollection
75 {
76 /**
77 * Constructs a collection object of the specified type, optionally with the
78 * specified data.
79 *
80 * @param string $collectionType The type or class name associated with this
81 * collection.
82 * @param array<array-key, T> $data The initial items to store in the collection.
83 */
84 public function __construct(private readonly string $collectionType, array $data = [])
85 {
86 parent::__construct($data);
87 }
88 public function getType() : string
89 {
90 return $this->collectionType;
91 }
92 }
93