當前位置: 首頁>>代碼示例>>PHP>>正文


PHP EntityRepository::findOneBy方法代碼示例

本文整理匯總了PHP中Doctrine\ORM\EntityRepository::findOneBy方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityRepository::findOneBy方法的具體用法?PHP EntityRepository::findOneBy怎麽用?PHP EntityRepository::findOneBy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Doctrine\ORM\EntityRepository的用法示例。


在下文中一共展示了EntityRepository::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: validateAttribute

 /**
  * @inheritdoc
  */
 public function validateAttribute($model, $attribute)
 {
     $targetAttribute = $this->targetAttribute === null ? $attribute : $this->targetAttribute;
     $findResult = $this->repository->findOneBy([$targetAttribute => $model->{$attribute}]);
     if ($findResult === null) {
         $this->addError($model, $attribute, $this->message);
     }
 }
開發者ID:iw-reload,項目名稱:iw,代碼行數:11,代碼來源:ExistValidator.php

示例3: load

 public function load(ObjectManager $manager)
 {
     $organization = $this->getReference('default_organization');
     /** @var \Oro\Bundle\UserBundle\Entity\Role $marketingRole */
     $marketingRole = $this->roles->findOneBy(array('role' => 'ROLE_MARKETING_MANAGER'));
     /** @var \Oro\Bundle\UserBundle\Entity\Role $saleRole */
     $saleRole = $this->roles->findOneBy(array('role' => LoadRolesData::ROLE_MANAGER));
     /** @var \Oro\Bundle\UserBundle\Entity\Group $salesGroup */
     $salesGroup = $this->group->findOneBy(array('name' => 'Executive Sales'));
     /** @var \Oro\Bundle\UserBundle\Entity\Group $marketingGroup */
     $marketingGroup = $this->group->findOneBy(array('name' => 'Executive Marketing'));
     /** @var \Oro\Bundle\UserBundle\Entity\UserManager $userManager */
     $userManager = $this->container->get('oro_user.manager');
     $sale = $userManager->createUser();
     $sale->setUsername('sale')->setPlainPassword('sale')->setFirstName('Ellen')->setLastName('Rowell')->addRole($saleRole)->addGroup($salesGroup)->setEmail('sale@example.com')->setOrganization($organization)->addOrganization($organization)->setBusinessUnits(new ArrayCollection(array($this->getBusinessUnit($manager, 'Acme, General'), $this->getBusinessUnit($manager, 'Acme, East'), $this->getBusinessUnit($manager, 'Acme, West'))));
     if ($this->hasReference('default_main_business')) {
         $sale->setOwner($this->getBusinessUnit($manager, 'Acme, General'));
     }
     $this->addReference('default_sale', $sale);
     $userManager->updateUser($sale);
     /** @var \Oro\Bundle\UserBundle\Entity\User $marketing */
     $marketing = $userManager->createUser();
     $marketing->setUsername('marketing')->setPlainPassword('marketing')->setFirstName('Michael')->setLastName('Buckley')->addRole($marketingRole)->addGroup($marketingGroup)->setEmail('marketing@example.com')->setOrganization($organization)->addOrganization($organization)->setBusinessUnits(new ArrayCollection(array($this->getBusinessUnit($manager, 'Acme, General'), $this->getBusinessUnit($manager, 'Acme, East'), $this->getBusinessUnit($manager, 'Acme, West'))));
     if ($this->hasReference('default_main_business')) {
         $marketing->setOwner($this->getBusinessUnit($manager, 'Acme, General'));
     }
     $this->addReference('default_marketing', $marketing);
     $userManager->updateUser($marketing);
 }
開發者ID:antrampa,項目名稱:crm,代碼行數:29,代碼來源:LoadUserData.php

