当前位置: 首页>>代码示例>>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;未经允许,请勿转载。