Doctrine\Common\Collections\ArrayCollection::exists PHP Méthode

exists() public méthode

{@inheritDoc}
public exists ( Closure $p )
$p Closure
    public function exists(Closure $p)
    {
        foreach ($this->elements as $key => $element) {
            if ($p($key, $element)) {
                return true;
            }
        }
        return false;
    }

Usage Example

 /**
  * @param Itinerary $other
  * @return bool
  */
 public function sameValueAs(Itinerary $other) : bool
 {
     //We use doctrine's ArrayCollection only to ease comparison
     //If Legs would be stored in an ArrayCollection hole the time
     //Itinerary itself would not be immutable,
     //cause a client could call $itinerary->legs()->add($anotherLeg);
     //Keeping ValueObjects immutable is a rule of thumb
     $myLegs = new ArrayCollection($this->legs());
     $otherLegs = new ArrayCollection($other->legs());
     if ($myLegs->count() !== $otherLegs->count()) {
         return false;
     }
     return $myLegs->forAll(function ($index, Leg $leg) use($otherLegs) {
         return $otherLegs->exists(function ($otherIndex, Leg $otherLeg) use($leg) {
             return $otherLeg->sameValueAs($leg);
         });
     });
 }
All Usage Examples Of Doctrine\Common\Collections\ArrayCollection::exists