当前位置: 首页>>代码示例>>PHP>>正文


PHP EntityManager::find方法代码示例

本文整理汇总了PHP中Kdyby\Doctrine\EntityManager::find方法的典型用法代码示例。如果您正苦于以下问题:PHP EntityManager::find方法的具体用法?PHP EntityManager::find怎么用?PHP EntityManager::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Kdyby\Doctrine\EntityManager的用法示例。


在下文中一共展示了EntityManager::find方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: findById

 /**
  * @param string
  * @param int
  * @return object|NULL
  * @throws BadRequestException
  */
 private function findById($entityName, $id)
 {
     $entity = $this->em->find($entityName, $id);
     if ($entity === NULL) {
         throw new BadRequestException('Entity "' . $entityName . '" with id = "' . $id . '" was not found.');
     }
     return $entity;
 }
开发者ID:Olicek,项目名称:DoctrineMethodsHydrator,代码行数:14,代码来源:ParametersToEntitiesConvertor.php

示例2: update

 public function update($entityClass, array $items)
 {
     $position = 1;
     foreach ($items as $id) {
         $entity = $this->em->find($entityClass, $id);
         $entity->setPosition($position * 10);
         $this->em->persist($entity);
         $position++;
     }
     $this->em->flush();
 }
开发者ID:lexinek,项目名称:doctrine-behaviors,代码行数:11,代码来源:Organiser.php

示例3: renderDefault

 public function renderDefault($id)
 {
     if (!is_null($id)) {
         $search = $this->em->find(Search::getClassName(), $id);
         if (!$search) {
             $this->flashMessage('Data not found for this id', 'error');
             $this->redirect('Homepage:');
         }
     } else {
         $this->flashMessage('Data not found for this id', 'error');
     }
     $this->template->search = $search;
 }
开发者ID:tkliner,项目名称:etn-github,代码行数:13,代码来源:ShowSearch.php

示例4: createRole

 /**
  * @param array $values
  * @return Role
  * @throws RoleAlreadyExistsException
  * @throws RoleMissingException
  */
 public function createRole(array $values)
 {
     $parentRole = null;
     if ($values['parent'] !== null) {
         $parentRole = $this->em->find(Role::class, $values['parent']);
         if ($parentRole === null) {
             throw new RoleMissingException();
         }
     }
     $role = new Role($values['name'], $parentRole);
     $role = $this->em->safePersist($role);
     if ($role === false) {
         throw new RoleAlreadyExistsException();
     }
     $this->onSuccessRoleCreation($role);
     return $role;
 }
开发者ID:blitzik,项目名称:CMS,代码行数:23,代码来源:RolePersister.php

示例5: save

 /**
  * @param array $values
  * @param Page|null $page
  * @return Page
  * @throws PagePublicationTimeException
  * @throws PagePublicationTimeMissingException
  * @throws UrlAlreadyExistsException
  * @throws LocaleNotFoundException
  * @throws PageTitleAlreadyExistsException
  * @throws PageIntroHtmlLengthException
  * @throws \Exception
  */
 public function save(array $values, Page $page = null)
 {
     foreach ($values as $k => $v) {
         $values[$k] = $v === '' ? null : $v;
     }
     if ($values['publishedAt'] === null and $values['saveAsDraft'] === false) {
         throw new PagePublicationTimeMissingException();
     }
     $values['author'] = $this->em->find(User::class, $values['author']->getId());
     try {
         if ($page !== null and $page->getId() !== null) {
             $wasDraft = $page->isDraft();
             $hadOpenedComments = $page->getAllowedComments();
             $this->updatePage($page, $values);
             $this->onSuccessPageEditing($page);
         } else {
             $wasDraft = true;
             $hadOpenedComments = true;
             $page = $this->createNewPage($values, $page);
             $this->onSuccessPageCreation($page);
         }
         if ($wasDraft !== $page->isDraft() and $wasDraft === true) {
             $this->onPageRelease($page);
         }
         if ($hadOpenedComments !== $page->getAllowedComments()) {
             if ($hadOpenedComments === true) {
                 $this->onPageCommentsClosure($page);
             } else {
                 $this->onPageCommentsOpening($page);
             }
         }
     } catch (UrlAlreadyExistsException $u) {
         $this->closeEntityManager();
         throw $u;
     } catch (PageTitleAlreadyExistsException $p) {
         $this->closeEntityManager();
         throw $p;
     } catch (\Exception $e) {
         $this->closeEntityManager();
         throw $e;
     }
     return $page;
 }
