本文整理汇总了PHP中Doctrine\ORM\PersistentCollection::count方法的典型用法代码示例。如果您正苦于以下问题:PHP PersistentCollection::count方法的具体用法?PHP PersistentCollection::count怎么用?PHP PersistentCollection::count使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ORM\PersistentCollection
的用法示例。
在下文中一共展示了PersistentCollection::count方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getValidUserApi
/**
* 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;
}
示例2: clearPreviousCollection
/**
* Resets previous photo collection
*
* @param PersistentCollection $collection
*/
protected function clearPreviousCollection(PersistentCollection $collection)
{
if ($collection->count()) {
foreach ($collection as $item) {
$collection->removeElement($item);
}
}
}
示例3: numberComputersAndNumberEnabled
public function numberComputersAndNumberEnabled(PersistentCollection $computers)
{
$nbComputersEnabled = 0;
foreach ($computers as $computer) {
if ($computer->isEnabled()) {
$nbComputersEnabled++;
}
}
return sprintf("%d computers (%d enabled)", $computers->count(), $nbComputersEnabled);
}
示例4: validateCount
/**
* 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;
}
示例5: hasChildren
/**
* (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;
}