本文整理汇总了PHP中Doctrine\Common\Persistence\ObjectRepository::findOneBy方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectRepository::findOneBy方法的具体用法?PHP ObjectRepository::findOneBy怎么用?PHP ObjectRepository::findOneBy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\ObjectRepository
的用法示例。
在下文中一共展示了ObjectRepository::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: checkDuplicity
private function checkDuplicity(Category $category)
{
$duplicate = $this->repository->findOneBy(['path' => $category->getPath()]);
if ($duplicate !== null) {
throw new EntityDuplicateException(sprintf('Category with path %s already exists.', $category->getPath()));
}
}
示例3: checkDuplicity
private function checkDuplicity(User $user)
{
$duplicate = $this->repository->findOneBy(['email' => $user->getEmail()]);
if ($duplicate !== null) {
throw new EntityDuplicateException(sprintf('User with e-mail %s already exists.', $user->getEmail()));
}
}
示例4: tryGetMRByCode
/**
* Try to get from local property if exist or load from database afterwards
*
* @param string $code
*
* @return Region|Null
*/
protected function tryGetMRByCode($code)
{
if (!isset($this->MRIdentityMap[$code]) && !array_key_exists($code, $this->MRIdentityMap)) {
$this->MRIdentityMap[$code] = $this->repository->findOneBy(['combinedCode' => $code]);
}
return $this->MRIdentityMap[$code];
}
示例5: Place
function it_converts_node_to_street_entry_with_updating_existing_one(ObjectManager $om, ObjectRepository $or, Street $street)
{
$xml = <<<EOT
<row>
<col name="WOJ">02</col>
<col name="POW">23</col>
<col name="GMI">09</col>
<col name="RODZ_GMI">2</col>
<col name="SYM">0884849</col>
<col name="SYM_UL">10268</col>
<col name="CECHA">ul.</col>
<col name="NAZWA_1">Księżycowa </col>
<col name="NAZWA_2"/>
<col name="STAN_NA">2013-10-10</col>
</row>
EOT;
$place = new Place(884849);
$place->setName('City');
$or->findOneBy(array('id' => '0884849'))->shouldBeCalled()->willReturn($place);
$or->findOneBy(array('id' => '10268', 'place' => $place))->shouldBeCalled()->willReturn($street);
$street->setName('Księżycowa')->shouldBeCalled()->willReturn($street);
$street->setAdditionalName('')->shouldBeCalled()->willReturn($street);
$street->setType('ul.')->shouldBeCalled()->willReturn($street);
$this->beConstructedWith(new \SimpleXMLElement($xml), $om);
$this->convertToEntity()->shouldBeLike($street->getWrappedObject());
}
示例6: getUserByUsername
/**
* @param $username
* @return \AppBundle\Entity\User
* @throws UserNotFoundException
*/
public function getUserByUsername($username)
{
$user = $this->userRepository->findOneBy(array('username' => $username));
if ($user === null) {
throw new UserNotFoundException();
}
return $user;
}
示例7: Isbn
function it_searches_book_by_isbn_number(BookInterface $book, ObjectRepository $doctrineRepository)
{
$isbn = new Isbn('978-1-56619-909-4');
$doctrineRepository->findOneBy(array('isbn.number' => $isbn))->willReturn($book);
$this->searchByIsbn($isbn)->shouldBeLike(SearchResults::fromArrayOfBooks(array($book->getWrappedObject())));
$doctrineRepository->findOneBy(array('isbn.number' => $isbn))->willReturn(null);
$this->searchByIsbn($isbn)->shouldBeLike(SearchResults::asEmpty());
}
示例8: findModuleByIdentity
/**
* {@inheritdoc}
*
* @throws \RuntimeException if the identifier is not set
*/
public function findModuleByIdentity($identity)
{
$field = $this->getModularIdentifier();
if (null == $field) {
throw new \RuntimeException('The module manager is missing a modular identifier.');
}
return $this->repository->findOneBy([$field => $identity]);
}
示例9: findFromToRate
/**
* This is used to return a from to rate and is used in the cron section
* @param $fromCurrency
* @param $toCurrency
* @return null|object
*/
public function findFromToRate($fromCurrency, $toCurrency)
{
//Check if the rate exists
$exRateObject = $this->exRateRepository->findOneBy(array('fromCurrency' => $fromCurrency, 'toCurrency' => $toCurrency));
if (!$exRateObject instanceof ExchangeRate) {
return null;
}
return $exRateObject;
}
示例10: getProductsByCategoryName
/**
* @param $categoryName
* @return Category
*/
public function getProductsByCategoryName($categoryName)
{
try {
$category = $this->repository->findOneBy(['name' => $categoryName, 'isActive' => 1]);
} catch (\Exception $e) {
$category = new Category(self::CATEGORY_NOT_FOUND);
}
return $category;
}
示例11: transform
/**
* {@inheritdoc}
*/
public function transform($value)
{
if (!$value) {
return null;
}
if (null === ($entity = $this->repository->findOneBy(array($this->identifier => $value)))) {
throw new TransformationFailedException(sprintf('Object "%s" with identifier "%s"="%s" does not exist.', $this->repository->getClassName(), $this->identifier, $value));
}
return $entity;
}
示例12: release
public function release($name)
{
$nameWithPrefix = $this->getNameWithPrefix($name);
$lock = $this->repository->findOneBy(['name' => $nameWithPrefix]);
if ($lock) {
$this->objectManager->remove($lock);
$this->objectManager->flush();
return true;
}
return false;
}
示例13: createUserIdentity
public function createUserIdentity($user)
{
list($className, $identifier) = $this->extractUserIdentityFields($user);
if (isset($this->userCache[$className][$identifier])) {
return $this->userCache[$className][$identifier];
}
if (null !== ($this->userCache[$className][$identifier] = $this->userRepository->findOneBy(array('class' => $className, 'identifier' => $identifier)))) {
return $this->userCache[$className][$identifier];
}
$userClass = $this->userRepository->getClassName();
return $this->userCache[$className][$identifier] = new $userClass($className, $identifier);
}
示例14: findByName
/**
* @param string $name
* @return object
*/
private function findByName($name)
{
$sequence = $this->repository->findOneBy(array('name' => $name));
if (!$sequence) {
$sequence = new $this->class();
$sequence->setName($name);
$sequence->setCurrentValue(0);
$this->objectManager->persist($sequence);
$this->objectManager->flush();
}
return $sequence;
}
示例15: validate
/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint)
{
if (!$value instanceof ProductInterface) {
throw new UnexpectedTypeException($value, ProductInterface::class);
}
$product = $value;
$accessor = PropertyAccess::createPropertyAccessor();
$criteria = array($constraint->property => $accessor->getValue($product, $constraint->property));
$conflictualProduct = $this->repository->findOneBy($criteria);
if (null !== $conflictualProduct && $conflictualProduct != $product) {
$this->context->addViolationAt($constraint->property, $constraint->message, array('%property%' => $constraint->property));
}
}