本文整理匯總了PHP中Doctrine\ORM\EntityManagerInterface::find方法的典型用法代碼示例。如果您正苦於以下問題:PHP EntityManagerInterface::find方法的具體用法?PHP EntityManagerInterface::find怎麽用?PHP EntityManagerInterface::find使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Doctrine\ORM\EntityManagerInterface
的用法示例。
在下文中一共展示了EntityManagerInterface::find方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: getOrderRequest
public function getOrderRequest($sessionId)
{
/** @var PayuOrderRequest $orderRequest */
$orderRequest = $this->em->find($this->orderRequestClass, $sessionId);
if (!$orderRequest) {
throw new EntityNotFoundException();
}
return $orderRequest;
}
示例2: validate
/**
* @param $value
* @return object|null
*/
public function validate($value)
{
if (isset($this->valuesCallback)) {
$values = call_user_func($this->valuesCallback, $value);
return $this->em->getRepository($this->entityClass)->findOneBy($values);
} elseif ($this->identifierField) {
return boolval($this->em->getRepository($this->entityClass)->findOneBy([$this->identifierField => $value]));
}
return boolval($this->em->find($this->entityClass, $value));
}
示例3: saveCountries
/**
* @param array $countries
*/
public function saveCountries($countries)
{
foreach ($countries as $country) {
if ($this->em->find('MainBundle:Country', $country->getCodeCountry())) {
$this->em->merge($country);
} else {
$this->em->persist($country);
}
}
$this->em->flush();
}
示例4: updatePending
/**
* @param int $pageId
*
* @return Pages
*/
protected function updatePending($pageId)
{
$pageEntity = $this->entityManager->find('Application\\V1\\Entity\\Pages', $pageId, LockMode::PESSIMISTIC_WRITE);
$imagesCnt = $pageEntity->getPendingImagesCnt();
if ($imagesCnt > 0) {
$pageEntity->setPendingImagesCnt($imagesCnt - 1);
if ($pageEntity->getPendingImagesCnt() == 0) {
$pageEntity->setStatus(PageInterface::STATUS_DONE);
}
}
return $pageEntity;
}
示例5: saveRegId
public function saveRegId($regId, $section)
{
$regIdDb = $this->em->find('MainBundle:RegId', $regId);
$section = $this->em->find('MainBundle:Section', $section);
if ($regIdDb) {
$regIdDb->setSection($section)->setUpdatedAt();
} else {
$regIdDb = $this->regIdCreator->createRegId($regId, $section);
$this->em->persist($regIdDb);
}
$this->em->flush();
return $regIdDb;
}
示例6: move
public function move(Category $category, $parentId, $newPosition)
{
if ($parentId) {
$parentCategory = $this->em->find('MainBundle:Category', $parentId);
$newSiblings = $parentCategory->getChildren();
} else {
$guide = $category->getGuide();
$newSiblings = $guide->getCategoriesWithoutParent();
}
$oldPosition = $category->getPosition();
// if we just move the position
if ($category->getParent() == null && $parentId == null || $category->getParent() != null && $category->getParent()->getId() == $parentId) {
if ($oldPosition > $newPosition) {
foreach ($newSiblings as $child) {
if ($child->getPosition() >= $newPosition && $child->getPosition() < $oldPosition) {
$child->setPosition($child->getPosition() + 1);
}
$this->em->persist($child);
}
} else {
foreach ($newSiblings as $child) {
if ($child->getPosition() <= $newPosition && $child->getPosition() > $oldPosition) {
$child->setPosition($child->getPosition() - 1);
}
$this->em->persist($child);
}
}
} else {
$oldSiblings = $category->getParent() ? $category->getParent()->getChildren() : $category->getGuide()->getCategoriesWithoutParent();
foreach ($oldSiblings as $child) {
if ($child->getPosition() >= $oldPosition) {
$child->setPosition($child->getPosition() - 1);
}
$this->em->persist($child);
}
foreach ($newSiblings as $child) {
if ($child->getPosition() >= $newPosition) {
$child->setPosition($child->getPosition() + 1);
}
$this->em->persist($child);
}
}
$category->setPosition($newPosition);
if (isset($parentCategory)) {
$category->setParent($parentCategory);
} else {
$category->setParent(null);
}
$this->em->persist($category);
$this->em->flush();
}
示例7: reFetchObject
/**
* @param object $object
*
* @return object
*/
private function reFetchObject($object)
{
$metadata = $this->entityManager->getClassMetadata(get_class($object));
$freshValue = $this->entityManager->find($metadata->getName(), $metadata->getIdentifierValues($object));
if (!$freshValue) {
throw MissingBatchItemException::fromInvalidReference($metadata, $object);
}
return $freshValue;
}
示例8: get
/**
* {@inheritdoc}
*/
public function get($key)
{
if (!$this->initialized && $this->association['fetch'] === ClassMetadata::FETCH_EXTRA_LAZY && isset($this->association['indexBy'])) {
if (!$this->typeClass->isIdentifierComposite && $this->typeClass->isIdentifier($this->association['indexBy'])) {
return $this->em->find($this->typeClass->name, $key);
}
return $this->em->getUnitOfWork()->getCollectionPersister($this->association)->get($this, $key);
}
return parent::get($key);
}
示例9: process
/**
* Process form
*
* @param ContactPhone $entity
*
* @return bool True on successful processing, false otherwise
*
* @throws AccessDeniedException
*/
public function process(ContactPhone $entity)
{
$this->form->setData($entity);
$submitData = ['phone' => $this->request->request->get('phone'), 'primary' => $this->request->request->get('primary')];
if (in_array($this->request->getMethod(), ['POST', 'PUT'])) {
$this->form->submit($submitData);
if ($this->form->isValid() && $this->request->request->get('contactId')) {
$contact = $this->manager->find('OroCRMContactBundle:Contact', $this->request->request->get('contactId'));
if (!$this->securityFacade->isGranted('EDIT', $contact)) {
throw new AccessDeniedException();
}
if ($contact->getPrimaryPhone() && $this->request->request->get('primary') === true) {
return false;
}
$this->onSuccess($entity, $contact);
return true;
}
}
return false;
}
示例10: remove
/**
* @param Request $request
* @param Response $response
* @param $args
* @return Response
* @throws \Doctrine\ORM\EntityNotFoundException
*/
public function remove(Request $request, Response $response, $args)
{
foreach (explode(',', $request->getHeader('id')[0]) as $id) {
$ticket = $this->em->find('App\\Entity\\Ticket', $id);
if ($ticket) {
$this->em->remove($ticket);
} else {
throw new EntityNotFoundException();
}
}
$this->em->flush();
return $response;
}
示例11: execute
public function execute()
{
$payload = $this->getContent();
echo "processing >> " . $payload['page_url'] . " >> for id >> " . $payload['page_id'] . "\n";
/* @var \Application\V1\Entity\Pages $pageEntity */
$pageEntity = $this->entityManager->find('Application\\V1\\Entity\\Pages', $payload['page_id']);
try {
$this->httpClient->setUri($payload['page_url']);
$response = $this->httpClient->send();
$document = new Document($response->getBody());
$manager = $this->grabImageQueue->getJobPluginManager();
$jobs = [];
$parsedPageUrl = parse_url($this->httpClient->getRequest()->getUriString());
$cnt = 0;
/* @var \DOMElement $node */
foreach ($this->documentQuery->execute('//body//img', $document) as $node) {
$job = $manager->get('Application\\QueueJob\\GrabImage');
$src = $this->normalizeSchemeAndHost($node->getAttribute('src'), $parsedPageUrl['scheme'], $parsedPageUrl['host']);
$ext = strtolower(pathinfo($src, PATHINFO_EXTENSION));
$job->setContent(['image_src' => $src, 'image_ext' => $ext, 'page_id' => $payload['page_id']]);
$jobs[] = $job;
$cnt++;
}
if ($cnt < 1) {
$pageEntity->setStatus(PageInterface::STATUS_DONE);
} else {
$pageEntity->setStatus(PageInterface::STATUS_RUNNING);
}
$pageEntity->setPendingImagesCnt($cnt);
$pageEntity->setTotalImagesCnt($cnt);
$this->entityManager->flush();
foreach ($jobs as $job) {
$this->grabImageQueue->push($job);
}
echo "Jobs to push >> " . count($jobs) . " count pending images >>" . $cnt . "\n";
} catch (\Exception $e) {
echo 'Exception: >> ' . $e->getMessage();
$pageEntity->setErrorMessage($e->getMessage());
if ($pageEntity->getStatusNumeric() == PageInterface::STATUS_RECOVERING) {
$pageEntity->setStatus(PageInterface::STATUS_ERROR);
$this->entityManager->flush();
return WorkerEvent::JOB_STATUS_FAILURE;
} else {
$pageEntity->setStatus(PageInterface::STATUS_RECOVERING);
$this->entityManager->flush();
throw new ReleasableException(array('priority' => 10, 'delay' => 15));
}
}
}
示例12: getUser
/**
* @return User|null
*/
protected function getUser()
{
if (!($token = $this->tokenStorage->getToken())) {
return null;
}
$user = $token->getUser();
/**
* Check cases when user is not in the entity manager
* (e.g. after clear or if it is in the different entity manager)
*/
if ($user instanceof User && !$this->entityManager->contains($user)) {
$user = $this->entityManager->find('OroUserBundle:User', $user->getId());
}
return $user;
}
示例13: findOneBy
/**
* @param array $criteria The criteria.
* @return object The object.
*/
public function findOneBy(array $criteria)
{
return $this->em->find(Log::class, $criteria);
}
示例14: mergeEntityStateIntoManagedCopy
/**
* @param object $entity
* @param object $managedCopy
*
* @throws ORMException
* @throws OptimisticLockException
* @throws TransactionRequiredException
*/
private function mergeEntityStateIntoManagedCopy($entity, $managedCopy)
{
$class = $this->em->getClassMetadata(get_class($entity));
foreach ($this->reflectionPropertiesGetter->getProperties($class->name) as $prop) {
$name = $prop->name;
$prop->setAccessible(true);
if (!isset($class->associationMappings[$name])) {
if (!$class->isIdentifier($name)) {
$prop->setValue($managedCopy, $prop->getValue($entity));
}
} else {
$assoc2 = $class->associationMappings[$name];
if ($assoc2['type'] & ClassMetadata::TO_ONE) {
$other = $prop->getValue($entity);
if ($other === null) {
$prop->setValue($managedCopy, null);
} else {
if ($other instanceof Proxy && !$other->__isInitialized()) {
// do not merge fields marked lazy that have not been fetched.
return;
}
if (!$assoc2['isCascadeMerge']) {
if ($this->getEntityState($other) === self::STATE_DETACHED) {
$targetClass = $this->em->getClassMetadata($assoc2['targetEntity']);
$relatedId = $targetClass->getIdentifierValues($other);
if ($targetClass->subClasses) {
$other = $this->em->find($targetClass->name, $relatedId);
} else {
$other = $this->em->getProxyFactory()->getProxy($assoc2['targetEntity'], $relatedId);
$this->registerManaged($other, $relatedId, array());
}
}
$prop->setValue($managedCopy, $other);
}
}
} else {
$mergeCol = $prop->getValue($entity);
if ($mergeCol instanceof PersistentCollection && !$mergeCol->isInitialized()) {
// do not merge fields marked lazy that have not been fetched.
// keep the lazy persistent collection of the managed copy.
return;
}
$managedCol = $prop->getValue($managedCopy);
if (!$managedCol) {
$managedCol = new PersistentCollection($this->em, $this->em->getClassMetadata($assoc2['targetEntity']), new ArrayCollection());
$managedCol->setOwner($managedCopy, $assoc2);
$prop->setValue($managedCopy, $managedCol);
$this->originalEntityData[spl_object_hash($entity)][$name] = $managedCol;
}
if ($assoc2['isCascadeMerge']) {
$managedCol->initialize();
// clear and set dirty a managed collection if its not also the same collection to merge from.
if (!$managedCol->isEmpty() && $managedCol !== $mergeCol) {
$managedCol->unwrap()->clear();
$managedCol->setDirty(true);
if ($assoc2['isOwningSide'] && $assoc2['type'] == ClassMetadata::MANY_TO_MANY && $class->isChangeTrackingNotify()) {
$this->scheduleForDirtyCheck($managedCopy);
}
}
}
}
}
if ($class->isChangeTrackingNotify()) {
// Just treat all properties as changed, there is no other choice.
$this->propertyChanged($managedCopy, $name, null, $prop->getValue($managedCopy));
}
}
}
示例15: load
/**
* @inheritdoc
*/
public function load(LinkInterface $link)
{
return $this->entityManager->find($this->subjectRegistry->getByAlias($link->getResourceType())->getClass(), $link->getResourceId());
}