本文整理汇总了PHP中Doctrine\Common\Collections\ArrayCollection::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayCollection::exists方法的具体用法?PHP ArrayCollection::exists怎么用?PHP ArrayCollection::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Collections\ArrayCollection
的用法示例。
在下文中一共展示了ArrayCollection::exists方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sameValueAs
/**
* @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);
});
});
}
示例2: exists
public function exists(Closure $p)
{
if (null === $this->entries) {
$this->__load___();
}
return $this->entries->exists($p);
}
示例3: contextHasTransportable
/**
* @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;
});
}
示例4: canAddUser
/**
* @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;
}
示例5: isActivated
/**
* {@inheritdoc}
*/
public function isActivated()
{
return $this->activations->exists(function ($id, Activation $activation) {
return $activation->isCompleted();
});
}
示例6: testExists
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");
}
示例7: isPreviouslyLoginFailed
/**
* 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());
});
}
示例8: exists
/** {@inheritDoc} */
public function exists(Closure $p)
{
$this->initialize();
return $this->collection->exists($p);
}
示例9: inRole
/**
* {@inheritdoc}
*/
public function inRole($role)
{
return $this->roles->exists(function ($key, Role $myRole) use($role) {
return $myRole->is($role);
});
}
示例10: exists
/**
* 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);
}
示例11: saveTagging
/**
* 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();
}
}
}
示例12: exists
function exists(\Closure $p)
{
return $this->fields->exists($p);
}
示例13: saveTagging
/**
* 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();
}
}
}