本文整理汇总了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;
}
示例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);
}
}
示例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);
}
示例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;
}
示例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);
}
示例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;
}
示例7: findUserByDeviceToken
/**
* @param $deviceToken
* @return null|int
*/
public function findUserByDeviceToken($deviceToken)
{
if (null !== ($device = $this->repository->findOneBy(['deviceToken' => $deviceToken]))) {
return $device->getUserId();
}
return null;
}
示例8: getNewInstance
public function getNewInstance()
{
$instance = parent::getNewInstance();
/* @var $instance Employee */
$instance->getProjects()->add($this->projectRepo->findOneBy(['isInternal' => true]));
return $instance;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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];
}
示例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();
}
示例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;
}