123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <?php
- declare(strict_types=1);
- /**
- * @package Grav\Framework\Flex
- *
- * @copyright Copyright (c) 2015 - 2021 Trilby Media, LLC. All rights reserved.
- * @license MIT License; see LICENSE file for details.
- */
- namespace Grav\Framework\Flex\Interfaces;
- use Grav\Framework\Flex\Flex;
- use Grav\Framework\Object\Interfaces\NestedObjectInterface;
- use Grav\Framework\Object\Interfaces\ObjectCollectionInterface;
- use Grav\Framework\Flex\FlexDirectory;
- use InvalidArgumentException;
- /**
- * Defines a collection of Flex Objects.
- *
- * @used-by \Grav\Framework\Flex\FlexCollection
- * @since 1.6
- * @template T
- * @extends ObjectCollectionInterface<string,T>
- */
- interface FlexCollectionInterface extends FlexCommonInterface, ObjectCollectionInterface, NestedObjectInterface
- {
- /**
- * Creates a Flex Collection from an array.
- *
- * @used-by FlexDirectory::createCollection() Official method to create a Flex Collection.
- *
- * @param FlexObjectInterface[] $entries Associated array of Flex Objects to be included in the collection.
- * @param FlexDirectory $directory Flex Directory where all the objects belong into.
- * @param string|null $keyField Key field used to index the collection.
- * @return static Returns a new Flex Collection.
- */
- public static function createFromArray(array $entries, FlexDirectory $directory, string $keyField = null);
- /**
- * Creates a new Flex Collection.
- *
- * @used-by FlexDirectory::createCollection() Official method to create Flex Collection.
- *
- * @param FlexObjectInterface[] $entries Associated array of Flex Objects to be included in the collection.
- * @param FlexDirectory|null $directory Flex Directory where all the objects belong into.
- * @throws InvalidArgumentException
- */
- public function __construct(array $entries = [], FlexDirectory $directory = null);
- /**
- * Search a string from the collection.
- *
- * @param string $search Search string.
- * @param string|string[]|null $properties Properties to search for, defaults to configured properties.
- * @param array|null $options Search options, defaults to configured options.
- * @return FlexCollectionInterface Returns a Flex Collection with only matching objects.
- * @phpstan-return static<T>
- * @api
- */
- public function search(string $search, $properties = null, array $options = null);
- /**
- * Sort the collection.
- *
- * @param array $orderings Pair of [property => 'ASC'|'DESC', ...].
- *
- * @return FlexCollectionInterface Returns a sorted version from the collection.
- * @phpstan-return static<T>
- */
- public function sort(array $orderings);
- /**
- * Filter collection by filter array with keys and values.
- *
- * @param array $filters
- * @return FlexCollectionInterface
- * @phpstan-return static<T>
- */
- public function filterBy(array $filters);
- /**
- * Get timestamps from all the objects in the collection.
- *
- * This method can be used for example in caching.
- *
- * @return int[] Returns [key => timestamp, ...] pairs.
- */
- public function getTimestamps(): array;
- /**
- * Get storage keys from all the objects in the collection.
- *
- * @see FlexDirectory::getObject() If you want to get Flex Object from the Flex Directory.
- *
- * @return string[] Returns [key => storage_key, ...] pairs.
- */
- public function getStorageKeys(): array;
- /**
- * Get Flex keys from all the objects in the collection.
- *
- * @see Flex::getObjects() If you want to get list of Flex Objects from any Flex Directory.
- *
- * @return string[] Returns[key => flex_key, ...] pairs.
- */
- public function getFlexKeys(): array;
- /**
- * Return new collection with a different key.
- *
- * @param string|null $keyField Switch key field of the collection.
- * @return FlexCollectionInterface Returns a new Flex Collection with new key field.
- * @phpstan-return static<T>
- * @api
- */
- public function withKeyField(string $keyField = null);
- /**
- * Get Flex Index from the Flex Collection.
- *
- * @return FlexIndexInterface Returns a Flex Index from the current collection.
- * @phpstan-return FlexIndexInterface<T>
- */
- public function getIndex();
- /**
- * Load all the objects into memory,
- *
- * @return FlexCollectionInterface
- * @phpstan-return static<T>
- */
- public function getCollection();
- /**
- * Get metadata associated to the object
- *
- * @param string $key Key.
- * @return array
- */
- public function getMetaData(string $key): array;
- }
|