/** * @param mixed $item * @param CollectionInterface $collection * * @return bool */ public function __invoke($item, CollectionInterface $collection) { if (self::VALIDATE_KEY === $this->mode) { return !$collection->has($item); } return !$collection->contains($item, $this->strict); }
/** * @param CollectionInterface $from * @param CollectionInterface $to * * @return Collection */ private function getNew(CollectionInterface $from, CollectionInterface $to) { $added = []; foreach ($to as $name => $element) { if (!$from->has($name)) { $added[$name] = $element; } } return new Collection($added); }
/** * @return mixed */ public function execute() { if ($this->collection instanceof PipelineInterface) { $collection = $this->collection->execute(); if (!$collection instanceof CollectionInterface) { throw new \UnexpectedValueException('Expecting an instance of ' . CollectionInterface::class); } } else { $collection = $this->collection; } return call_user_func($this->callback, $collection); }
/** * @param string $name * * @return CollectionInterface */ public function additional($name = null) { return isset($name) ? $this->newElements->get($name) : $this->newElements; }
/** * @param integer $index * @param CollectionInterface $collection * * @return bool */ public function __invoke($index, CollectionInterface $collection) { return is_numeric($index) && $index <= $collection->count(); }