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


PHP EntityRepository::find方法代码示例

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


在下文中一共展示了EntityRepository::find方法的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: 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

示例3: execute

 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $app = $this->getProjectApplication();
     $this->logger = $this->getLogger();
     $this->regionService = $app['region.skyforge.service'];
     $this->regionService->setRegion($input->getOption('region'));
     $this->em = $app['orm.ems'][$this->regionService->getDbConnectionNameByRegion()];
     $this->parseService = $app['parse.skyforge.service'];
     $this->parseService->setAuthData($this->regionService->getCredentials());
     $this->playerRepository = $this->em->getRepository('Erliz\\SkyforgeBundle\\Entity\\Player');
     $this->pantheonRepository = $this->em->getRepository('Erliz\\SkyforgeBundle\\Entity\\Pantheon');
     $this->communityRepository = $this->em->getRepository('Erliz\\SkyforgeBundle\\Entity\\Community');
     //        $lockFilePath = $app['config']['app']['path'].'/cache/curl/parse.lock';
     //        if (is_file($lockFilePath)) {
     //            throw new \RuntimeException('Another parse in progress');
     //        } else {
     //            file_put_contents($lockFilePath, getmypid());
     //        }
     if ($communityId = $input->getOption('id')) {
         $community = $this->communityRepository->find($communityId);
         $type = $this::TYPE_COMMUNITY;
         if (!$community) {
             $community = $this->pantheonRepository->find($communityId);
             $type = $this::TYPE_PANTHEON;
         }
         if (!$community) {
             $this->logger->addInfo(sprintf('Community with id %s not found in db', $communityId));
         } else {
             $this->updateCommunityMembers($community, $output, $type);
             $this->flush();
         }
     }
     if ($input->getOption('pantheons') || $input->getOption('communities')) {
         $lastId = $input->getOption('lastId');
         if ($input->getOption('pantheons')) {
             $sqlResponse = $this->em->createQuery("\n                    SELECT pt.id, count(pl.id) cnt\n                    FROM Erliz\\SkyforgeBundle\\Entity\\Pantheon pt\n                    LEFT JOIN pt.members pl\n                    group by pt.id\n                    order by cnt DESC")->getScalarResult();
             $type = $this::TYPE_PANTHEON;
             $repo = $this->pantheonRepository;
         } else {
             $sqlResponse = $this->em->createQuery("\n                    SELECT pt.id, count(pl.id) cnt\n                    FROM Erliz\\SkyforgeBundle\\Entity\\Community pt\n                    JOIN pt.members pl\n                    group by pt.id\n                    order by cnt DESC")->getScalarResult();
             $type = $this::TYPE_COMMUNITY;
             $repo = $this->communityRepository;
         }
         $communityIds = array_map('current', $sqlResponse);
         $communitiesCount = count($communityIds);
         /** @var CommunityInterface $community */
         foreach ($communityIds as $index => $communityId) {
             if ($communityId == $lastId) {
                 $lastId = false;
             }
             if ($lastId) {
                 continue;
             }
             $this->updateCommunityMembers($repo->find($communityId), $output, $type);
             $this->logger->addInfo(sprintf('Processed %s / %s', $index + 1, $communitiesCount));
             $this->flush();
         }
     }
     //        unlink($lockFilePath);
 }
开发者ID:Erliz,项目名称:skyforge-bundle,代码行数:60,代码来源:UpdatePantheonInfoCommand.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");
     }
     if ($client->getUser() === null) {
         throw new AuthenticationException("Client is not associated with any user");
     }
     $token->setUser($client->getUser());
     $token->setClient($client);
     return $token;
 }
开发者ID:koenreiniers,项目名称:oauth-server-bundle,代码行数:35,代码来源:ClientCredentialsProvider.php

示例5: getById

 /**
  * @param int $id
  *
  * @return bool|Pantheon
  */
 public function getById($id)
 {
     $pantheon = $this->repository->find($id);
     if (!$pantheon) {
         throw new \InvalidArgumentException(sprintf('Pantheon with id "%s" not found', $id));
     }
     return $pantheon;
 }
开发者ID:Erliz,项目名称:skyforge-bundle,代码行数:13,代码来源:PantheonService.php

