当前位置: 首页>>代码示例>>PHP>>正文


PHP ObjectRepository::findOneBy方法代码示例

本文整理汇总了PHP中Doctrine\Common\Persistence\ObjectRepository::findOneBy方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectRepository::findOneBy方法的具体用法?PHP ObjectRepository::findOneBy怎么用?PHP ObjectRepository::findOneBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Doctrine\Common\Persistence\ObjectRepository的用法示例。


在下文中一共展示了ObjectRepository::findOneBy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: createAddress

 /**
  * @param $data
  * @return AbstractDefaultTypedAddress
  */
 protected function createAddress($data)
 {
     /** @var Country $country */
     $country = $this->countryRepository->findOneBy(['iso2Code' => $data['country']]);
     if (!$country) {
         throw new \RuntimeException('Can\'t find country with ISO ' . $data['country']);
     }
     /** @var Region $region */
     $region = $this->regionRepository->findOneBy(['country' => $country, 'code' => $data['state']]);
     if (!$region) {
         throw new \RuntimeException(printf('Can\'t find region with country ISO %s and code %s', $data['country'], $data['state']));
     }
     $types = [];
     $typesFromData = explode(',', $data['types']);
     foreach ($typesFromData as $type) {
         $types[] = $this->addressTypeRepository->find($type);
     }
     $defaultTypes = [];
     $defaultTypesFromData = explode(',', $data['defaultTypes']);
     foreach ($defaultTypesFromData as $defaultType) {
         $defaultTypes[] = $this->addressTypeRepository->find($defaultType);
     }
     $address = $this->getNewAddressEntity();
     $address->setTypes(new ArrayCollection($types));
     $address->setDefaults(new ArrayCollection($defaultTypes))->setPrimary(true)->setLabel('Primary address')->setCountry($country)->setStreet($data['street'])->setCity($data['city'])->setRegion($region)->setPostalCode($data['zipCode']);
     return $address;
 }
开发者ID:adam-paterson,项目名称:orocommerce,代码行数:31,代码来源:AbstractLoadAddressDemoData.php

示例2: checkDuplicity

 private function checkDuplicity(Category $category)
 {
     $duplicate = $this->repository->findOneBy(['path' => $category->getPath()]);
     if ($duplicate !== null) {
         throw new EntityDuplicateException(sprintf('Category with path %s already exists.', $category->getPath()));
     }
 }
开发者ID:shophp,项目名称:shophp,代码行数:7,代码来源:CategoryService.php

示例3: checkDuplicity

 private function checkDuplicity(User $user)
 {
     $duplicate = $this->repository->findOneBy(['email' => $user->getEmail()]);
     if ($duplicate !== null) {
         throw new EntityDuplicateException(sprintf('User with e-mail %s already exists.', $user->getEmail()));
     }
 }
开发者ID:shophp,项目名称:shophp,代码行数:7,代码来源:UserService.php

示例4: tryGetMRByCode

 /**
  * Try to get from local property if exist or load from database afterwards
  *
  * @param string $code
  *
  * @return Region|Null
  */
 protected function tryGetMRByCode($code)
 {
     if (!isset($this->MRIdentityMap[$code]) && !array_key_exists($code, $this->MRIdentityMap)) {
         $this->MRIdentityMap[$code] = $this->repository->findOneBy(['combinedCode' => $code]);
     }
     return $this->MRIdentityMap[$code];
 }
开发者ID:dairdr,项目名称:crm,代码行数:14,代码来源:RegionConverter.php

示例5: Place

    function it_converts_node_to_street_entry_with_updating_existing_one(ObjectManager $om, ObjectRepository $or, Street $street)
    {
        $xml = <<<EOT
<row>
    <col name="WOJ">02</col>
    <col name="POW">23</col>
    <col name="GMI">09</col>
    <col name="RODZ_GMI">2</col>
    <col name="SYM">0884849</col>
    <col name="SYM_UL">10268</col>
    <col name="CECHA">ul.</col>
    <col name="NAZWA_1">Księżycowa </col>
    <col name="NAZWA_2"/>
    <col name="STAN_NA">2013-10-10</col>
</row>
EOT;
        $place = new Place(884849);
        $place->setName('City');
        $or->findOneBy(array('id' => '0884849'))->shouldBeCalled()->willReturn($place);
        $or->findOneBy(array('id' => '10268', 'place' => $place))->shouldBeCalled()->willReturn($street);
        $street->setName('Księżycowa')->shouldBeCalled()->willReturn($street);
        $street->setAdditionalName('')->shouldBeCalled()->willReturn($street);
        $street->setType('ul.')->shouldBeCalled()->willReturn($street);
        $this->beConstructedWith(new \SimpleXMLElement($xml), $om);
        $this->convertToEntity()->shouldBeLike($street->getWrappedObject());
    }
开发者ID:jacdobro,项目名称:teryt-database-bundle,代码行数:26,代码来源:StreetsNodeConverterSpec.php

示例6: getUserByUsername

 /**
  * @param $username
  * @return \AppBundle\Entity\User
  * @throws UserNotFoundException
  */
 public function getUserByUsername($username)
 {
     $user = $this->userRepository->findOneBy(array('username' => $username));
     if ($user === null) {
         throw new UserNotFoundException();
     }
     return $user;
 }
开发者ID:sfarkas1988,项目名称:timekeepingAPI,代码行数:13,代码来源:UserService.php

