本文整理汇总了PHP中Doctrine\ORM\EntityRepository类的典型用法代码示例。如果您正苦于以下问题:PHP EntityRepository类的具体用法?PHP EntityRepository怎么用?PHP EntityRepository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EntityRepository类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
function it_handles_a_find_all_query(FindAll $query, EntityRepository $repository, EntityManagerInterface $em)
{
$query->getEntityClass()->willReturn('Indigo\\Crud\\Stub\\Entity');
$repository->findAll()->shouldBeCalled();
$em->getRepository('Indigo\\Crud\\Stub\\Entity')->willReturn($repository);
$this->handle($query);
}
示例2: 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;
}
示例3: 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);
}
}
示例4: getSimilarArticlesByCategory
/**
* Return a similar articles by category
* @param Article $article
* @return Article array
*/
public function getSimilarArticlesByCategory(Article $article)
{
$category = $article->getCategory();
$similarArticles = $this->articleRepository->findBy(array('category' => $category), array('date' => 'ASC'), 3);
unset($similarArticles[array_search($article, $similarArticles)]);
return $similarArticles;
}
示例5: uniqueAppKey
private function uniqueAppKey()
{
do {
$appKey = str_shuffle("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
$application = $this->userRepository->findBy(array('appKey' => $appKey));
} while ($application);
return $appKey;
}
示例6: countShouldReturnNumberOfResults
/**
* @test
* @covers Plum\PlumDoctrine\ORM\RepositoryReader::count()
*/
public function countShouldReturnNumberOfResults()
{
$result = new stdClass();
$this->repository->shouldReceive('findBy')->andReturn([$result, $result]);
$reader = new RepositoryReader($this->repository, ['age' => 29]);
$this->assertEquals(2, $reader->count());
}
示例7: 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);
}
示例8: 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;
}
示例9: 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);
}
示例10: indexAction
/**
* Get the attribute collection
*
* @return JsonResponse
*/
public function indexAction()
{
$attributes = $this->attributeRepository->findAll();
$filteredAttributes = $this->collectionFilter->filterCollection($attributes, 'pim.internal_api.attribute.view');
$normalizedAttributes = $this->normalizer->normalize($filteredAttributes, 'internal_api');
return new JsonResponse($normalizedAttributes);
}
示例11: 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);
}
示例12: givenDatabaseIsClear
protected function givenDatabaseIsClear()
{
if (0 !== count($this->items->findAll())) {
$purger = new ORMPurger($this->entityManager);
$purger->purge();
}
}
示例13: testIsApplicableOnEmailCampaign
/**
* @param EmailCampaign $emailCampaign
* @param Campaign $campaign
* @param bool $expected
* @dataProvider staticCampaignProvider
*/
public function testIsApplicableOnEmailCampaign($emailCampaign, $campaign, $expected)
{
$this->entityRepository->expects($this->any())->method('findOneBy')->will($this->returnValue($campaign));
$this->managerRegistry->expects($this->any())->method('getManager')->will($this->returnValue($this->entityManager));
$this->entityManager->expects($this->any())->method('getRepository')->will($this->returnValue($this->entityRepository));
$this->assertEquals($expected, $this->placeholderFilter->isApplicableOnEmailCampaign($emailCampaign));
}
示例14: buildBaseQuery
/**
* @return QueryBuilder
*/
private function buildBaseQuery()
{
$qb = $this->entityRepository->createQueryBuilder('z');
GathererHelper::addFiltersDataToQuery($this->filters, $qb);
GathererHelper::addAdditionalFilterDataToQuery($this->additionalFilters, $qb);
return $qb;
}
示例15: getFormValue
/**
* {@inheritdoc}
*/
public function getFormValue(array $converterAttributes, $value)
{
if ($value === null) {
return $this->businessUnitRepository->findAll();
}
return parent::getFormValue($converterAttributes, $value);
}