Collection extends Collection
Pages collection class. Represents a collection of pages, providing methods to filter and sort them.
Table of Contents
Properties
Methods
- __construct() : mixed
- __toString() : string
- Returns the collection ID.
- add() : CollectionInterface
- Add an item or throw an exception if exists.
- all() : self
- Alias of showable().
- count() : int
- Implements Countable.
- filter() : self
- Filters items using a callback function.
- first() : Page|null
- Retrieves the first item.
- get() : Page
- Retrieves an item or throw an exception if not exists.
- getId() : string
- Returns the collection's identifier.
- getIterator() : ArrayIterator
- Implements \IteratorAggregate.
- getPosition() : int
- Retrieves an item position or throw an exception if not exists.
- has() : bool
- Does the item $id exists?
- keys() : array<string|int, mixed>
- Retrieves all keys.
- last() : ItemInterface|null
- {@inheritdoc}
- map() : CollectionInterface
- Applies a callback to items.
- offsetExists() : bool
- Implements \ArrayAccess.
- offsetGet() : CollectionInterface|ItemInterface|null
- Implements \ArrayAccess.
- offsetSet() : void
- Implements \ArrayAccess.
- offsetUnset() : void
- Implements \ArrayAccess.
- remove() : CollectionInterface
- Removes an item or throw an exception if not exists.
- replace() : CollectionInterface
- Replaces an item or throw an exception if not exists.
- reverse() : self
- Reverse items order.
- setId() : BaseInterface
- Set the collection's identifier.
- showable() : self
- Returns all "showable" pages.
- sortBy() : self
- Sorts pages by.
- sortByDate() : self
- Sorts pages by date (or 'updated'): the most recent first.
- sortByTitle() : self
- Sorts pages by title (natural sort).
- sortByWeight() : self
- Sorts by weight (the heaviest first).
- toArray() : array<string|int, mixed>
- Returns collection as array.
- toJson() : string
- Returns a JSON string of items.
- usort() : self
- Implements usort.
- searchItem() : array<string|int, mixed>|null
- Search an item by ID.
Properties
$id
Collection's identifier.
protected
string
$id
$items
Collection's items.
protected
array<string|int, mixed>
$items
= []
Methods
__construct()
public
__construct(string $id[, array<string|int, mixed> $items = [] ]) : mixed
Parameters
- $id : string
- $items : array<string|int, mixed> = []
__toString()
Returns the collection ID.
public
__toString() : string
Return values
stringadd()
Add an item or throw an exception if exists.
public
add(ItemInterface $item) : CollectionInterface
Parameters
- $item : ItemInterface
Tags
Return values
CollectionInterfaceall()
Alias of showable().
public
all() : self
Return values
selfcount()
Implements Countable.
public
count() : int
Return values
intfilter()
Filters items using a callback function.
public
filter(Closure $callback) : self
Parameters
- $callback : Closure
Return values
selffirst()
Retrieves the first item.
public
first() : Page|null
Return values
Page|nullget()
Retrieves an item or throw an exception if not exists.
public
get(string $id) : Page
Parameters
- $id : string
Return values
PagegetId()
Returns the collection's identifier.
public
getId() : string
Return values
stringgetIterator()
Implements \IteratorAggregate.
public
getIterator() : ArrayIterator
Return values
ArrayIteratorgetPosition()
Retrieves an item position or throw an exception if not exists.
public
getPosition(string $id) : int
Parameters
- $id : string
Tags
Return values
inthas()
Does the item $id exists?
public
has(string $id) : bool
Parameters
- $id : string
Return values
boolkeys()
Retrieves all keys.
public
keys() : array<string|int, mixed>
Return values
array<string|int, mixed>last()
{@inheritdoc}
public
last() : ItemInterface|null
Return values
ItemInterface|nullmap()
Applies a callback to items.
public
map(Closure $callback) : CollectionInterface
Parameters
- $callback : Closure
Return values
CollectionInterfaceoffsetExists()
Implements \ArrayAccess.
public
offsetExists(string $offset) : bool
Parameters
- $offset : string
Attributes
- #[ReturnTypeWillChange]
Return values
booloffsetGet()
Implements \ArrayAccess.
public
offsetGet(string $offset) : CollectionInterface|ItemInterface|null
Parameters
- $offset : string
Attributes
- #[ReturnTypeWillChange]
Return values
CollectionInterface|ItemInterface|nulloffsetSet()
Implements \ArrayAccess.
public
offsetSet(mixed $offset, ItemInterface $value) : void
Parameters
- $offset : mixed
- $value : ItemInterface
Tags
Attributes
- #[ReturnTypeWillChange]
offsetUnset()
Implements \ArrayAccess.
public
offsetUnset(string $offset) : void
Parameters
- $offset : string
Attributes
- #[ReturnTypeWillChange]
remove()
Removes an item or throw an exception if not exists.
public
remove(string $id) : CollectionInterface
Parameters
- $id : string
Tags
Return values
CollectionInterfacereplace()
Replaces an item or throw an exception if not exists.
public
replace(string $id, ItemInterface $item) : CollectionInterface
Parameters
- $id : string
- $item : ItemInterface
Tags
Return values
CollectionInterfacereverse()
Reverse items order.
public
reverse() : self
Return values
selfsetId()
Set the collection's identifier.
public
setId(string $id) : BaseInterface
Parameters
- $id : string
Return values
BaseInterfaceshowable()
Returns all "showable" pages.
public
showable() : self
Return values
selfsortBy()
Sorts pages by.
public
sortBy(string|array<string|int, mixed>|null $options) : self
$options: [date|updated|title|weight] or [ variable => date|updated|title|weight desc_title => false|true reverse => false|true ]
Parameters
- $options : string|array<string|int, mixed>|null
Return values
selfsortByDate()
Sorts pages by date (or 'updated'): the most recent first.
public
sortByDate([string|array<string|int, mixed>|null $options = null ]) : self
Parameters
- $options : string|array<string|int, mixed>|null = null
Return values
selfsortByTitle()
Sorts pages by title (natural sort).
public
sortByTitle([string|array<string|int, mixed>|null $options = null ]) : self
Parameters
- $options : string|array<string|int, mixed>|null = null
Return values
selfsortByWeight()
Sorts by weight (the heaviest first).
public
sortByWeight([string|array<string|int, mixed>|null $options = null ]) : self
Parameters
- $options : string|array<string|int, mixed>|null = null
Return values
selftoArray()
Returns collection as array.
public
toArray() : array<string|int, mixed>
Return values
array<string|int, mixed>toJson()
Returns a JSON string of items.
public
toJson() : string
Return values
stringusort()
Implements usort.
public
usort([Closure|null $callback = null ]) : self
Parameters
- $callback : Closure|null = null
Return values
selfsearchItem()
Search an item by ID.
protected
searchItem(string $id) : array<string|int, mixed>|null
Parameters
- $id : string