/** * @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; }
/** * @{inheritdoc} */ public function get($id = null) { if (null !== $id) { return $this->repository->find($id); } return $this->manager->findUsers(); }
public function findById($userId) { if (false === $this->authorizationService->isGranted('user.admin')) { throw new UnauthorizedException('Insufficient Permissions'); } return $this->objectRepository->find($userId); }
/** * @return Order */ public function getLastOrder() { if ($this->orderSession->orderId !== null) { return $this->repository->find($this->orderSession->orderId); } return null; }
/** * @{inheritdoc} */ public function get($id = null) { if (null !== $id) { return $this->repository->find($id); } return $this->repository->findAll(); }
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; } }
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; }
/** * @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()); }
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; }
/** * @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; }
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; }
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; }
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; }
/** * @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(); } }
/** * 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))); } }
/** * Attach a pack to a product * * @param $data * @param $id */ public function attachProduct($data, $id) { $commande = new Commande(); $commande->setDate(Carbon::now()->toDateString()); $commande->setUser($this->om->getRepository('FinorthoFritageEchangeBundle:User')->find($id)); foreach ($data as $item) { $this->validateReactData->check($data); $stl = $this->repository->find($item['id']); $stl->setPack($this->om->getRepository('FinorthoFritageEchangeBundle:PackItem')->find($item['packId'])); $stl->setCommande($commande); $commande->addStl($stl); } $this->om->persist($commande); $this->om->flush(); return $commande->getId(); }
/** * @param $id * @return UserDTO * @throws UserNotFoundException */ public function getUserById($id) { $user = $this->userRepository->find($id); if ($user === null) { throw new UserNotFoundException(); } return UserDTO::withEntity($user); }
/** * {@inheritdoc} */ public function delete($entity) { if (!$entity instanceof Entities\IEntity) { $entity = $this->entityRepository->find($entity); } if (!$entity) { throw new Exceptions\InvalidArgumentException('Entity not found.'); } $this->processHooks($this->beforeDelete, [$entity]); $entityManager = $this->managerRegistry->getManagerForClass(get_class($entity)); $entityManager->remove($entity); $this->processHooks($this->afterDelete); if ($this->getFlush() === TRUE) { $entityManager->flush(); } return TRUE; }
function it_should_read_entity(ManagerRegistry $registry, EntityManager $em, ObjectRepository $repo) { $repo->find(1)->willReturn(['foo' => 1]); $em->getRepository('foo')->willReturn($repo); $registry->getManager(null)->willReturn($em); $this->setRegistry($registry); $this->read(1)->shouldBe(['foo' => 1]); }
public function buildEntity($value) { if (empty($value[16])) { throw new SkipImportException("Country '{$value[0]}' not imported because is no longer bound to a toponym"); } /* @var $toponym \Giosh94mhz\GeonamesBundle\Entity\Toponym */ $toponym = $this->toponymRepository->find($value[16]); if (!$toponym) { throw new MissingToponymException("Country '{$value[0]}' not imported due to missing toponym '{$value[16]}'"); } /* @var $country \Giosh94mhz\GeonamesBundle\Entity\Country */ $country = $this->repository->find($toponym) ?: new Country($toponym); $languages = empty($value[15]) ? array() : explode(',', $value[15]); $neighbours = empty($value[17]) ? array() : explode(',', $value[17]); $country->setIso($value[0])->setIso3($value[1])->setIsoNumeric($value[2])->setFipsCode($value[3])->setName($value[4])->setCapital($value[5])->setArea($value[6])->setPopulation($value[7])->setContinent($value[8])->setTopLevelDomain($value[9])->setCurrency($value[10])->setCurrencyName($value[11])->setPhone($value[12])->setPostalCodeFormat($value[13])->setPostalCodeRegex($value[14])->setLanguages($languages)->setNeighbours($neighbours)->setEquivalentFipsCode($value[18]); return $country; }
function __construct(ObjectRepository $userRepository, Session $sessionHandler) { parent::__construct($sessionHandler); $identity = parent::getIdentity(); if ($identity !== NULL) { $identity = $userRepository->find($identity->getId()); } $this->identity = $identity; }
/** * {@inheritdoc} */ public function update(Utils\ArrayHash $values, $entity) { if (!$entity instanceof Entities\IEntity) { $entity = $this->entityRepository->find($entity); } if (!$entity) { throw new Exceptions\InvalidArgumentException('Entity not found.'); } $this->processHooks($this->beforeUpdate, [$entity, $values]); $this->entityMapper->fillEntity($values, $entity, FALSE); $entityManager = $this->managerRegistry->getManagerForClass(get_class($entity)); $entityManager->persist($entity); $this->processHooks($this->afterUpdate, [$entity, $values]); if ($this->getFlush() === TRUE) { $entityManager->flush(); } return $entity; }
/** * Is document signature completed * * @param DocumentSignature|int $signature * @throws \InvalidArgumentException * @return bool */ public function isSignatureCompleted($signature) { if ($signature instanceof DocumentSignature) { $documentSignature = $signature; } elseif (is_numeric($signature)) { $documentSignature = $this->documentSignatureRepository->find($signature); } else { throw new \InvalidArgumentException('Argument must be integer or instance of DocumentSignature.'); } return $documentSignature ? $documentSignature->isCompleted() : false; }
/** * Transforms a value from the transformed representation to its original * representation. * * This method is called when {@link Form::submit()} is called to transform the requests tainted data * into an acceptable format for your data processing/model layer. * * This method must be able to deal with empty values. Usually this will * be an empty string, but depending on your implementation other empty * values are possible as well (such as empty strings). The reasoning behind * this is that value transformers must be chainable. If the * reverseTransform() method of the first value transformer outputs an * empty string, the second value transformer must be able to process that * value. * * By convention, reverseTransform() should return NULL if an empty string * is passed. * * @param mixed $identifier The value in the transformed representation * * @return object|null The value in the original representation * * @throws TransformationFailedException When the transformation fails. */ public function reverseTransform($identifier) { if (!$identifier) { return; } $entity = $this->repository->find($identifier); if (null === $entity) { throw new TransformationFailedException(); } return $entity; }
public function buildEntity($value) { if (empty($value[3])) { throw new SkipImportException("Admin level '{$value[0]}' not imported because is no longer bound to a toponym"); } /* @var $toponym \Giosh94mhz\GeonamesBundle\Entity\Toponym */ if (!($toponym = $this->toponymRepository->find($value[3]))) { throw new MissingToponymException("Skipped '{$value[0]}' due to missing toponym '{$value[3]}'"); } try { $codes = explode('.', $value[0]); if (!empty($this->countryCodes) && !in_array($codes[0], $this->countryCodes)) { throw new SkipImportException("Skipped admin level '{$value[0]}' because country '{$codes[0]}' is not enabled"); } $value = array_merge($value, $codes); $admin = $this->buildAdminEntity($value, $toponym); return $admin; } catch (\Exception $e) { $this->om->detach($toponym); throw $e; } }
/** * Add a comment. * * @param Request $request Request * @param string $authorToken Author Token * @param string $context Context * @param string $source Source * * @return Response */ public function addCommentAction(Request $request, $authorToken, $context, $source) { $requestBag = $request->request; $content = $requestBag->get('content'); $authorName = $requestBag->get('author_name'); $authorEmail = $requestBag->get('author_email'); $parentId = $requestBag->get('parent'); /** * @var CommentInterface|null $parent */ $parent = $parentId > 0 ? $this->commentRepository->find($parentId) : null; $comment = $this->commentManager->addComment($source, $context, $content, $authorToken, $authorName, $authorEmail, $parent); $commentStructure = $this->commentCache->createCommentStructure($comment); return new Response(json_encode(['entity' => $commentStructure, 'children' => []])); }
private function checkPrecondition(array $value) { if (empty($value[6]) || empty($value[7])) { throw new InvalidFeature("Invalid feature class='{$value[6]}' code='{$value['7']}'"); } if ($this->featureMatch && !$this->featureMatch->isIncluded($value[6], $value[7])) { throw new SkipImportException("Feature should not be included"); } if (!empty($this->countryCodes) || !empty($this->cityPopulation)) { if (!in_array($value[8], $this->countryCodes) && $value[14] < $this->cityPopulation) { throw new SkipImportException("Toponym does not match country or cities limits"); } } return $this->featureRepo->find(array('class' => $value[6], 'code' => $value[7])); }
/** * {@inheritdoc} */ public function reverseTransform($value) { if (null === $value) { return; } if ($this->multiple) { if (is_string($value) && null !== $this->delimiter) { $value = explode($this->delimiter, $value); } if (!is_array($value)) { throw new UnexpectedTypeException($value, 'array'); } if (method_exists($this->repository, 'findByIds')) { return $this->repository->findByIds($value); } else { return $this->repository->findBy(['id' => $value]); } } return $this->repository->find($value); }
/** * @param $id * @return object */ public function find($id) { $object = $this->usStatesRepository->find($id); return $object; }
/** * @param $criteria * @return int */ public function findContentRoute($criteria) { return $this->repository->find($criteria); }