FlexIndexInterface
extends
FlexCollectionInterface
in
Defines Indexes for Flex Objects.
Flex indexes are similar to database indexes, they contain indexed fields which can be used to quickly look up or find the objects without loading them.
Tags
Table of Contents
Methods
- __construct() : mixed
- Creates a new Flex Collection.
- call() : array<string|int, mixed>
- chunk() : array<string|int, mixed>
- Split collection into chunks.
- collectionGroup() : array<string|int, static>
- Group items in the collection by a field and return them as associated array of collections.
- copy() : static
- Create a copy from this collection by cloning all objects in the collection.
- createFromArray() : static
- Creates a Flex Collection from an array.
- createFromStorage() : static
- Helper method to create Flex Index.
- defNestedProperty() : $this
- defProperty() : $this
- filterBy() : FlexCollectionInterface
- Filter collection by filter array with keys and values.
- getCacheChecksum() : string
- Get cache checksum for the object / collection.
- getCacheKey() : string
- Get a cache key which is used for caching the object / collection.
- getCollection() : FlexCollectionInterface
- Load all the objects into memory,
- getFlexDirectory() : FlexDirectory
- Get Flex Directory for the object / collection.
- getFlexFeatures() : array<string|int, mixed>
- Get full list of features the object / collection implements.
- getFlexKeys() : array<string|int, string>
- Get Flex keys from all the objects in the collection.
- getFlexType() : string
- Get Flex Type of the object / collection.
- getIndex() : FlexIndexInterface
- Get Flex Index from the Flex Collection.
- getIndexMap() : array<string|int, mixed>
- getKey() : string
- getMetaData() : array<string|int, mixed>
- Get metadata associated to the object
- getNestedProperty() : mixed|array<string|int, mixed>
- getObjectKeys() : array<string|int, mixed>
- getProperty() : array<string|int, mixed>
- getStorageKeys() : array<string|int, string>
- Get storage keys from all the objects in the collection.
- getTimestamp() : int
- Get last updated timestamp for the object / collection.
- getTimestamps() : array<string|int, int>
- Get timestamps from all the objects in the collection.
- getType() : string
- group() : array<string|int, mixed>
- Group items in the collection by a field and return them as associated array.
- hasFlexFeature() : bool
- Test whether the feature is implemented in the object / collection.
- hasNestedProperty() : bool|array<string|int, bool>
- hasProperty() : array<string|int, bool>
- limit() : ObjectCollectionInterface
- loadEntriesFromStorage() : array<string|int, mixed>
- Method to load index from the object storage, usually filesystem.
- orderBy() : ObjectCollectionInterface
- render() : ContentBlockInterface|HtmlBlock
- Renders the object.
- reverse() : CollectionInterface
- Reverse the order of the items.
- search() : FlexCollectionInterface
- Search a string from the collection.
- select() : CollectionInterface
- Select items from collection.
- setKey() : $this
- setNestedProperty() : $this
- setProperty() : $this
- shuffle() : CollectionInterface
- Shuffle items.
- sort() : FlexCollectionInterface
- Sort the collection.
- unselect() : CollectionInterface
- Un-select items from collection.
- unsetNestedProperty() : $this
- unsetProperty() : $this
- withKeyField() : static
- Return new collection with a different key.
Methods
__construct()
Creates a new Flex Collection.
public
__construct([array<string|int, FlexObjectInterface> $entries = [] ][, FlexDirectory|null $directory = null ]) : mixed
Parameters
- $entries : array<string|int, FlexObjectInterface> = []
-
Associated array of Flex Objects to be included in the collection.
- $directory : FlexDirectory|null = null
-
Flex Directory where all the objects belong into.
Tags
call()
public
call(string $name[, array<string|int, mixed> $arguments = [] ]) : array<string|int, mixed>
Parameters
- $name : string
-
Method name.
- $arguments : array<string|int, mixed> = []
-
List of arguments passed to the function.
Return values
array<string|int, mixed> —Return values.
chunk()
Split collection into chunks.
public
chunk(int $size) : array<string|int, mixed>
Parameters
- $size : int
-
Size of each chunk.
Tags
Return values
array<string|int, mixed>collectionGroup()
Group items in the collection by a field and return them as associated array of collections.
public
collectionGroup(string $property) : array<string|int, static>
Parameters
- $property : string
Tags
Return values
array<string|int, static>copy()
Create a copy from this collection by cloning all objects in the collection.
public
copy() : static
Tags
Return values
staticcreateFromArray()
Creates a Flex Collection from an array.
public
static createFromArray(array<string|int, FlexObjectInterface> $entries, FlexDirectory $directory[, string|null $keyField = null ]) : static
Parameters
- $entries : array<string|int, FlexObjectInterface>
-
Associated array of Flex Objects to be included in the collection.
- $directory : FlexDirectory
-
Flex Directory where all the objects belong into.
- $keyField : string|null = null
-
Key field used to index the collection.
Tags
Return values
static —Returns a new Flex Collection.
createFromStorage()
Helper method to create Flex Index.
public
static createFromStorage(FlexDirectory $directory) : static
Parameters
- $directory : FlexDirectory
-
Flex directory.
Tags
Return values
static —Returns a new Flex Index.
defNestedProperty()
public
defNestedProperty(string $property, mixed $default[, string|null $separator = null ]) : $this
Parameters
- $property : string
-
Object property to be defined.
- $default : mixed
-
Default value.
- $separator : string|null = null
-
Separator, defaults to '.'
Tags
Return values
$thisdefProperty()
public
defProperty(string $property, mixed $default) : $this
Parameters
- $property : string
-
Object property to be defined.
- $default : mixed
-
Default value.
Return values
$thisfilterBy()
Filter collection by filter array with keys and values.
public
filterBy(array<string|int, mixed> $filters) : FlexCollectionInterface
Parameters
- $filters : array<string|int, mixed>
Tags
Return values
FlexCollectionInterfacegetCacheChecksum()
Get cache checksum for the object / collection.
public
getCacheChecksum() : string
If checksum changes, cache gets invalided.
Return values
string —Returns cache checksum.
getCacheKey()
Get a cache key which is used for caching the object / collection.
public
getCacheKey() : string
Return values
string —Returns cache key.
getCollection()
Load all the objects into memory,
public
getCollection() : FlexCollectionInterface
Tags
Return values
FlexCollectionInterfacegetFlexDirectory()
Get Flex Directory for the object / collection.
public
getFlexDirectory() : FlexDirectory
Return values
FlexDirectory —Returns associated Flex Directory.
getFlexFeatures()
Get full list of features the object / collection implements.
public
getFlexFeatures() : array<string|int, mixed>
Return values
array<string|int, mixed>getFlexKeys()
Get Flex keys from all the objects in the collection.
public
getFlexKeys() : array<string|int, string>
Tags
Return values
array<string|int, string> —Returns[key => flex_key, ...] pairs.
getFlexType()
Get Flex Type of the object / collection.
public
getFlexType() : string
Return values
string —Returns Flex Type of the collection.
getIndex()
Get Flex Index from the Flex Collection.
public
getIndex() : FlexIndexInterface
Tags
Return values
FlexIndexInterface —Returns a Flex Index from the current collection.
getIndexMap()
public
getIndexMap([string|null $indexKey = null ]) : array<string|int, mixed>
Parameters
- $indexKey : string|null = null
Return values
array<string|int, mixed>getKey()
public
getKey() : string
Return values
stringgetMetaData()
Get metadata associated to the object
public
getMetaData(string $key) : array<string|int, mixed>
Parameters
- $key : string
-
Key.
Return values
array<string|int, mixed>getNestedProperty()
public
getNestedProperty(string $property[, mixed|null $default = null ][, string|null $separator = null ]) : mixed|array<string|int, mixed>
Parameters
- $property : string
-
Object property to be fetched.
- $default : mixed|null = null
-
Default value if property has not been set.
- $separator : string|null = null
-
Separator, defaults to '.'
Return values
mixed|array<string|int, mixed> —Property value.
getObjectKeys()
public
getObjectKeys() : array<string|int, mixed>
Return values
array<string|int, mixed>getProperty()
public
getProperty(string $property[, mixed|null $default = null ]) : array<string|int, mixed>
Parameters
- $property : string
-
Object property to be fetched.
- $default : mixed|null = null
-
Default value if property has not been set.
Return values
array<string|int, mixed> —List of [key => value] pairs.
getStorageKeys()
Get storage keys from all the objects in the collection.
public
getStorageKeys() : array<string|int, string>
Tags
Return values
array<string|int, string> —Returns [key => storage_key, ...] pairs.
getTimestamp()
Get last updated timestamp for the object / collection.
public
getTimestamp() : int
Return values
int —Returns Unix timestamp.
getTimestamps()
Get timestamps from all the objects in the collection.
public
getTimestamps() : array<string|int, int>
This method can be used for example in caching.
Return values
array<string|int, int> —Returns [key => timestamp, ...] pairs.
getType()
public
getType() : string
Return values
stringgroup()
Group items in the collection by a field and return them as associated array.
public
group(string $property) : array<string|int, mixed>
Parameters
- $property : string
Return values
array<string|int, mixed>hasFlexFeature()
Test whether the feature is implemented in the object / collection.
public
hasFlexFeature(string $name) : bool
Parameters
- $name : string
Return values
boolhasNestedProperty()
public
hasNestedProperty(string $property[, string|null $separator = null ]) : bool|array<string|int, bool>
Parameters
- $property : string
-
Object property name.
- $separator : string|null = null
-
Separator, defaults to '.'
Return values
bool|array<string|int, bool> —True if property has been defined (can be null).
hasProperty()
public
hasProperty(string $property) : array<string|int, bool>
Parameters
- $property : string
-
Object property name.
Return values
array<string|int, bool> —List of [key => bool] pairs.
limit()
public
limit(int $start[, int|null $limit = null ]) : ObjectCollectionInterface
Parameters
- $start : int
- $limit : int|null = null
Tags
Return values
ObjectCollectionInterfaceloadEntriesFromStorage()
Method to load index from the object storage, usually filesystem.
public
static loadEntriesFromStorage(FlexStorageInterface $storage) : array<string|int, mixed>
Parameters
- $storage : FlexStorageInterface
-
Flex Storage associated to the directory.
Tags
Return values
array<string|int, mixed> —Returns a list of existing objects [storage_key => [storage_key => xxx, storage_timestamp => 123456, ...]]
orderBy()
public
orderBy(array<string|int, mixed> $ordering) : ObjectCollectionInterface
Parameters
- $ordering : array<string|int, mixed>
Tags
Return values
ObjectCollectionInterfacerender()
Renders the object.
public
render([string|null $layout = null ][, array<string|int, mixed> $context = [] ]) : ContentBlockInterface|HtmlBlock
Parameters
- $layout : string|null = null
-
Layout to be used.
- $context : array<string|int, mixed> = []
-
Extra context given to the renderer.
Tags
Return values
ContentBlockInterface|HtmlBlock —Returns HtmlBlock containing the rendered output.
reverse()
Reverse the order of the items.
public
reverse() : CollectionInterface
Tags
Return values
CollectionInterfacesearch()
Search a string from the collection.
public
search(string $search[, string|array<string|int, string>|null $properties = null ][, array<string|int, mixed>|null $options = null ]) : FlexCollectionInterface
Parameters
- $search : string
-
Search string.
- $properties : string|array<string|int, string>|null = null
-
Properties to search for, defaults to configured properties.
- $options : array<string|int, mixed>|null = null
-
Search options, defaults to configured options.
Tags
Return values
FlexCollectionInterface —Returns a Flex Collection with only matching objects.
select()
Select items from collection.
public
select(array<string|int, int|string> $keys) : CollectionInterface
Collection is returned in the order of $keys given to the function.
Parameters
- $keys : array<string|int, int|string>
Tags
Return values
CollectionInterfacesetKey()
public
setKey(string $key) : $this
Parameters
- $key : string
Return values
$thissetNestedProperty()
public
setNestedProperty(string $property, mixed $value[, string|null $separator = null ]) : $this
Parameters
- $property : string
-
Object property to be updated.
- $value : mixed
-
New value.
- $separator : string|null = null
-
Separator, defaults to '.'
Tags
Return values
$thissetProperty()
public
setProperty(string $property, mixed $value) : $this
Parameters
- $property : string
-
Object property to be updated.
- $value : mixed
-
New value.
Return values
$thisshuffle()
Shuffle items.
public
shuffle() : CollectionInterface
Tags
Return values
CollectionInterfacesort()
Sort the collection.
public
sort(array<string|int, mixed> $orderings) : FlexCollectionInterface
Parameters
- $orderings : array<string|int, mixed>
-
Pair of [property => 'ASC'|'DESC', ...].
Tags
Return values
FlexCollectionInterface —Returns a sorted version from the collection.
unselect()
Un-select items from collection.
public
unselect(array<string|int, int|string> $keys) : CollectionInterface
Parameters
- $keys : array<string|int, int|string>
Tags
Return values
CollectionInterfaceunsetNestedProperty()
public
unsetNestedProperty(string $property[, string|null $separator = null ]) : $this
Parameters
- $property : string
-
Object property to be unset.
- $separator : string|null = null
-
Separator, defaults to '.'
Tags
Return values
$thisunsetProperty()
public
unsetProperty(string $property) : $this
Parameters
- $property : string
-
Object property to be unset.
Return values
$thiswithKeyField()
Return new collection with a different key.
public
withKeyField([string|null $keyField = null ]) : static
Parameters
- $keyField : string|null = null
-
Switch key field of the collection.
Tags
Return values
static —Returns a new Flex Collection with new key field.