示例7: Isbn

 function it_searches_book_by_isbn_number(BookInterface $book, ObjectRepository $doctrineRepository)
 {
     $isbn = new Isbn('978-1-56619-909-4');
     $doctrineRepository->findOneBy(array('isbn.number' => $isbn))->willReturn($book);
     $this->searchByIsbn($isbn)->shouldBeLike(SearchResults::fromArrayOfBooks(array($book->getWrappedObject())));
     $doctrineRepository->findOneBy(array('isbn.number' => $isbn))->willReturn(null);
     $this->searchByIsbn($isbn)->shouldBeLike(SearchResults::asEmpty());
 }
开发者ID:pjedrzejewski,项目名称:phpbenelux-2016-modelling-by-example,代码行数:8,代码来源:DoctrineLibrarySpec.php

示例8: findModuleByIdentity

 /**
  * {@inheritdoc}
  *
  * @throws \RuntimeException if the identifier is not set
  */
 public function findModuleByIdentity($identity)
 {
     $field = $this->getModularIdentifier();
     if (null == $field) {
         throw new \RuntimeException('The module manager is missing a modular identifier.');
     }
     return $this->repository->findOneBy([$field => $identity]);
 }
开发者ID:harmony-project,项目名称:modular-routing,代码行数:13,代码来源:DoctrineModuleManager.php

示例9: findFromToRate

 /**
  * This is used to return a from to rate and is used in the cron section
  * @param $fromCurrency
  * @param $toCurrency
  * @return null|object
  */
 public function findFromToRate($fromCurrency, $toCurrency)
 {
     //Check if the rate exists
     $exRateObject = $this->exRateRepository->findOneBy(array('fromCurrency' => $fromCurrency, 'toCurrency' => $toCurrency));
     if (!$exRateObject instanceof ExchangeRate) {
         return null;
     }
     return $exRateObject;
 }
开发者ID:chateaux,项目名称:toolbox,代码行数:15,代码来源:ExchangeRateService.php

示例10: getProductsByCategoryName

 /**
  * @param $categoryName
  * @return Category
  */
 public function getProductsByCategoryName($categoryName)
 {
     try {
         $category = $this->repository->findOneBy(['name' => $categoryName, 'isActive' => 1]);
     } catch (\Exception $e) {
         $category = new Category(self::CATEGORY_NOT_FOUND);
     }
     return $category;
 }
开发者ID:dev-learning,项目名称:symfony,代码行数:13,代码来源:CategoryService.php

示例11: transform

 /**
  * {@inheritdoc}
  */
 public function transform($value)
 {
     if (!$value) {
         return null;
     }
     if (null === ($entity = $this->repository->findOneBy(array($this->identifier => $value)))) {
         throw new TransformationFailedException(sprintf('Object "%s" with identifier "%s"="%s" does not exist.', $this->repository->getClassName(), $this->identifier, $value));
     }
     return $entity;
 }
开发者ID:bcremer,项目名称:Sylius,代码行数:13,代码来源:ObjectToIdentifierTransformer.php

示例12: release

 public function release($name)
 {
     $nameWithPrefix = $this->getNameWithPrefix($name);
     $lock = $this->repository->findOneBy(['name' => $nameWithPrefix]);
     if ($lock) {
         $this->objectManager->remove($lock);
         $this->objectManager->flush();
         return true;
     }
     return false;
 }
开发者ID:aboutcoders,项目名称:resource-lock-bundle,代码行数:11,代码来源:LockManager.php

示例13: createUserIdentity

 public function createUserIdentity($user)
 {
     list($className, $identifier) = $this->extractUserIdentityFields($user);
     if (isset($this->userCache[$className][$identifier])) {
         return $this->userCache[$className][$identifier];
     }
     if (null !== ($this->userCache[$className][$identifier] = $this->userRepository->findOneBy(array('class' => $className, 'identifier' => $identifier)))) {
         return $this->userCache[$className][$identifier];
     }
     $userClass = $this->userRepository->getClassName();
     return $this->userCache[$className][$identifier] = new $userClass($className, $identifier);
 }
开发者ID:senthilkumar3282,项目名称:symfony-acl-bundle,代码行数:12,代码来源:SecurityIdentityFactory.php

示例14: findByName

 /**
  * @param string $name
  * @return object
  */
 private function findByName($name)
 {
     $sequence = $this->repository->findOneBy(array('name' => $name));
     if (!$sequence) {
         $sequence = new $this->class();
         $sequence->setName($name);
         $sequence->setCurrentValue(0);
         $this->objectManager->persist($sequence);
         $this->objectManager->flush();
     }
     return $sequence;
 }
开发者ID:aboutcoders,项目名称:sequence-bundle,代码行数:16,代码来源:SequenceManager.php

示例15: validate

 /**
  * {@inheritdoc}
  */
 public function validate($value, Constraint $constraint)
 {
     if (!$value instanceof ProductInterface) {
         throw new UnexpectedTypeException($value, ProductInterface::class);
     }
     $product = $value;
     $accessor = PropertyAccess::createPropertyAccessor();
     $criteria = array($constraint->property => $accessor->getValue($product, $constraint->property));
     $conflictualProduct = $this->repository->findOneBy($criteria);
     if (null !== $conflictualProduct && $conflictualProduct != $product) {
         $this->context->addViolationAt($constraint->property, $constraint->message, array('%property%' => $constraint->property));
     }
 }
开发者ID:Silwereth,项目名称:Sylius,代码行数:16,代码来源:ProductUniqueValidator.php


注:本文中的Doctrine\Common\Persistence\ObjectRepository::findOneBy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。