exists() public method

{@inheritDoc}
public exists ( Closure $p )
$p Closure
Ejemplo n.º 1
1
 /**
  * @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);
         });
     });
 }
 public function exists(Closure $p)
 {
     if (null === $this->entries) {
         $this->__load___();
     }
     return $this->entries->exists($p);
 }
Ejemplo n.º 3
0
 /**
  * @param TransportableInterface $transportable
  * @return bool
  */
 protected function contextHasTransportable(TransportableInterface $transportable)
 {
     return $this->context->exists(function ($k, $v) use($transportable) {
         /** @var TransportableInterface $v */
         return $transportable === $v;
     });
 }
Ejemplo n.º 4
0
 /**
  * @param User $user
  *
  * @return bool
  */
 protected function canAddUser(User $user)
 {
     $foundUser = $this->taUsers->exists(function ($key, $element) use($user) {
         return $user->getUsername() == $element->getUsername();
     });
     return $foundUser == false;
 }
Ejemplo n.º 5
0
 /**
  * {@inheritdoc}
  */
 public function isActivated()
 {
     return $this->activations->exists(function ($id, Activation $activation) {
         return $activation->isCompleted();
     });
 }
Ejemplo n.º 6
0
 public function testExists()
 {
     $elements = array(1, 'A' => 'a', 2, 'null' => null, 3, 'A2' => 'a', 'zero' => 0);
     $collection = new ArrayCollection($elements);
     $this->assertTrue($collection->exists(function ($key, $element) {
         return $key == 'A' && $element == 'a';
     }), "Element exists");
     $this->assertFalse($collection->exists(function ($key, $element) {
         return $key == 'non-existent' && $element == 'non-existent';
     }), "Element not exists");
 }
Ejemplo n.º 7
0
 /**
  * Checks if the auth failed previously.
  *
  * @param string             $diff
  * @param bool               $ignoreLastAttempts
  * @param DateTimeComparison $comparison
  *
  * @return bool
  */
 private function isPreviouslyLoginFailed(string $diff, DateTimeComparison $comparison, bool $ignoreLastAttempts = false) : bool
 {
     return $this->failedAuthentications->exists(function (int $index, AuthenticationAttempt $failedAttempt) use($diff, $ignoreLastAttempts, $comparison) {
         $ipRange = $failedAttempt->getLastFailedAttemptTimesInRange();
         return $comparison($diff, $failedAttempt->getIp() && $ignoreLastAttempts ? end($ipRange) : $failedAttempt->getLatestFailedAttemptTime());
     });
 }
Ejemplo n.º 8
0
 /** {@inheritDoc} */
 public function exists(Closure $p)
 {
     $this->initialize();
     return $this->collection->exists($p);
 }
Ejemplo n.º 9
0
 /**
  * {@inheritdoc}
  */
 public function inRole($role)
 {
     return $this->roles->exists(function ($key, Role $myRole) use($role) {
         return $myRole->is($role);
     });
 }
Ejemplo n.º 10
0
 /**
  * Tests for the existence of an element that satisfies the given predicate.
  *
  * @param Closure $p The predicate.
  *
  * @return boolean TRUE if the predicate is TRUE for at least one element, FALSE otherwise.
  */
 public function exists(Closure $p)
 {
     return $this->collection->exists($p);
 }
