Cecil

Collection extends Collection

Pages collection class.

Represents a collection of pages, providing methods to filter and sort them.

Table of Contents

Properties

$id  : string
Collection's identifier.
$items  : array<string|int, mixed>
Collection's items.

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
string

all()

Alias of showable().

public all() : self
Return values
self

count()

Implements Countable.

public count() : int
Return values
int

filter()

Filters items using a callback function.

public filter(Closure $callback) : self
Parameters
$callback : Closure
Return values
self

get()

Retrieves an item or throw an exception if not exists.

public get(string $id) : Page
Parameters
$id : string
Return values
Page

getId()

Returns the collection's identifier.

public getId() : string
Return values
string

getIterator()

Implements \IteratorAggregate.

public getIterator() : ArrayIterator
Return values
ArrayIterator

getPosition()

Retrieves an item position or throw an exception if not exists.

public getPosition(string $id) : int
Parameters
$id : string
Tags
throws
DomainException
Return values
int

has()

Does the item $id exists?

public has(string $id) : bool
Parameters
$id : string
Return values
bool

keys()

Retrieves all keys.

public keys() : array<string|int, mixed>
Return values
array<string|int, mixed>

offsetExists()

Implements \ArrayAccess.

public offsetExists(string $offset) : bool
Parameters
$offset : string
Attributes
#[ReturnTypeWillChange]
Return values
bool

offsetSet()

Implements \ArrayAccess.

public offsetSet(mixed $offset, ItemInterface $value) : void
Parameters
$offset : mixed
$value : ItemInterface
Tags
SuppressWarnings

(PHPMD.UnusedFormalParameter)

Attributes
#[ReturnTypeWillChange]

offsetUnset()

Implements \ArrayAccess.

public offsetUnset(string $offset) : void
Parameters
$offset : string
Attributes
#[ReturnTypeWillChange]

reverse()

Reverse items order.

public reverse() : self
Return values
self

showable()

Returns all "showable" pages.

public showable() : self
Return values
self

sortBy()

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
self

sortByDate()

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
self

sortByTitle()

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
self

sortByWeight()

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
self

toArray()

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
string

usort()

Implements usort.

public usort([Closure|null $callback = null ]) : self
Parameters
$callback : Closure|null = null
Return values
self

searchItem()

Search an item by ID.

protected searchItem(string $id) : array<string|int, mixed>|null
Parameters
$id : string
Return values
array<string|int, mixed>|null
 
On this page

Search results