本文整理汇总了PHP中Doctrine\Common\Persistence\ObjectRepository::find方法的典型用法代码示例。如果您正苦于以下问题:PHP ObjectRepository::find方法的具体用法?PHP ObjectRepository::find怎么用?PHP ObjectRepository::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\Common\Persistence\ObjectRepository
的用法示例。
在下文中一共展示了ObjectRepository::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;
}
示例2: get
/**
* @{inheritdoc}
*/
public function get($id = null)
{
if (null !== $id) {
return $this->repository->find($id);
}
return $this->manager->findUsers();
}
示例3: findById
public function findById($userId)
{
if (false === $this->authorizationService->isGranted('user.admin')) {
throw new UnauthorizedException('Insufficient Permissions');
}
return $this->objectRepository->find($userId);
}
示例4: getLastOrder
/**
* @return Order
*/
public function getLastOrder()
{
if ($this->orderSession->orderId !== null) {
return $this->repository->find($this->orderSession->orderId);
}
return null;
}
示例5: get
/**
* @{inheritdoc}
*/
public function get($id = null)
{
if (null !== $id) {
return $this->repository->find($id);
}
return $this->repository->findAll();
}
示例6: buildEntity
public function buildEntity($value)
{
$parent = null;
$child = null;
try {
/* @var $parent \Giosh94mhz\GeonamesBundle\Entity\Toponym */
$parent = $this->toponymRepository->find($value[0]);
/* @var $child \Giosh94mhz\GeonamesBundle\Entity\Toponym */
$child = $this->toponymRepository->find($value[1]);
if (!$parent || !$child) {
throw new MissingToponymException("HierarchyLink not imported due to missing toponym '{$value['0']}=>{$value['1']}'");
}
/* @var $link \Giosh94mhz\GeonamesBundle\Entity\HierarchyLink */
$link = $this->repository->find(array('parent' => $parent->getId(), 'child' => $child->getId())) ?: new HierarchyLink($parent, $child);
$link->setType($value[2]);
return $link;
} catch (\Exception $e) {
if ($parent !== null) {
$this->om->detach($parent);
}
if ($child !== null) {
$this->om->detach($child);
}
throw $e;
}
}
示例7: buildAdminEntity
protected function buildAdminEntity($value, Toponym $toponym)
{
/* @var $admin \Giosh94mhz\GeonamesBundle\Entity\Admin1 */
$admin = $this->repository->find($toponym) ?: new Admin1($toponym);
$admin->setCode($value[5])->setCountryCode($value[4])->setName($value[1])->setAsciiName($value[2]);
return $admin;
}
示例8: refreshUser
/**
* @param UserInterface $user
*
* @return object
*/
public function refreshUser(UserInterface $user)
{
$class = get_class($user);
if (!$this->supportsClass($class)) {
throw new UnsupportedUserException(sprintf('Instances of "%s" are not supported.', $class));
}
return $this->userRepository->find($user->getId());
}
示例9: buildEntity
public function buildEntity($value)
{
if ($value[0] === 'ISO 639-3') {
throw new SkipImportException("Language file header is not commented out");
}
/* @var $language \Giosh94mhz\GeonamesBundle\Entity\Language */
$language = $this->repository->find($value[0]) ?: new Language($value[0]);
$language->setIso639p2($value[1])->setIso639p1($value[2])->setName($value[3]);
return $language;
}
示例10: hydrate
/**
* @param int|null $value
* @return object|null
* @throws RuntimeException
*/
public function hydrate($value)
{
if (empty($value)) {
return null;
}
$entity = $this->objectRepository->find($value);
if ($entity === null) {
throw new RuntimeException(sprintf('Entity with ID "%s" not found', $value));
}
return $entity;
}
示例11: buildEntity
public function buildEntity($value)
{
if (mb_strtolower($value[0]) === 'null') {
throw new SkipImportException("Well-known null feature");
}
list($class, $code) = explode('.', $value[0], 2);
/* @var $feature \Giosh94mhz\GeonamesBundle\Entity\Feature */
$feature = $this->repository->find(array('code' => $code, 'class' => $class)) ?: new Feature($class, $code);
$feature->setName($value[1])->setDescription($value[2]);
return $feature;
}
示例12: buildEntity
public function buildEntity($value)
{
/* @var $continent \Giosh94mhz\GeonamesBundle\Entity\Continent */
$continent = $this->repository->find($value[2]);
if (!$continent) {
/* @var $toponym \Giosh94mhz\GeonamesBundle\Entity\Toponym */
$toponym = $this->toponymRepository->find($value[2]) ?: $this->createFallbackToponym($value[0], $value[1], $value[2]);
$continent = new Continent($toponym);
}
$continent->setCode($value[0])->setName($value[1]);
return $continent;
}
示例13: buildEntity
public function buildEntity($value)
{
/* @var $toponym \Giosh94mhz\GeonamesBundle\Entity\Toponym */
$toponym = $this->toponymRepository->find($value[1]);
if (!$toponym) {
throw new SkipImportException("Toponym doesn't exists");
}
/* @var $alternateName \Giosh94mhz\GeonamesBundle\Entity\AlternateName */
$alternateName = $this->repository->find($value[0]) ?: new AlternateName($value[0]);
$alternateName->setToponym($toponym)->setLanguage($value[2])->setName($value[3])->setIsPreferredName(!empty($value[4]))->setIsShortName(!empty($value[5]))->setIsColloquial(!empty($value[6]))->setIsHistoric(!empty($value[6]));
return $alternateName;
}
示例14: getById
/**
* @return ShipmentOption
*/
public function getById(ShipmentType $type, $id)
{
if ($type->isPersonal()) {
return $this->personalPointRepository->find($id);
} elseif ($type->isByTransportCompany()) {
return $this->transportCompanyRepository->find($id);
} elseif ($type->isToCollectionPoint()) {
return $this->collectionPointRepository->find($id);
} else {
throw new \LogicException();
}
}
示例15: preSubmit
/**
* Removes or adds a province field based on the country set on submitted form.
*
* @param FormEvent $event
*/
public function preSubmit(FormEvent $event)
{
$data = $event->getData();
if (!is_array($data) || !array_key_exists('country', $data)) {
return;
}
$country = $this->countryRepository->find($data['country']);
if (null === $country) {
return;
}
if ($country->hasProvinces()) {
$event->getForm()->add($this->factory->createNamed('province', 'sylius_province_choice', null, array('country' => $country, 'auto_initialize' => false)));
}
}