Ejemplo n.º 11
0
 /**
  * Saves tags for the given taggable resource
  *
  * @param Taggable $resource Taggable resource
  * @param  bool $flush Whether to flush the changes (default true)
  */
 public function saveTagging(Taggable $resource, $flush = true)
 {
     $oldTags = $this->getTagging($resource, $this->getUser()->getId());
     $newTags = $resource->getTags();
     if (isset($newTags['all'], $newTags['owner'])) {
         $newOwnerTags = new ArrayCollection($newTags['owner']);
         $newAllTags = new ArrayCollection($newTags['all']);
         $manager = $this;
         $tagsToAdd = $newOwnerTags->filter(function ($tag) use($oldTags, $manager) {
             return !$oldTags->exists($manager->compareCallback($tag));
         });
         $tagsToDelete = $oldTags->filter(function ($tag) use($newOwnerTags, $manager) {
             return !$newOwnerTags->exists($manager->compareCallback($tag));
         });
         if (!$tagsToDelete->isEmpty() && $this->securityFacade->isGranted(self::ACL_RESOURCE_ASSIGN_ID_KEY)) {
             $this->deleteTaggingByParams($tagsToDelete, ClassUtils::getClass($resource), $resource->getTaggableId(), $this->getUser()->getId());
         }
         // process if current user allowed to remove other's tag links
         if ($this->securityFacade->isGranted(self::ACL_RESOURCE_REMOVE_ID_KEY)) {
             // get 'not mine' taggings
             $oldTags = $this->getTagging($resource, $this->getUser()->getId(), true);
             $tagsToDelete = $oldTags->filter(function ($tag) use($newAllTags, $manager) {
                 return !$newAllTags->exists($manager->compareCallback($tag));
             });
             if (!$tagsToDelete->isEmpty()) {
                 $this->deleteTaggingByParams($tagsToDelete, ClassUtils::getClass($resource), $resource->getTaggableId());
             }
         }
         foreach ($tagsToAdd as $tag) {
             if (!$this->securityFacade->isGranted(self::ACL_RESOURCE_ASSIGN_ID_KEY) || !$this->securityFacade->isGranted(self::ACL_RESOURCE_CREATE_ID_KEY) && !$tag->getId()) {
                 // skip tags that have not ID because user not granted to create tags
                 continue;
             }
             $this->em->persist($tag);
             $alias = $this->mapper->getEntityConfig(ClassUtils::getClass($resource));
             $tagging = $this->createTagging($tag, $resource)->setAlias($alias['alias']);
             $this->em->persist($tagging);
         }
         if (!$tagsToAdd->isEmpty() && $flush) {
             $this->em->flush();
         }
     }
 }
 function exists(\Closure $p)
 {
     return $this->fields->exists($p);
 }
Ejemplo n.º 13
0
 /**
  * Saves tags for the given taggable resource
  *
  * @param Taggable $resource Taggable resource
  * @param bool $flush Whether to flush the changes (default true)
  * @param Organization $organization Current one if not specified
  */
 public function saveTagging(Taggable $resource, $flush = true, Organization $organization = null)
 {
     $createdBy = $this->getUser() ? $this->getUser()->getId() : null;
     $oldTags = $this->getTagging($resource, $createdBy, false, $organization);
     $newTags = $resource->getTags();
     if (isset($newTags['all'], $newTags['owner'])) {
         $newOwnerTags = new ArrayCollection($newTags['owner']);
         $newAllTags = new ArrayCollection($newTags['all']);
         $manager = $this;
         $tagsToAdd = $newOwnerTags->filter(function ($tag) use($oldTags, $manager) {
             return !$oldTags->exists($manager->compareCallback($tag));
         });
         $tagsToDelete = $oldTags->filter(function ($tag) use($newOwnerTags, $manager) {
             return !$newOwnerTags->exists($manager->compareCallback($tag));
         });
         if (!$tagsToDelete->isEmpty() && $this->securityFacade->isGranted(self::ACL_RESOURCE_ASSIGN_ID_KEY)) {
             $this->deleteTaggingByParams($tagsToDelete, ClassUtils::getClass($resource), $resource->getTaggableId(), $this->getUser()->getId());
         }
         // process if current user allowed to remove other's tag links
         if (!$this->getUser() || $this->securityFacade->isGranted(self::ACL_RESOURCE_REMOVE_ID_KEY)) {
             // get 'not mine' taggings
             $oldTags = $this->getTagging($resource, $createdBy, true, $organization);
             $tagsToDelete = $oldTags->filter(function ($tag) use($newAllTags, $manager) {
                 return !$newAllTags->exists($manager->compareCallback($tag));
             });
             if (!$tagsToDelete->isEmpty()) {
                 $this->deleteTaggingByParams($tagsToDelete, ClassUtils::getClass($resource), $resource->getTaggableId());
             }
         }
         $this->persistTags($resource, $tagsToAdd);
         if (!$tagsToAdd->isEmpty() && $flush) {
             $this->em->flush();
         }
     }
 }