Collection
extends Iterator
in package
implements
PageCollectionInterface
Class Collection
Tags
Table of Contents
Interfaces
- PageCollectionInterface
- Interface PageCollectionInterface
Properties
Methods
- __call() : mixed
- Convert function calls for the existing keys into their values.
- __clone() : mixed
- Clone the iterator.
- __construct() : mixed
- Collection constructor.
- __toString() : string
- Convents iterator to a comma separated list.
- add() : $this
- Add a page with path and slug
- addPage() : $this
- Add a single page to a collection
- adjacentSibling() : PageInterface|Collection
- Returns the adjacent sibling based on a direction.
- append() : $this
- Append new elements to the list.
- batch() : array<string|int, Collection>
- Split collection into array of smaller collections.
- copy() : static
- Create a copy of this collection
- current() : PageInterface
- Returns current page.
- currentPosition() : int|null
- Returns the item in the current position.
- dateRange() : $this
- Returns the items between a set of date ranges of either the page date field (default) or an arbitrary datetime page field where start date and end date are optional Dates must be passed in as text that strtotime() can process http://php.net/manual/en/function.strtotime.php
- filter() : $this
- Filter elements from the list
- first() : mixed
- Get the first item
- indexOf() : string|int|false
- intersect() : $this
- Intersect another collection with the current collection
- isFirst() : bool
- Check to see if this item is the first in the collection.
- isLast() : bool
- Check to see if this item is the last in the collection.
- key() : mixed
- Returns current slug.
- last() : mixed
- Get the last item
- merge() : $this
- Merge another collection with the current collection
- modular() : Collection
- Alias of modules()
- modules() : Collection
- Creates new collection with only modules
- nextSibling() : PageInterface
- Gets the next sibling based on current position.
- nonModular() : Collection
- Alias of pages()
- nonPublished() : Collection
- Creates new collection with only non-published pages
- nonRoutable() : Collection
- Creates new collection with only non-routable pages
- nonVisible() : Collection
- Creates new collection with only non-visible pages
- nth() : mixed|bool
- Return nth item.
- offsetGet() : PageInterface|null
- Returns the value at specified offset.
- ofOneOfTheseAccessLevels() : Collection
- Creates new collection with only pages of one of the specified access levels
- ofOneOfTheseTypes() : Collection
- Creates new collection with only pages of one of the specified types
- ofType() : Collection
- Creates new collection with only pages of the specified type
- order() : $this
- Reorder collection.
- pages() : Collection
- Creates new collection with only pages
- params() : array<string|int, mixed>
- Get the collection params
- prev() : mixed
- Return previous item.
- prevSibling() : PageInterface
- Gets the previous sibling based on current position.
- published() : Collection
- Creates new collection with only published pages
- random() : $this
- Pick one or more random entries.
- remove() : $this
- Remove item from the list.
- reverse() : $this
- Reverse the Iterator
- routable() : Collection
- Creates new collection with only routable pages
- setCurrent() : void
- Set current page.
- setParams() : $this
- Set parameters to the Collection
- shuffle() : $this
- Shuffle items.
- slice() : $this
- Slice the list.
- sort() : $this|array<string|int, mixed>
- Sorts elements from the list and returns a copy of the list in the proper order
- toExtendedArray() : array<string|int, mixed>
- Get the extended version of this Collection with each page keyed by route
- visible() : Collection
- Creates new collection with only visible pages
Properties
$items
protected
array<string|int, mixed>
$items
= []
$pages
protected
Pages
$pages
$params
protected
array<string|int, mixed>
$params
Methods
__call()
Convert function calls for the existing keys into their values.
public
__call(string $key, mixed $args) : mixed
Parameters
- $key : string
- $args : mixed
Attributes
- #[ReturnTypeWillChange]
__clone()
Clone the iterator.
public
__clone() : mixed
Attributes
- #[ReturnTypeWillChange]
__construct()
Collection constructor.
public
__construct([array<string|int, mixed> $items = [] ][, array<string|int, mixed> $params = [] ][, Pages|null $pages = null ]) : mixed
Parameters
- $items : array<string|int, mixed> = []
- $params : array<string|int, mixed> = []
- $pages : Pages|null = null
__toString()
Convents iterator to a comma separated list.
public
__toString() : string
Attributes
- #[ReturnTypeWillChange]
Return values
stringadd()
Add a page with path and slug
public
add(string $path, string $slug) : $this
Parameters
- $path : string
- $slug : string
Return values
$thisaddPage()
Add a single page to a collection
public
addPage(PageInterface $page) : $this
Parameters
- $page : PageInterface
Return values
$thisadjacentSibling()
Returns the adjacent sibling based on a direction.
public
adjacentSibling(string $path[, int $direction = 1 ]) : PageInterface|Collection
Parameters
- $path : string
- $direction : int = 1
-
either -1 or +1
Return values
PageInterface|Collection —The sibling item.
append()
Append new elements to the list.
public
append(array<string|int, mixed>|Iterator $items) : $this
Parameters
- $items : array<string|int, mixed>|Iterator
-
Items to be appended. Existing keys will be overridden with the new values.
Return values
$thisbatch()
Split collection into array of smaller collections.
public
batch(int $size) : array<string|int, Collection>
Parameters
- $size : int
Return values
array<string|int, Collection>copy()
Create a copy of this collection
public
copy() : static
Return values
staticcurrent()
Returns current page.
public
current() : PageInterface
Attributes
- #[ReturnTypeWillChange]
Return values
PageInterfacecurrentPosition()
Returns the item in the current position.
public
currentPosition(string $path) : int|null
Parameters
- $path : string
-
the path the item
Return values
int|null —The index of the current page, null if not found.
dateRange()
Returns the items between a set of date ranges of either the page date field (default) or an arbitrary datetime page field where start date and end date are optional Dates must be passed in as text that strtotime() can process http://php.net/manual/en/function.strtotime.php
public
dateRange([string|null $startDate = null ][, string|null $endDate = null ][, string|null $field = null ]) : $this
Parameters
- $startDate : string|null = null
- $endDate : string|null = null
- $field : string|null = null
Tags
Return values
$thisfilter()
Filter elements from the list
public
filter([callable|null $callback = null ]) : $this
Parameters
- $callback : callable|null = null
-
A function the receives ($value, $key) and must return a boolean to indicate filter status
Return values
$thisfirst()
Get the first item
public
first() : mixed
indexOf()
public
indexOf(mixed $needle) : string|int|false
Parameters
- $needle : mixed
-
Searched value.
Return values
string|int|false —Key if found, otherwise false.
intersect()
Intersect another collection with the current collection
public
intersect(PageCollectionInterface $collection) : $this
Parameters
- $collection : PageCollectionInterface
Return values
$thisisFirst()
Check to see if this item is the first in the collection.
public
isFirst(string $path) : bool
Parameters
- $path : string
Return values
bool —True if item is first.
isLast()
Check to see if this item is the last in the collection.
public
isLast(string $path) : bool
Parameters
- $path : string
Return values
bool —True if item is last.
key()
Returns current slug.
public
key() : mixed
Attributes
- #[ReturnTypeWillChange]
last()
Get the last item
public
last() : mixed
merge()
Merge another collection with the current collection
public
merge(PageCollectionInterface $collection) : $this
Parameters
- $collection : PageCollectionInterface
Return values
$thismodular()
Alias of modules()
public
modular() : Collection
Return values
Collection —The collection with only modules
modules()
Creates new collection with only modules
public
modules() : Collection
Return values
Collection —The collection with only modules
nextSibling()
Gets the next sibling based on current position.
public
nextSibling(string $path) : PageInterface
Parameters
- $path : string
Return values
PageInterface —The next item.
nonModular()
Alias of pages()
public
nonModular() : Collection
Return values
Collection —The collection with only non-module pages
nonPublished()
Creates new collection with only non-published pages
public
nonPublished() : Collection
Return values
Collection —The collection with only non-published pages
nonRoutable()
Creates new collection with only non-routable pages
public
nonRoutable() : Collection
Return values
Collection —The collection with only non-routable pages
nonVisible()
Creates new collection with only non-visible pages
public
nonVisible() : Collection
Return values
Collection —The collection with only non-visible pages
nth()
Return nth item.
public
nth(int $key) : mixed|bool
Parameters
- $key : int
Return values
mixed|booloffsetGet()
Returns the value at specified offset.
public
offsetGet(string $offset) : PageInterface|null
Parameters
- $offset : string
Attributes
- #[ReturnTypeWillChange]
Return values
PageInterface|nullofOneOfTheseAccessLevels()
Creates new collection with only pages of one of the specified access levels
public
ofOneOfTheseAccessLevels(array<string|int, mixed> $accessLevels) : Collection
Parameters
- $accessLevels : array<string|int, mixed>
Return values
Collection —The collection
ofOneOfTheseTypes()
Creates new collection with only pages of one of the specified types
public
ofOneOfTheseTypes(array<string|int, string> $types) : Collection
Parameters
- $types : array<string|int, string>
Return values
Collection —The collection
ofType()
Creates new collection with only pages of the specified type
public
ofType(string $type) : Collection
Parameters
- $type : string
Return values
Collection —The collection
order()
Reorder collection.
public
order(string $by[, string $dir = 'asc' ][, array<string|int, mixed>|null $manual = null ][, string|null $sort_flags = null ]) : $this
Parameters
- $by : string
- $dir : string = 'asc'
- $manual : array<string|int, mixed>|null = null
- $sort_flags : string|null = null
Return values
$thispages()
Creates new collection with only pages
public
pages() : Collection
Return values
Collection —The collection with only pages
params()
Get the collection params
public
params() : array<string|int, mixed>
Return values
array<string|int, mixed>prev()
Return previous item.
public
prev() : mixed
prevSibling()
Gets the previous sibling based on current position.
public
prevSibling(string $path) : PageInterface
Parameters
- $path : string
Return values
PageInterface —The previous item.
published()
Creates new collection with only published pages
public
published() : Collection
Return values
Collection —The collection with only published pages
random()
Pick one or more random entries.
public
random([int $num = 1 ]) : $this
Parameters
- $num : int = 1
-
Specifies how many entries should be picked.
Return values
$thisremove()
Remove item from the list.
public
remove([PageInterface|string|null $key = null ]) : $this
Parameters
- $key : PageInterface|string|null = null
Tags
Return values
$thisreverse()
Reverse the Iterator
public
reverse() : $this
Return values
$thisroutable()
Creates new collection with only routable pages
public
routable() : Collection
Return values
Collection —The collection with only routable pages
setCurrent()
Set current page.
public
setCurrent(string $path) : void
Parameters
- $path : string
setParams()
Set parameters to the Collection
public
setParams(array<string|int, mixed> $params) : $this
Parameters
- $params : array<string|int, mixed>
Return values
$thisshuffle()
Shuffle items.
public
shuffle() : $this
Return values
$thisslice()
Slice the list.
public
slice(int $offset[, int|null $length = null ]) : $this
Parameters
- $offset : int
- $length : int|null = null
Return values
$thissort()
Sorts elements from the list and returns a copy of the list in the proper order
public
sort([callable|null $callback = null ][, bool $desc = false ]) : $this|array<string|int, mixed>
Parameters
- $callback : callable|null = null
- $desc : bool = false
Return values
$this|array<string|int, mixed>toExtendedArray()
Get the extended version of this Collection with each page keyed by route
public
toExtendedArray() : array<string|int, mixed>
Tags
Return values
array<string|int, mixed>visible()
Creates new collection with only visible pages
public
visible() : Collection
Return values
Collection —The collection with only visible pages