Acf
1 day ago
Admin
1 day ago
Ajax
1 day ago
ApplyFilter
1 day ago
Asset
1 day ago
Capabilities
1 day ago
Check
1 day ago
Collection
1 day ago
Column
1 day ago
ColumnFactories
1 day ago
ColumnFactory
1 day ago
ColumnIterator
1 day ago
ColumnRepository
1 day ago
ColumnSize
1 day ago
DI
1 day ago
DefaultColumnHandler
1 day ago
Deprecated
1 day ago
Entity
1 day ago
Exception
1 day ago
Expression
1 day ago
Form
1 day ago
Formatter
1 day ago
Helper
1 day ago
Integration
1 day ago
ListScreenRepository
1 day ago
ListTable
1 day ago
Message
1 day ago
Meta
1 day ago
Nonce
1 day ago
Notice
1 day ago
Plugin
1 day ago
Preferences
1 day ago
Promo
1 day ago
Request
1 day ago
RequestHandler
1 day ago
Response
1 day ago
Sanitize
1 day ago
Service
1 day ago
Setting
1 day ago
Settings
1 day ago
Storage
1 day ago
Table
1 day ago
TableIdsFactory
1 day ago
TableScreen
1 day ago
TableScreenFactory
1 day ago
ThirdParty
1 day ago
Type
1 day ago
Value
1 day ago
View
1 day ago
Acf.php
1 day ago
AdminColumns.php
1 day ago
ArrayIterator.php
1 day ago
Capabilities.php
1 day ago
Collection.php
1 day ago
CollectionFormatter.php
1 day ago
Column.php
1 day ago
ColumnCollection.php
1 day ago
ColumnFactoryCollectionFactory.php
1 day ago
ColumnFactoryDefinitionCollection.php
1 day ago
ColumnGroups.php
1 day ago
ColumnIterator.php
1 day ago
ColumnNamesTrait.php
1 day ago
ColumnRepository.php
1 day ago
ColumnTypeRepository.php
1 day ago
Config.php
1 day ago
DateFormats.php
1 day ago
DefaultColumnHandler.php
1 day ago
Expirable.php
1 day ago
Formatter.php
1 day ago
FormatterCollection.php
1 day ago
Helper.php
1 day ago
ListScreen.php
1 day ago
ListScreenCollection.php
1 day ago
ListScreenRepository.php
1 day ago
ListScreenRepositoryWritable.php
1 day ago
ListTable.php
1 day ago
ListTableFactory.php
1 day ago
Loader.php
1 day ago
Message.php
1 day ago
MetaType.php
1 day ago
Middleware.php
1 day ago
OpCacheInvalidateTrait.php
1 day ago
PluginActionLinks.php
1 day ago
PluginActionUpgrade.php
1 day ago
PostType.php
1 day ago
PostTypeRepository.php
1 day ago
Registerable.php
1 day ago
Registry.php
1 day ago
Renderable.php
1 day ago
Request.php
1 day ago
RequestAjaxHandler.php
1 day ago
RequestAjaxHandlers.php
1 day ago
RequestAjaxParser.php
1 day ago
RequestHandler.php
1 day ago
RequestHandlerFactory.php
1 day ago
Screen.php
1 day ago
Services.php
1 day ago
TableIdsFactory.php
1 day ago
TableScreen.php
1 day ago
TableScreenFactory.php
1 day ago
Taxonomy.php
1 day ago
Transient.php
1 day ago
TypedArrayIterator.php
1 day ago
View.php
1 day ago
WooCommerce.php
1 day ago
WpListTableFactory.php
1 day ago
ColumnCollection.php
85 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC; |
| 6 | |
| 7 | use AC\Exception\IteratorException; |
| 8 | |
| 9 | class ColumnCollection implements ColumnIterator |
| 10 | { |
| 11 | /** |
| 12 | * @var Column[] |
| 13 | */ |
| 14 | private array $data = []; |
| 15 | |
| 16 | public function __construct(array $data = []) |
| 17 | { |
| 18 | array_map([$this, 'add'], $data); |
| 19 | } |
| 20 | |
| 21 | public function add(Column $column): self |
| 22 | { |
| 23 | $this->data[] = $column; |
| 24 | |
| 25 | return $this; |
| 26 | } |
| 27 | |
| 28 | public static function from_iterator(ColumnIterator $iterator): self |
| 29 | { |
| 30 | return new self(iterator_to_array($iterator)); |
| 31 | } |
| 32 | |
| 33 | public function current(): Column |
| 34 | { |
| 35 | $current = current($this->data); |
| 36 | |
| 37 | if (! $current instanceof Column) { |
| 38 | throw IteratorException::from_current(); |
| 39 | } |
| 40 | |
| 41 | return $current; |
| 42 | } |
| 43 | |
| 44 | public function next(): void |
| 45 | { |
| 46 | next($this->data); |
| 47 | } |
| 48 | |
| 49 | public function key(): int |
| 50 | { |
| 51 | $key = key($this->data); |
| 52 | |
| 53 | if (! is_int($key)) { |
| 54 | throw IteratorException::from_key(); |
| 55 | } |
| 56 | |
| 57 | return $key; |
| 58 | } |
| 59 | |
| 60 | public function valid(): bool |
| 61 | { |
| 62 | return key($this->data) !== null; |
| 63 | } |
| 64 | |
| 65 | public function rewind(): void |
| 66 | { |
| 67 | reset($this->data); |
| 68 | } |
| 69 | |
| 70 | public function count(): int |
| 71 | { |
| 72 | return count($this->data); |
| 73 | } |
| 74 | |
| 75 | public function first(): ?Column |
| 76 | { |
| 77 | $first = reset($this->data); |
| 78 | |
| 79 | return $first instanceof Column |
| 80 | ? $first |
| 81 | : null; |
| 82 | } |
| 83 | |
| 84 | } |
| 85 |