示例4: authenticate

 /**
  * Attempts to authenticate a GrantToken
  *
  * @param GrantToken $token
  *
  * @return GrantToken
  *
  * @throws AuthenticationException
  */
 public function authenticate(TokenInterface $token)
 {
     $credentials = $token->getCredentials();
     $clientId = $credentials['client_id'];
     /** @var ClientInterface $client */
     $client = $this->clientRepository->find($clientId);
     // Verify client id
     if (!$client) {
         throw new AuthenticationException("Client with id {$clientId} does not exist");
     }
     // Verify client secret
     $clientSecret = $credentials['client_secret'];
     if (!$client->getSecret() === $clientSecret) {
         throw new AuthenticationException("Invalid client secret");
     }
     // Verify grant type
     if (!in_array($token->getGrantType(), $client->getAllowedGrantTypes())) {
         throw new AuthenticationException("Grant type not allowed");
     }
     // Verify refresh_token
     $refreshToken = $this->refreshTokenRepository->findOneBy(["token" => $credentials['refresh_token'], "client" => $client]);
     if ($refreshToken === null) {
         throw new AuthenticationException("Invalid token");
     }
     // Verify expiry date
     if ($refreshToken->isExpired()) {
         throw new AuthenticationException("Token has expired");
     }
     $user = $refreshToken->getUser();
     $token->setUser($user);
     $token->setClient($client);
     return $token;
 }
開發者ID:koenreiniers,項目名稱:oauth-server-bundle,代碼行數:42,代碼來源:RefreshTokenProvider.php

示例5: load

 /**
  * {@inheritDoc}
  */
 public function load(ObjectManager $manager)
 {
     /** @var Organization $organization */
     $organization = $this->organizationRepository->getFirst();
     $this->addReference('default_organization', $organization);
     /** @var BusinessUnit $oroMain */
     $oroMain = $this->businessUnitRepository->findOneBy(array('name' => 'Main'));
     if (!$oroMain) {
         $oroMain = $this->businessUnitRepository->findOneBy(array('name' => 'Acme, General'));
     }
     if (!$oroMain) {
         throw new \Exception('"Main" business unit is not defined');
     }
     $oroMain->setName('Acme, General');
     $oroMain->setEmail('general@acme.inc');
     $oroMain->setPhone('798-682-5917');
     $this->persistAndFlush($this->organizationManager, $oroMain);
     $this->addReference('default_main_business', $oroMain);
     /** @var BusinessUnit $oroUnit */
     $oroUnit = new BusinessUnit();
     /** @var BusinessUnit $mageCoreUnit */
     $mageCoreUnit = new BusinessUnit();
     $oroUnit->setName('Acme, West')->setWebsite('http://www.orocrm.com')->setOrganization($organization)->setEmail('west@acme.inc')->setPhone('798-682-5918')->setOwner($oroMain);
     $this->persist($this->organizationManager, $oroUnit);
     $this->addReference('default_crm_business', $oroUnit);
     $mageCoreUnit->setName('Acme, East')->setWebsite('http://www.magecore.com/')->setOrganization($organization)->setEmail('east@acme.inc')->setPhone('798-682-5919')->setOwner($oroMain);
     $this->persistAndFlush($this->organizationManager, $mageCoreUnit);
     $this->addReference('default_core_business', $mageCoreUnit);
 }
開發者ID:antrampa,項目名稱:crm,代碼行數:32,代碼來源:LoadBusinessUnitData.php

示例6: createTicket

 protected function createTicket($iterator, $reporter, $assignee)
 {
     /** @var \Diamante\DeskBundle\Entity\Branch $branch */
     $branch = $this->branchRepository->findOneBy(array('name' => 'branchName' . $iterator));
     $ticket = new Ticket(UniqueId::generate(), new TicketSequenceNumber(null), 'ticketSubject' . $iterator, 'ticketDescription' . $iterator, $branch, $reporter, $assignee, new Source(Source::PHONE), new Priority(Priority::PRIORITY_MEDIUM), new Status(Status::OPEN));
     return $ticket;
 }
開發者ID:gitter-badger,項目名稱:diamantedesk-application,代碼行數:7,代碼來源:LoadTicketData.php

示例7: findUserByDeviceToken

 /**
  * @param $deviceToken
  * @return null|int
  */
 public function findUserByDeviceToken($deviceToken)
 {
     if (null !== ($device = $this->repository->findOneBy(['deviceToken' => $deviceToken]))) {
         return $device->getUserId();
     }
     return null;
 }
開發者ID:nnmer,項目名稱:push-notification-bundle,代碼行數:11,代碼來源:DeviceService.php

示例8: getNewInstance

 public function getNewInstance()
 {
     $instance = parent::getNewInstance();
     /* @var $instance Employee */
     $instance->getProjects()->add($this->projectRepo->findOneBy(['isInternal' => true]));
     return $instance;
 }
開發者ID:bOmBeLq,項目名稱:polcode,代碼行數:7,代碼來源:EmployeeAdmin.php

