PK yNgU` ` psalm.xml.distnu W+A
PK yNՆ" " . lib/Doctrine/Common/Collections/Collection.phpnu W+A ordered map that can also be used
* like a list.
*
* A Collection has an internal iterator just like a PHP array. In addition,
* a Collection can be iterated with external iterators, which is preferable.
* To use an external iterator simply use the foreach language construct to
* iterate over the collection (which calls {@link getIterator()} internally) or
* explicitly retrieve an iterator though {@link getIterator()} which can then be
* used to iterate over the collection.
* You can not rely on the internal iterator of the collection being at a certain
* position unless you explicitly positioned it before. Prefer iteration with
* external iterators.
*
* @psalm-template TKey of array-key
* @psalm-template T
* @template-extends IteratorAggregate
* @template-extends ArrayAccess
*/
interface Collection extends Countable, IteratorAggregate, ArrayAccess
{
/**
* Adds an element at the end of the collection.
*
* @param mixed $element The element to add.
*
* @return true Always TRUE.
*
* @psalm-param T $element
*/
public function add($element);
/**
* Clears the collection, removing all elements.
*
* @return void
*/
public function clear();
/**
* Checks whether an element is contained in the collection.
* This is an O(n) operation, where n is the size of the collection.
*
* @param mixed $element The element to search for.
*
* @return bool TRUE if the collection contains the element, FALSE otherwise.
*
* @psalm-param T $element
*/
public function contains($element);
/**
* Checks whether the collection is empty (contains no elements).
*
* @return bool TRUE if the collection is empty, FALSE otherwise.
*/
public function isEmpty();
/**
* Removes the element at the specified index from the collection.
*
* @param string|int $key The key/index of the element to remove.
*
* @return mixed The removed element or NULL, if the collection did not contain the element.
*
* @psalm-param TKey $key
* @psalm-return T|null
*/
public function remove($key);
/**
* Removes the specified element from the collection, if it is found.
*
* @param mixed $element The element to remove.
*
* @return bool TRUE if this collection contained the specified element, FALSE otherwise.
*
* @psalm-param T $element
*/
public function removeElement($element);
/**
* Checks whether the collection contains an element with the specified key/index.
*
* @param string|int $key The key/index to check for.
*
* @return bool TRUE if the collection contains an element with the specified key/index,
* FALSE otherwise.
*
* @psalm-param TKey $key
*/
public function containsKey($key);
/**
* Gets the element at the specified key/index.
*
* @param string|int $key The key/index of the element to retrieve.
*
* @return mixed
*
* @psalm-param TKey $key
* @psalm-return T|null
*/
public function get($key);
/**
* Gets all keys/indices of the collection.
*
* @return int[]|string[] The keys/indices of the collection, in the order of the corresponding
* elements in the collection.
*
* @psalm-return TKey[]
*/
public function getKeys();
/**
* Gets all values of the collection.
*
* @return array The values of all elements in the collection, in the order they
* appear in the collection.
*
* @psalm-return T[]
*/
public function getValues();
/**
* Sets an element in the collection at the specified key/index.
*
* @param string|int $key The key/index of the element to set.
* @param mixed $value The element to set.
*
* @return void
*
* @psalm-param TKey $key
* @psalm-param T $value
*/
public function set($key, $value);
/**
* Gets a native PHP array representation of the collection.
*
* @return array
*
* @psalm-return array
*/
public function toArray();
/**
* Sets the internal iterator to the first element in the collection and returns this element.
*
* @return mixed
*
* @psalm-return T|false
*/
public function first();
/**
* Sets the internal iterator to the last element in the collection and returns this element.
*
* @return mixed
*
* @psalm-return T|false
*/
public function last();
/**
* Gets the key/index of the element at the current iterator position.
*
* @return int|string
*
* @psalm-return TKey
*/
public function key();
/**
* Gets the element of the collection at the current iterator position.
*
* @return mixed
*
* @psalm-return T|false
*/
public function current();
/**
* Moves the internal iterator position to the next element and returns this element.
*
* @return mixed
*
* @psalm-return T|false
*/
public function next();
/**
* Tests for the existence of an element that satisfies the given predicate.
*
* @param Closure $p The predicate.
*
* @return bool TRUE if the predicate is TRUE for at least one element, FALSE otherwise.
*
* @psalm-param Closure(TKey=, T=):bool $p
*/
public function exists(Closure $p);
/**
* Returns all the elements of this collection that satisfy the predicate p.
* The order of the elements is preserved.
*
* @param Closure $p The predicate used for filtering.
*
* @return Collection A collection with the results of the filter operation.
*
* @psalm-param Closure(T=):bool $p
* @psalm-return Collection
*/
public function filter(Closure $p);
/**
* Tests whether the given predicate p holds for all elements of this collection.
*
* @param Closure $p The predicate.
*
* @return bool TRUE, if the predicate yields TRUE for all elements, FALSE otherwise.
*
* @psalm-param Closure(TKey=, T=):bool $p
*/
public function forAll(Closure $p);
/**
* Applies the given function to each element in the collection and returns
* a new collection with the elements returned by the function.
*
* @return Collection
*
* @psalm-template U
* @psalm-param Closure(T=):U $func
* @psalm-return Collection
*/
public function map(Closure $func);
/**
* Partitions this collection in two collections according to a predicate.
* Keys are preserved in the resulting collections.
*
* @param Closure $p The predicate on which to partition.
*
* @return Collection[] An array with two elements. The first element contains the collection
* of elements where the predicate returned TRUE, the second element
* contains the collection of elements where the predicate returned FALSE.
*
* @psalm-param Closure(TKey=, T=):bool $p
* @psalm-return array{0: Collection, 1: Collection}
*/
public function partition(Closure $p);
/**
* Gets the index/key of a given element. The comparison of two elements is strict,
* that means not only the value but also the type must match.
* For objects this means reference equality.
*
* @param mixed $element The element to search for.
*
* @return int|string|bool The key/index of the element or FALSE if the element was not found.
*
* @psalm-param T $element
* @psalm-return TKey|false
*/
public function indexOf($element);
/**
* Extracts a slice of $length elements starting at position $offset from the Collection.
*
* If $length is null it returns all elements from $offset to the end of the Collection.
* Keys have to be preserved by this method. Calling this method will only return the
* selected slice and NOT change the elements contained in the collection slice is called on.
*
* @param int $offset The offset to start from.
* @param int|null $length The maximum number of elements to return, or null for no limit.
*
* @return array
*
* @psalm-return array
*/
public function slice($offset, $length = null);
}
PK yN( 5 lib/Doctrine/Common/Collections/ExpressionBuilder.phpnu W+A
*/
abstract class AbstractLazyCollection implements Collection
{
/**
* The backed collection to use
*
* @psalm-var Collection
* @var Collection
*/
protected $collection;
/** @var bool */
protected $initialized = false;
/**
* {@inheritDoc}
*/
public function count()
{
$this->initialize();
return $this->collection->count();
}
/**
* {@inheritDoc}
*/
public function add($element)
{
$this->initialize();
return $this->collection->add($element);
}
/**
* {@inheritDoc}
*/
public function clear()
{
$this->initialize();
$this->collection->clear();
}
/**
* {@inheritDoc}
*/
public function contains($element)
{
$this->initialize();
return $this->collection->contains($element);
}
/**
* {@inheritDoc}
*/
public function isEmpty()
{
$this->initialize();
return $this->collection->isEmpty();
}
/**
* {@inheritDoc}
*/
public function remove($key)
{
$this->initialize();
return $this->collection->remove($key);
}
/**
* {@inheritDoc}
*/
public function removeElement($element)
{
$this->initialize();
return $this->collection->removeElement($element);
}
/**
* {@inheritDoc}
*/
public function containsKey($key)
{
$this->initialize();
return $this->collection->containsKey($key);
}
/**
* {@inheritDoc}
*/
public function get($key)
{
$this->initialize();
return $this->collection->get($key);
}
/**
* {@inheritDoc}
*/
public function getKeys()
{
$this->initialize();
return $this->collection->getKeys();
}
/**
* {@inheritDoc}
*/
public function getValues()
{
$this->initialize();
return $this->collection->getValues();
}
/**
* {@inheritDoc}
*/
public function set($key, $value)
{
$this->initialize();
$this->collection->set($key, $value);
}
/**
* {@inheritDoc}
*/
public function toArray()
{
$this->initialize();
return $this->collection->toArray();
}
/**
* {@inheritDoc}
*/
public function first()
{
$this->initialize();
return $this->collection->first();
}
/**
* {@inheritDoc}
*/
public function last()
{
$this->initialize();
return $this->collection->last();
}
/**
* {@inheritDoc}
*/
public function key()
{
$this->initialize();
return $this->collection->key();
}
/**
* {@inheritDoc}
*/
public function current()
{
$this->initialize();
return $this->collection->current();
}
/**
* {@inheritDoc}
*/
public function next()
{
$this->initialize();
return $this->collection->next();
}
/**
* {@inheritDoc}
*/
public function exists(Closure $p)
{
$this->initialize();
return $this->collection->exists($p);
}
/**
* {@inheritDoc}
*/
public function filter(Closure $p)
{
$this->initialize();
return $this->collection->filter($p);
}
/**
* {@inheritDoc}
*/
public function forAll(Closure $p)
{
$this->initialize();
return $this->collection->forAll($p);
}
/**
* {@inheritDoc}
*/
public function map(Closure $func)
{
$this->initialize();
return $this->collection->map($func);
}
/**
* {@inheritDoc}
*/
public function partition(Closure $p)
{
$this->initialize();
return $this->collection->partition($p);
}
/**
* {@inheritDoc}
*/
public function indexOf($element)
{
$this->initialize();
return $this->collection->indexOf($element);
}
/**
* {@inheritDoc}
*/
public function slice($offset, $length = null)
{
$this->initialize();
return $this->collection->slice($offset, $length);
}
/**
* {@inheritDoc}
*/
public function getIterator()
{
$this->initialize();
return $this->collection->getIterator();
}
/**
* {@inheritDoc}
*/
public function offsetExists($offset)
{
$this->initialize();
return $this->collection->offsetExists($offset);
}
/**
* {@inheritDoc}
*/
public function offsetGet($offset)
{
$this->initialize();
return $this->collection->offsetGet($offset);
}
/**
* {@inheritDoc}
*/
public function offsetSet($offset, $value)
{
$this->initialize();
$this->collection->offsetSet($offset, $value);
}
/**
* {@inheritDoc}
*/
public function offsetUnset($offset)
{
$this->initialize();
$this->collection->offsetUnset($offset);
}
/**
* Is the lazy collection already initialized?
*
* @return bool
*/
public function isInitialized()
{
return $this->initialized;
}
/**
* Initialize the collection
*
* @return void
*/
protected function initialize()
{
if ($this->initialized) {
return;
}
$this->doInitialize();
$this->initialized = true;
}
/**
* Do the initialization logic
*
* @return void
*/
abstract protected function doInitialize();
}
PK yN98 . lib/Doctrine/Common/Collections/Selectable.phpnu W+A
*/
public function matching(Criteria $criteria);
}
PK yNO& . lib/Doctrine/Common/Collections/Expr/Value.phpnu W+A value = $value;
}
/**
* @return mixed
*/
public function getValue()
{
return $this->value;
}
/**
* {@inheritDoc}
*/
public function visit(ExpressionVisitor $visitor)
{
return $visitor->walkValue($this);
}
}
PK yN 3 lib/Doctrine/Common/Collections/Expr/Expression.phpnu W+A $accessor();
}
}
if (preg_match('/^is[A-Z]+/', $field) === 1 && method_exists($object, $field)) {
return $object->$field();
}
// __call should be triggered for get.
$accessor = $accessors[0] . $field;
if (method_exists($object, '__call')) {
return $object->$accessor();
}
if ($object instanceof ArrayAccess) {
return $object[$field];
}
if (isset($object->$field)) {
return $object->$field;
}
// camelcase field name to support different variable naming conventions
$ccField = preg_replace_callback('/_(.?)/', static function ($matches) {
return strtoupper($matches[1]);
}, $field);
foreach ($accessors as $accessor) {
$accessor .= $ccField;
if (method_exists($object, $accessor)) {
return $object->$accessor();
}
}
return $object->$field;
}
/**
* Helper for sorting arrays of objects based on multiple fields + orientations.
*
* @param string $name
* @param int $orientation
*
* @return Closure
*/
public static function sortByField($name, $orientation = 1, ?Closure $next = null)
{
if (! $next) {
$next = static function () : int {
return 0;
};
}
return static function ($a, $b) use ($name, $next, $orientation) : int {
$aValue = ClosureExpressionVisitor::getObjectFieldValue($a, $name);
$bValue = ClosureExpressionVisitor::getObjectFieldValue($b, $name);
if ($aValue === $bValue) {
return $next($a, $b);
}
return ($aValue > $bValue ? 1 : -1) * $orientation;
};
}
/**
* {@inheritDoc}
*/
public function walkComparison(Comparison $comparison)
{
$field = $comparison->getField();
$value = $comparison->getValue()->getValue(); // shortcut for walkValue()
switch ($comparison->getOperator()) {
case Comparison::EQ:
return static function ($object) use ($field, $value) : bool {
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) === $value;
};
case Comparison::NEQ:
return static function ($object) use ($field, $value) : bool {
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) !== $value;
};
case Comparison::LT:
return static function ($object) use ($field, $value) : bool {
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) < $value;
};
case Comparison::LTE:
return static function ($object) use ($field, $value) : bool {
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) <= $value;
};
case Comparison::GT:
return static function ($object) use ($field, $value) : bool {
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) > $value;
};
case Comparison::GTE:
return static function ($object) use ($field, $value) : bool {
return ClosureExpressionVisitor::getObjectFieldValue($object, $field) >= $value;
};
case Comparison::IN:
return static function ($object) use ($field, $value) : bool {
return in_array(ClosureExpressionVisitor::getObjectFieldValue($object, $field), $value, true);
};
case Comparison::NIN:
return static function ($object) use ($field, $value) : bool {
return ! in_array(ClosureExpressionVisitor::getObjectFieldValue($object, $field), $value, true);
};
case Comparison::CONTAINS:
return static function ($object) use ($field, $value) {
return strpos(ClosureExpressionVisitor::getObjectFieldValue($object, $field), $value) !== false;
};
case Comparison::MEMBER_OF:
return static function ($object) use ($field, $value) : bool {
$fieldValues = ClosureExpressionVisitor::getObjectFieldValue($object, $field);
if (! is_array($fieldValues)) {
$fieldValues = iterator_to_array($fieldValues);
}
return in_array($value, $fieldValues, true);
};
case Comparison::STARTS_WITH:
return static function ($object) use ($field, $value) : bool {
return strpos(ClosureExpressionVisitor::getObjectFieldValue($object, $field), $value) === 0;
};
case Comparison::ENDS_WITH:
return static function ($object) use ($field, $value) : bool {
return $value === substr(ClosureExpressionVisitor::getObjectFieldValue($object, $field), -strlen($value));
};
default:
throw new RuntimeException('Unknown comparison operator: ' . $comparison->getOperator());
}
}
/**
* {@inheritDoc}
*/
public function walkValue(Value $value)
{
return $value->getValue();
}
/**
* {@inheritDoc}
*/
public function walkCompositeExpression(CompositeExpression $expr)
{
$expressionList = [];
foreach ($expr->getExpressionList() as $child) {
$expressionList[] = $this->dispatch($child);
}
switch ($expr->getType()) {
case CompositeExpression::TYPE_AND:
return $this->andExpressions($expressionList);
case CompositeExpression::TYPE_OR:
return $this->orExpressions($expressionList);
default:
throw new RuntimeException('Unknown composite ' . $expr->getType());
}
}
/**
* @param array $expressions
*/
private function andExpressions(array $expressions) : callable
{
return static function ($object) use ($expressions) : bool {
foreach ($expressions as $expression) {
if (! $expression($object)) {
return false;
}
}
return true;
};
}
/**
* @param array $expressions
*/
private function orExpressions(array $expressions) : callable
{
return static function ($object) use ($expressions) : bool {
foreach ($expressions as $expression) {
if ($expression($object)) {
return true;
}
}
return false;
};
}
}
PK yN 3 lib/Doctrine/Common/Collections/Expr/Comparison.phpnu W+A ';
public const LT = '<';
public const LTE = '<=';
public const GT = '>';
public const GTE = '>=';
public const IS = '='; // no difference with EQ
public const IN = 'IN';
public const NIN = 'NIN';
public const CONTAINS = 'CONTAINS';
public const MEMBER_OF = 'MEMBER_OF';
public const STARTS_WITH = 'STARTS_WITH';
public const ENDS_WITH = 'ENDS_WITH';
/** @var string */
private $field;
/** @var string */
private $op;
/** @var Value */
private $value;
/**
* @param string $field
* @param string $operator
* @param mixed $value
*/
public function __construct($field, $operator, $value)
{
if (! ($value instanceof Value)) {
$value = new Value($value);
}
$this->field = $field;
$this->op = $operator;
$this->value = $value;
}
/**
* @return string
*/
public function getField()
{
return $this->field;
}
/**
* @return Value
*/
public function getValue()
{
return $this->value;
}
/**
* @return string
*/
public function getOperator()
{
return $this->op;
}
/**
* {@inheritDoc}
*/
public function visit(ExpressionVisitor $visitor)
{
return $visitor->walkComparison($this);
}
}
PK yNvz : lib/Doctrine/Common/Collections/Expr/ExpressionVisitor.phpnu W+A walkComparison($expr);
case $expr instanceof Value:
return $this->walkValue($expr);
case $expr instanceof CompositeExpression:
return $this->walkCompositeExpression($expr);
default:
throw new RuntimeException('Unknown Expression ' . get_class($expr));
}
}
}
PK yNwje <