當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。