开发者ID:blitzik,项目名称:CMS,代码行数:55,代码来源:PagePersister.php

示例6: getRole

 /**
  * @param $roleId
  * @param ValidationObject $validationObject
  * @return Role
  */
 private function getRole($roleId, ValidationObject $validationObject)
 {
     /** @var Role $role */
     $role = $this->em->find(Role::class, $roleId);
     if ($role === null) {
         //throw new RoleMissingException;
         $validationObject->addError('users.user.form.messages.missingRole', FlashMessage::WARNING);
     }
     return $role;
 }
开发者ID:blitzik,项目名称:CMS,代码行数:15,代码来源:UserPersister.php

示例7: save

 /**
  * @param Role $role
  * @param array $permissionDefinitions
  * @throws DBALException
  * @throws \Exception
  */
 public function save(Role $role, array $permissionDefinitions)
 {
     $resources = $this->em->createQuery('SELECT r FROM ' . Resource::class . ' r INDEX BY r.id')->execute();
     $privileges = $this->em->createQuery('SELECT p FROM ' . Privilege::class . ' p INDEX BY p.id')->execute();
     try {
         $this->em->beginTransaction();
         $this->em->createQuery('DELETE ' . Permission::class . ' p
              WHERE p.role = :role')->execute(['role' => $role->getId()]);
         $parentRole = null;
         if ($role->hasParent()) {
             /** @var Role $parentRole */
             $parentRole = $this->em->find(Role::class, $role->getParentId());
         }
         foreach ($permissionDefinitions as $definition => $isAllowed) {
             $isAllowed = (bool) $isAllowed;
             $x = explode('-', $definition);
             // eg. 1-3
             /** @var \Users\Authorization\Resource $resource */
             $resource = $resources[$x[0]];
             /** @var Privilege $privilege */
             $privilege = $privileges[$x[1]];
             // check Users\Authorization\Authorizator ACL assembling
             // Role without parent
             // privilege: allowed -> must be in database
             // privilege: denied  -> does NOT have to be in database
             // Role with parent (all depths)
             /*
                               ------------------------------------------------------------
                                  parent    |    descendant    |    should be persisted?
                               ------------------------------------------------------------
                                  allowed         allowed                  NO
                                  allowed         denied                  YES
                                  denied          denied                  NO
                                  denied          allowed                 YES
                               ------------------------------------------------------------
                                 We save records where permission and denial differ
             */
             if ($parentRole !== null) {
                 // has parent
                 if ($this->authorizator->isAllowed($parentRole, $resource->getName(), $privilege->getName()) === $isAllowed) {
                     continue;
                 }
             } else {
                 // doesn't have parent
                 if ($isAllowed === false) {
                     continue;
                 }
             }
             $permission = new Permission($role, $resource, $privilege, $isAllowed);
             $this->em->persist($permission);
         }
         $this->em->flush();
         $this->em->commit();
         $this->cache->remove('acl');
         $this->onSuccessRolePermissionsEditing($role);
     } catch (\Exception $e) {
         $this->em->rollback();
         $this->em->close();
         // todo log error
         throw new $e();
     }
 }
开发者ID:blitzik,项目名称:CMS,代码行数:68,代码来源:RolePermissionsPersister.php

示例8: findById

 /**
  * Find entity by ID.
  * @param string $entityName
  * @param int $id
  * @return object
  */
 protected function findById($entityName, $id)
 {
     return $this->entityManager->find($entityName, $id);
 }
开发者ID:frosty22,项目名称:ale,代码行数:10,代码来源:Presenter.php


注:本文中的Kdyby\Doctrine\EntityManager::find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。