本文整理汇总了PHP中Doctrine\ORM\EntityRepository类的典型用法代码示例。如果您正苦于以下问题:PHP EntityRepository类的具体用法?PHP EntityRepository怎么用?PHP EntityRepository使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EntityRepository类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:indigophp,项目名称:crud-doctrine,代码行数:7,代码来源:AllFinderSpec.php
示例2:
function it_returns_null_when_no_entity_found(Load $query, EntityRepository $repository, EntityManagerInterface $em)
{
$query->getEntityClass()->willReturn('Indigo\\Crud\\Stub\\Entity');
$query->getId()->willReturn(1);
$repository->find(1)->willReturn(null);
$em->getRepository('Indigo\\Crud\\Stub\\Entity')->willReturn($repository);
$this->handle($query)->shouldReturn(null);
}
开发者ID:indigophp,项目名称:crud-doctrine,代码行数:8,代码来源:LoaderSpec.php
示例3: 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
示例4: 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
示例5: 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;
}
开发者ID:baptistelinel,项目名称:Administrable-Blog,代码行数:12,代码来源:ArticleService.php
示例6: uniqueAppKey
private function uniqueAppKey()
{
do {
$appKey = str_shuffle("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ");
$application = $this->userRepository->findBy(array('appKey' => $appKey));
} while ($application);
return $appKey;
}
开发者ID:tarnawski,项目名称:JSONMock-backend,代码行数:8,代码来源:ApplicationFactory.php
示例7: 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());
}
开发者ID:plumphp,项目名称:plum-doctrine,代码行数:11,代码来源:RepositoryReaderTest.php
示例8: 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('[email protected]')->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('[email protected]')->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
示例9: 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
示例10: 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('[email protected]');
$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('[email protected]')->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('[email protected]')->setPhone('798-682-5919')->setOwner($oroMain);
$this->persistAndFlush($this->organizationManager, $mageCoreUnit);
$this->addReference('default_core_business', $mageCoreUnit);
}
开发者ID:antrampa,项目名称:crm,代码行数:32,代码来源:LoadBusinessUnitData.php
示例11: 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);
}
开发者ID:noglitchyo,项目名称:pim-community-dev,代码行数:12,代码来源:AttributeController.php
示例12: 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
示例13: givenDatabaseIsClear
protected function givenDatabaseIsClear()
{
if (0 !== count($this->items->findAll())) {
$purger = new ORMPurger($this->entityManager);
$purger->purge();
}
}
开发者ID:lzakrzewski,项目名称:tests-with-database-examples,代码行数:7,代码来源:TestCase.php
示例14: 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));
}
开发者ID:aculvi,项目名称:OroCRMMailChimpBundle,代码行数:13,代码来源:EmailCampaignPlaceholderFilterTest.php
示例15: buildBaseQuery
/**
* @return QueryBuilder
*/
private function buildBaseQuery()
{
$qb = $this->entityRepository->createQueryBuilder('z');
GathererHelper::addFiltersDataToQuery($this->filters, $qb);
GathererHelper::addAdditionalFilterDataToQuery($this->additionalFilters, $qb);
return $qb;
}
开发者ID:amstaffix,项目名称:extjs-entity-gatherer,代码行数:10,代码来源:Gatherer.php
示例16: getFormValue
/**
* {@inheritdoc}
*/
public function getFormValue(array $converterAttributes, $value)
{
if ($value === null) {
return $this->businessUnitRepository->findAll();
}
return parent::getFormValue($converterAttributes, $value);
}
开发者ID:snorchel,项目名称:platform,代码行数:10,代码来源:WidgetBusinessUnitSelectConverter.php
示例17: 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
示例18: addFilterByOrderStatus
/**
* @param QueryBuilder $qb
* @param string $orderStatus
*/
protected function addFilterByOrderStatus(QueryBuilder $qb, $orderStatus)
{
$aliases = $qb->getRootAliases();
$subQueryBuilder = $this->customerRepository->createQueryBuilder('c');
$subQueryBuilder->select('IDENTITY(c.account)')->join('c.orders', 'o', 'WITH', $subQueryBuilder->expr()->eq($subQueryBuilder->expr()->lower('o.status'), ':filteredOrderStatus'));
$qb->andWhere($qb->expr()->in($aliases[0] . '.account', $subQueryBuilder->getDQL()))->setParameter('filteredOrderStatus', $orderStatus);
}
开发者ID:antrampa,项目名称:crm,代码行数:11,代码来源:UpdateCustomerLifetimeForCanceledOrders.php
示例19: 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
示例20: 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
注:本文中的Doctrine\ORM\EntityRepository类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论