本文整理汇总了PHP中Doctrine\Common\Persistence\ObjectRepository::findBy方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectRepository::findBy方法的具体用法?PHP ObjectRepository::findBy怎么用?PHP ObjectRepository::findBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\ObjectRepository
的用法示例。
在下文中一共展示了ObjectRepository::findBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: findAll
public function findAll()
{
if (false === $this->authorizationService->isGranted('user.admin')) {
throw new UnauthorizedException('Insufficient Permissions');
}
return $this->objectRepository->findBy([], ['email' => 'ASC']);
}
示例2: getSupportedMethods
/**
* {@inheritdoc}
*/
public function getSupportedMethods(ShippingSubjectInterface $subject)
{
$methods = [];
foreach ($this->shippingMethodRepository->findBy(['enabled' => true]) as $shippingMethod) {
if ($this->eligibilityChecker->isEligible($subject, $shippingMethod)) {
$methods[] = $shippingMethod;
}
}
return $methods;
}
示例3: findAll
/**
* @return array
* @throws UnauthorizedException
*/
public function findAll()
{
if ($this->authorizationService->isGranted('recipe.admin')) {
return $this->objectRepository->findBy([], ['dateUpdated' => 'DESC']);
}
if ($this->authorizationService->isGranted('recipe.manage')) {
return $this->objectRepository->findBy(['author' => $this->authorizationService->getIdentity()], ['dateUpdated' => 'DESC']);
}
throw new UnauthorizedException('Insufficient Permission');
}
示例4: onArchetypeUpdate
/**
* @param GenericEvent $event
*/
public function onArchetypeUpdate(GenericEvent $event)
{
$archetype = $event->getSubject();
if (!$archetype instanceof ArchetypeInterface) {
throw new UnexpectedTypeException($archetype, ArchetypeInterface::class);
}
$products = $this->productRepository->findBy(array('archetype' => $archetype));
foreach ($products as $product) {
$this->builder->build($product);
$this->productManager->persist($product);
}
}
示例5: fillBackorders
/**
* {@inheritdoc}
*/
public function fillBackorders(StockableInterface $stockable)
{
$onHand = $stockable->getOnHand();
if ($onHand <= 0) {
return;
}
$units = $this->repository->findBy(array('stockable' => $stockable, 'inventoryState' => InventoryUnitInterface::STATE_BACKORDERED), array('createdAt' => 'ASC'));
foreach ($units as $unit) {
$unit->setInventoryState(InventoryUnitInterface::STATE_SOLD);
if (--$onHand === 0) {
break;
}
}
$stockable->setOnHand($onHand);
}
示例6: getZones
/**
* Gets all zones
*
* @param string|null $scope
*
* @return array $zones
*/
protected function getZones($scope = null)
{
if (null === $scope) {
return $this->repository->findAll();
}
return $this->repository->findBy(array('scope' => $scope));
}
示例7:
function it_should_index_entity(ManagerRegistry $registry, EntityManager $em, ObjectRepository $repo)
{
$repo->findBy([], ['id' => 'DESC'], 1, 2)->willReturn([1, 2, 3]);
$em->getRepository('foo')->willReturn($repo);
$registry->getManager(null)->willReturn($em);
$this->setRegistry($registry);
$this->index(1, 2, 'id', 'DESC')->shouldBe([1, 2, 3]);
}
示例8: getNonAppliedAutomaticCoupons
/**
* Get current cart automatic coupons.
*
* @param CartInterface $cart Cart
*
* @returns CouponInterface[] Array of non applied coupons
*/
private function getNonAppliedAutomaticCoupons(CartInterface $cart)
{
$automaticCoupons = $this->couponRepository->findBy(['enforcement' => ElcodiCouponTypes::ENFORCEMENT_AUTOMATIC]);
$loadedAutomaticCoupons = $this->cartCouponManager->getCoupons($cart);
return array_udiff($automaticCoupons, $loadedAutomaticCoupons, function (CouponInterface $a, CouponInterface $b) {
return $a->getId() != $b->getId();
});
}
示例9: array
function it_does_reverse_transform_identifiers_to_array_of_entities(ObjectRepository $repository, FakeEntity $entityOne, FakeEntity $entityTwo)
{
$value = array(1, 2);
$entityOne->getId()->willReturn(1);
$entityTwo->getId()->willReturn(2);
$repository->findBy(array('id' => $value))->shouldBeCalled()->willReturn(array($entityOne, $entityTwo));
$this->reverseTransform($value)->shouldReturn(array($entityOne, $entityTwo));
}
示例10: tryAutomaticCoupons
/**
* Method subscribed to PreCartLoad event
*
* Iterate over all automatic Coupons and check if they apply.
* If any applies, it will be added to the Cart
*
* @param CartOnLoadEvent $event Event
*
* @return null
*/
public function tryAutomaticCoupons(CartOnLoadEvent $event)
{
$cart = $event->getCart();
if ($cart->getCartLines()->isEmpty()) {
return null;
}
/**
* @var CouponInterface[] $automaticCoupons
*/
$automaticCoupons = $this->couponRepository->findBy(['enforcement' => ElcodiCouponTypes::ENFORCEMENT_AUTOMATIC]);
foreach ($automaticCoupons as $coupon) {
try {
$this->cartCouponManager->addCoupon($cart, $coupon);
} catch (AbstractCouponException $e) {
// Silently tries next coupon on controlled exception
}
}
}
示例11:
function it_returns_all_methods_eligible_for_given_subject(ObjectRepository $methodRepository, ShippingMethodEligibilityCheckerInterface $eligibilityChecker, ShippingSubjectInterface $subject, ShippingMethodInterface $method1, ShippingMethodInterface $method2, ShippingMethodInterface $method3)
{
$methods = [$method1, $method2, $method3];
$methodRepository->findBy(['enabled' => true])->shouldBeCalled()->willReturn($methods);
$eligibilityChecker->isEligible($subject, $method1)->shouldBeCalled()->willReturn(true);
$eligibilityChecker->isEligible($subject, $method2)->shouldBeCalled()->willReturn(true);
$eligibilityChecker->isEligible($subject, $method3)->shouldBeCalled()->willReturn(false);
$this->getSupportedMethods($subject)->shouldReturn([$method1, $method2]);
}
示例12:
function it_partially_fills_backordered_units_and_updates_stock_accordingly(StockableInterface $stockable, InventoryUnitInterface $inventoryUnit1, InventoryUnitInterface $inventoryUnit2, ObjectRepository $repository)
{
$stockable->getOnHand()->shouldBeCalled()->willReturn(5);
$stockable->setOnHand(3)->shouldBeCalled();
$inventoryUnit1->setInventoryState(InventoryUnitInterface::STATE_SOLD)->shouldBeCalled();
$inventoryUnit2->setInventoryState(InventoryUnitInterface::STATE_SOLD)->shouldBeCalled();
$repository->findBy(['stockable' => $stockable, 'inventoryState' => InventoryUnitInterface::STATE_BACKORDERED], ['createdAt' => 'ASC'])->willReturn([$inventoryUnit1, $inventoryUnit2]);
$this->fillBackorders($stockable);
}
示例13:
function it_schedules_owning_document_for_update_when_setting_element_by_key_in_the_collection(MongoDBODMUnitOfWork $uow, DocumentStub $document, ObjectRepository $repository, ClassMetadata $classMetadata, EntityStub $entity4, EntityStub $entity8, EntityStub $entity15, EntityStub $newEntity)
{
$classMetadata->getIdentifier()->willReturn(['id']);
$repository->findBy(['id' => [4, 8, 15]])->willReturn([$entity4, $entity8, $entity15]);
$uow->getDocumentState($document)->willReturn(MongoDBODMUnitOfWork::STATE_MANAGED);
$uow->isScheduledForUpdate($document)->willReturn(false);
$uow->scheduleForUpdate($document)->shouldBeCalled();
$this->setOwner($document);
$this->set(2, $newEntity);
}
示例14: getRoles
/**
* {@inheritDoc}
*/
public function getRoles(array $roleNames)
{
$key = implode($roleNames);
if (isset($this->roleCache[$key])) {
return $this->roleCache[$key];
}
$roles = $this->objectRepository->findBy([$this->roleNameProperty => $roleNames]);
// We allow more roles to be loaded than asked (although this should not happen because
// role name should have a UNIQUE constraint in database... but just in case ;))
if (count($roles) >= count($roleNames)) {
$this->roleCache[$key] = $roles;
return $roles;
}
// We have roles that were asked but couldn't be found in database... problem!
foreach ($roles as &$role) {
$role = $role->getName();
}
throw new RoleNotFoundException(sprintf('Some roles were asked but could not be loaded from database: %s', implode(', ', array_diff($roleNames, $roles))));
}
示例15:
function it_updates_products_with_newer_attributes_added_to_their_archetypes(GenericEvent $event, ArchetypeInterface $archetype, ArchetypeBuilderInterface $builder, ObjectRepository $productRepository, ObjectManager $productManager, ProductInterface $productA, ProductInterface $productB)
{
$event->getSubject()->willReturn($archetype);
$productRepository->findBy(array('archetype' => $archetype))->willReturn(array($productA, $productB));
$builder->build($productA)->shouldBeCalled();
$builder->build($productB)->shouldBeCalled();
$productManager->persist($productA)->shouldBeCalled();
$productManager->persist($productB)->shouldBeCalled();
$this->onArchetypeUpdate($event);
}