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
ListScreenCollection.php
97 lines
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace AC; |
| 6 | |
| 7 | use AC\Exception\IteratorException; |
| 8 | use Countable; |
| 9 | use Iterator; |
| 10 | |
| 11 | final class ListScreenCollection implements Iterator, Countable |
| 12 | { |
| 13 | /** |
| 14 | * @var ListScreen[] |
| 15 | */ |
| 16 | private array $data = []; |
| 17 | |
| 18 | public function __construct(array $list_screens = []) |
| 19 | { |
| 20 | array_map([$this, 'add'], $list_screens); |
| 21 | } |
| 22 | |
| 23 | public function add(ListScreen $list_screen): void |
| 24 | { |
| 25 | $this->data[(string)$list_screen->get_id()] = $list_screen; |
| 26 | } |
| 27 | |
| 28 | public function remove(ListScreen $list_screen): void |
| 29 | { |
| 30 | unset($this->data[(string)$list_screen->get_id()]); |
| 31 | } |
| 32 | |
| 33 | public function contains(ListScreen $list_screen): bool |
| 34 | { |
| 35 | return isset($this->data[(string)$list_screen->get_id()]); |
| 36 | } |
| 37 | |
| 38 | public function rewind(): void |
| 39 | { |
| 40 | reset($this->data); |
| 41 | } |
| 42 | |
| 43 | public function current(): ListScreen |
| 44 | { |
| 45 | $current = current($this->data); |
| 46 | |
| 47 | if (! $current instanceof ListScreen) { |
| 48 | throw IteratorException::from_current(); |
| 49 | } |
| 50 | |
| 51 | return $current; |
| 52 | } |
| 53 | |
| 54 | public function first(): ?ListScreen |
| 55 | { |
| 56 | return $this->count() |
| 57 | ? $this->data[array_key_first($this->data)] |
| 58 | : null; |
| 59 | } |
| 60 | |
| 61 | public function key(): string |
| 62 | { |
| 63 | $key = key($this->data); |
| 64 | |
| 65 | if (! is_string($key)) { |
| 66 | throw IteratorException::from_key(); |
| 67 | } |
| 68 | |
| 69 | return $key; |
| 70 | } |
| 71 | |
| 72 | public function next(): void |
| 73 | { |
| 74 | next($this->data); |
| 75 | } |
| 76 | |
| 77 | public function valid(): bool |
| 78 | { |
| 79 | return key($this->data) !== null; |
| 80 | } |
| 81 | |
| 82 | public function count(): int |
| 83 | { |
| 84 | return count($this->data); |
| 85 | } |
| 86 | |
| 87 | public function get_copy(): array |
| 88 | { |
| 89 | $copy = $this->data; |
| 90 | |
| 91 | reset($copy); |
| 92 | |
| 93 | return $copy; |
| 94 | } |
| 95 | |
| 96 | } |
| 97 |