示例9: findByOAuthResponse

 /**
  * @return User
  * @throws InvalidArgumentException if no user is found
  */
 public function findByOAuthResponse(UserResponseInterface $oAuthResponse)
 {
     $foundUser = $this->doctrineUserRepo->findOneBy(['oAuthProviderClass' => get_class($oAuthResponse->getResourceOwner()), 'oAuthId' => $oAuthResponse->getUsername()]);
     if (null === $foundUser) {
         throw new \InvalidArgumentException("user not found");
     }
     return $foundUser;
 }
開發者ID:lukaszmakuch,項目名稱:question-sheet-storage,代碼行數:12,代碼來源:UserRepo.php

示例10: findItemByName

 protected function findItemByName($name)
 {
     $item = $this->items->findOneBy(['name' => $name]);
     if (null === $item) {
         throw new \InvalidArgumentException(sprintf('Item with name %s does not exist.', $name));
     }
     return $item;
 }
開發者ID:lzakrzewski,項目名稱:tests-with-database-examples,代碼行數:8,代碼來源:TestCase.php

示例11: acceptInvitation

 /**
  * @param InvitationInterface $invitation
  *
  * @return \Tahoe\Bundle\MultiTenancyBundle\Entity\TenantUser
  */
 public function acceptInvitation(InvitationInterface $invitation)
 {
     $user = $this->userRepository->findOneBy(array('emailCanonical' => $invitation->getEmail()));
     $tenant = $invitation->getTenant();
     $tenantUser = $this->tenantUserHandler->addUserToTenant($user, $tenant);
     $this->entityManager->flush();
     $this->delete($invitation, true);
     return $tenantUser;
 }
開發者ID:adrianoaguiar,項目名稱:multi-tenancy-bundle,代碼行數:14,代碼來源:InvitationHandler.php

示例12: createOnRequest

 /**
  * @param string $name
  * @param bool   $controlledByAI
  *
  * @return Player
  * @throws PlayerException
  */
 protected function createOnRequest(string $name, bool $controlledByAI) : Player
 {
     /** @var Player $player */
     $player = $this->repository->findOneBy(['name' => $name]);
     if (null !== $player && $controlledByAI !== static::isAIControlled($player)) {
         throw new PlayerException("player with '{$name}' already exists and controlledByAI do not match");
     }
     return $player ?? (new Player())->setName($name)->setFlags($controlledByAI ? static::FLAG_AI_CONTROLLED : static::FLAG_NONE);
 }
開發者ID:eugene-matvejev,項目名稱:battleship-game-api,代碼行數:16,代碼來源:PlayerModel.php

示例13: makeSector

 public function makeSector($address)
 {
     /**
      * @var \Samsara\Eden\Entity\Sector $sectorDB
      */
     $sectorDB = $this->sectorRepo->findOneBy(['address' => $address]);
     $zone = new Zone();
     $this->sectors[$address] = new Sector($sectorDB, $zone);
     return $this->sectors[$address];
 }
開發者ID:JordanRL,項目名稱:eden,代碼行數:10,代碼來源:GameGridProvider.php

示例14: getUserId

 /** @inheritdoc */
 public function getUserId(Credentials $credentials = null)
 {
     /** @var UsernamePasswordCredentials $credentials */
     $user = $this->userRepository->findOneBy(['username' => $credentials->getUsername()]);
     /** @var User $user */
     if (!$user || !$user->isPasswordValid($credentials->getPassword())) {
         return null;
     }
     return $user->getUserId();
 }
開發者ID:alebear,項目名稱:horses,代碼行數:11,代碼來源:UserIdFactory.php

示例15: reverseTransform

 /**
  * @param mixed $id
  * @return mixed|null|object
  */
 public function reverseTransform($id)
 {
     if (!$id) {
         return null;
     }
     $entity = $this->repository->findOneBy(array($this->property => $id));
     if (null === $entity) {
         throw new TransformationFailedException(sprintf('Can\'t find entity of class "%s" with property "%s" = "%s".', $this->class, $this->property, $id));
     }
     return $entity;
 }
開發者ID:kwuerl,項目名稱:EntityHiddenTypeBundle,代碼行數:15,代碼來源:ObjectToIdTransformer.php


注:本文中的Doctrine\ORM\EntityRepository::findOneBy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。