示例6: findById

 public function findById($id)
 {
     $sheet = $this->doctrineSheetRepo->find($id);
     if (!$sheet instanceof QuestionSheet) {
         throw new \InvalidArgumentException("Unable to fetch this sheet");
     }
     return $sheet;
 }
开发者ID:lukaszmakuch,项目名称:question-sheet-storage,代码行数:8,代码来源:QuestionSheetRepoImpl.php

示例7: findById

 public function findById($id)
 {
     $foundUser = $this->doctrineUserRepo->find($id);
     if (null === $foundUser) {
         throw new \InvalidArgumentException("user not found");
     }
     return $foundUser;
 }
开发者ID:lukaszmakuch,项目名称:question-sheet-storage,代码行数:8,代码来源:UserRepo.php

示例8: find

 public function find($id)
 {
     $event = $this->repo->find($id);
     if (null === $event) {
         throw new NotFoundHttpException(sprintf("Couldn't find event with id '%d'", $id));
     }
     return $event;
 }
开发者ID:pguso,项目名称:CalendarBundle,代码行数:8,代码来源:EventManager.php

示例9: find

 public function find($id)
 {
     $calendar = $this->repo->find($id);
     if (null === $calendar) {
         throw new NotFoundHttpException(sprintf("Couldn't find calendar with id '%d'", $id));
     }
     return $calendar;
 }
开发者ID:pguso,项目名称:CalendarBundle,代码行数:8,代码来源:CalendarManager.php

示例10: find

 public function find($id)
 {
     $entity = $this->entityRepository->find($id);
     if (!$entity) {
         throw new MissingEntityException();
     }
     return $entity;
 }
开发者ID:lukasz-jakub-adamczuk,项目名称:sapi,代码行数:8,代码来源:AbstractManager.php

示例11: onLoggedOut

 public function onLoggedOut(Security $security)
 {
     // BUG: Nette\Security\User 2.1 fires onLoggedOut before clearing storage
     if ($user = $this->repository->find($security->getIdentity()->getId())) {
         $security->getStorage()->setAuthenticated(FALSE);
         $this->user->signOut($user);
     }
 }
开发者ID:rixxi,项目名称:user,代码行数:8,代码来源:Listener.php

示例12: findUser

 /**
  * @param $id
  * @return \Delivery\Entity\User
  */
 public function findUser($id)
 {
     if ($this->cache->has($id)) {
         $entity = $this->cache->get($id);
     } else {
         $entity = $this->repository->find($id);
     }
     return $entity;
 }
开发者ID:thibault-lenestour,项目名称:continuousdelivery,代码行数:13,代码来源:User.php

示例13: defaultAction

 function defaultAction($id)
 {
     /** @var Page $page */
     $page = $this->pageRepository->find($id);
     if (!$page) {
         throw new NotFoundHttpException();
     }
     $content = $this->templating->render('Page\\default.twig', array('title' => $page->getTitle(), 'content' => $page->getContent()));
     return new Response($content);
 }
开发者ID:illibejiep,项目名称:TrueDI,代码行数:10,代码来源:PageController.php

示例14: reverseTransform

 /**
  * Transforms an id to an entity.
  *
  * @param  string $id
  *
  * @return mixed
  *
  * @throws TransformationFailedException if entiyt is not found.
  */
 public function reverseTransform($id)
 {
     if (!$id) {
         return null;
     }
     $entity = $this->repository->find($id);
     if (null === $entity) {
         throw new TransformationFailedException(sprintf('A %s with id "%s" does not exist!', $this->entityName, $id));
     }
     return $entity;
 }
开发者ID:stopfstedt,项目名称:ilios,代码行数:20,代码来源:SingleRelatedTransformer.php

示例15: filterIn

 /**
  * @param mixed $value
  *
  * @throws BadRequestException
  *
  * @return object
  */
 public function filterIn($value)
 {
     if (!is_object($value)) {
         $entity = $this->repository->find($value);
     } elseif ($value instanceof QueryInterface) {
         $entity = $value->getEntity($this->repository);
     }
     $class = $this->repository->getClassName();
     if (!$entity instanceof $class) {
         throw new BadRequestException('Desired entity of type \'' . $this->repository->getClassName() . '\' could not be found.');
     }
     return $entity;
 }
开发者ID:arachne,项目名称:doctrine,代码行数:20,代码来源:FilterIn.php


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