/** * Get valid UserApi for given token * * @param TokenInterface $token * @param PersistentCollection $secrets * @param User $user * * @return bool|UserApi */ protected function getValidUserApi(TokenInterface $token, PersistentCollection $secrets, User $user) { $currentIteration = 0; $nonce = $token->getAttribute('nonce'); $secretsCount = $secrets->count(); /** @var UserApi $userApi */ foreach ($secrets as $userApi) { $currentIteration++; $isSecretValid = $this->validateDigest($token->getAttribute('digest'), $nonce, $token->getAttribute('created'), $userApi->getApiKey(), $this->getSalt($user)); if ($isSecretValid && !$userApi->getUser()->getOrganizations()->contains($userApi->getOrganization())) { throw new BadCredentialsException('Wrong API key.'); } if ($isSecretValid && !$userApi->getOrganization()->isEnabled()) { throw new BadCredentialsException('Organization is not active.'); } // delete nonce from cache because user have another api keys if (!$isSecretValid && $secretsCount !== $currentIteration) { $this->getNonceCache()->delete($nonce); } if ($isSecretValid) { return $userApi; } } return false; }
/** * Resets previous photo collection * * @param PersistentCollection $collection */ protected function clearPreviousCollection(PersistentCollection $collection) { if ($collection->count()) { foreach ($collection as $item) { $collection->removeElement($item); } } }
public function numberComputersAndNumberEnabled(PersistentCollection $computers) { $nbComputersEnabled = 0; foreach ($computers as $computer) { if ($computer->isEnabled()) { $nbComputersEnabled++; } } return sprintf("%d computers (%d enabled)", $computers->count(), $nbComputersEnabled); }
/** * Check that number of categories not less than minimum defined number. * * @param PersistentCollection $value * @param CategoriesConstraint $constraint * @return bool */ protected function validateCount(PersistentCollection $value, CategoriesConstraint $constraint) { if ($value->count() >= self::MIN_CATEGORIES_COUNT) { return true; } $this->context->addViolationAt($constraint->getType(), $constraint->countMessage, ['%count%' => self::MIN_CATEGORIES_COUNT]); return false; }
/** * (PHP 5 >= 5.1.0)<br/> * Returns if an iterator can be created for the current entry. * @link http://php.net/manual/en/recursiveiterator.haschildren.php * @return bool true if the current entry can be iterated over, otherwise returns false. */ public function hasChildren() { return $this->children->count() > 0; }