@param int    $id
@param string $class

@return LockableEntity
555060
public function getOrCreate($id, $class)
    {
        /** @var LockableEntity $lockable */
        $lockable = $this->findOneBy(['entityId' => $id, 'entityClass' => $class]);

        if ($lockable === null) {
            $lockable = new LockableEntity();
            $lockable->setEntityClass($class);
            $lockable->setEntityId($id);
        }

        return $lockable;
    }
1079339
public function removeClass($id)
    {
        if (isset($this->classes[$id])) {
            unset($this->classes[$id]);
        }
        if (isset($this->items[$id])) {
            unset($this->items[$id]);
        }
        return $this;
    }
344910
public function setDatatableId($id)
    {
        if (!array_key_exists($id, self::$_instances))
        {
            self::$_instances[$id] = $this;
        }
        else
        {
            throw new \Exception('Identifer already exists');
        }
        return $this;
    }
682075
public function dsql($class = null)
    {
        $class = $class ?: $this->dsql_class;
        $obj = $this->add($class);
        if (!$obj instanceof DB_dsql) {
            throw $this->exception('Specified class must be descendant of DB_dsql')
                ->addMoreInfo('class', $class);
        }

        return $obj;
    }
363682
private static function key($class, array $id)
    {
        $class = strtolower(ltrim($class, '\\'));
        ksort($id);

        $key = '';
        foreach ($id as $prop => $val) {
            if ($key) {
                $key .= ';';
            }
            $key .= "{$prop}:{$val}";
        }

        return $class . '@' . $key;
    }
349067
public static function factory ($id)
    {
        // Which class to instantiate
        $entityClassName = get_called_class();

        // Get object cache registry
        $ObjectRegistry  = \Teon\ObjectRegistry\ObjectRegistry::getInstance();

        // If this object already in cache, use that
        if ($ObjectRegistry->exists($entityClassName, $id)) {
            return $ObjectRegistry->get($entityClassName, $id);
        }

        // If not, instantiate new, store in object registry and return it
        $Object = new $entityClassName($id);
        $ObjectRegistry->store($Object);
        return $Object;
    }
686604
public function findByIds($class, array $ids)
    {
        if (count($ids) === 0) {
            return array();
        }

        $dql = "SELECT object FROM {$class} object WHERE object.id IN (:ids)";
        $query = $this->wrapped->createQuery($dql);
        $query->setParameter('ids', $ids);
        $objects = $query->getResult();

        if (($entityCount = count($objects)) !== ($idCount = count($ids))) {
            throw new MissingObjectException(
                "{$entityCount} out of {$idCount} ids don't match any existing object"
            );
        }

        return $objects;
    }
1218140
public static function classAttributeIdentifierByID( $id )
    {
        $identifierHash = array_flip( self::classAttributeIdentifiersHash() );

        if ( isset( $identifierHash[$id] ) )
        {
            $classAndClassAttributeIdentifier = explode( '/', $identifierHash[$id] );
            return $classAndClassAttributeIdentifier[1];
        }
        else
            return false;
    }
351224
public function find(string $modelClass, string $id = null)
    {
        if (null === $id) {
            return null;
        }

        return $this->getRepositoryByClass($modelClass)->find($id);
    }
246052
public function removeUsersAction($id, $class, Request $request)
    {
        $object = $this->find($class, $id);
        $users = $this->decodeIdsString($request, 'Claroline\CoreBundle\Entity\User');
        $this->crud->patch($object, 'user', Crud::COLLECTION_REMOVE, $users);

        return new JsonResponse(
            $this->serializer->serialize($object)
        );
    }
300038
public static function getLock($id) {

        $model = get_called_class();
        /* @var $t Record */
        $t = new $model;
        $select = DB::select($t->getTable())->where($t->getPkField(), $id)->lock()->setRecord($model);
        Event::trigger('record_before_select', [$t, $select]);
        $data = $select->find();
        return $data;
    }
662810
public function flattenIdentifier(ClassMetadata $class, array $id)
    {
        $flatId = [];

        foreach ($class->identifier as $field) {
            $property = $class->getProperty($field);

            if ($property instanceof FieldMetadata) {
                $flatId[$field] = $id[$field];

                continue;
            }

            if (isset($id[$field]) && is_object($id[$field])) {
                /** @var ClassMetadata $targetClassMetadata */
                $targetClassMetadata  = $this->metadataFactory->getMetadataFor($property->getTargetEntity());
                $targetClassPersister = $this->unitOfWork->getEntityPersister($property->getTargetEntity());
                // @todo guilhermeblanco Bring this back:
                // $identifiers         = $this->unitOfWork->isInIdentityMap($id[$field])
                //     ? $this->unitOfWork->getEntityIdentifier($id[$field])
                //     : $targetClassPersister->getIdentifier($id[$field])
                // ;
                $identifiers = $targetClassPersister->getIdentifier($id[$field]);

                $associatedId = $this->flattenIdentifier($targetClassMetadata, $identifiers);

                $flatId[$field] = implode(' ', $associatedId);

                continue;
            }

            $associatedId = [];

            foreach ($property->getJoinColumns() as $joinColumn) {
                $associatedId[] = $id[$joinColumn->getColumnName()];
            }

            $flatId[$field] = implode(' ', $associatedId);
        }

        return $flatId;
    }
222269
public function getClass($id)
    {
        return isset($this->classes[$id]) ? $this->classes[$id] : null;
    }
1334436
public function has($class, $entityId)
    {
        try {
            $em = $this->entityManager->getDoctrineEntityManager();
            $data = $em->getRepository($class)->findOneBy(array(
                'id' => $entityId,
            ));
             
            if ($data !== null) {
                return true;
            }
             
            return false;
        } catch (\Exception $e) {
            throw new Exception('Cannot check if there is an access entitiy for the given class "' . $class . '" and id "' . $entityId . '".', 0, $e);
        }
    }
1125262
public function findById($class, $id) {
        $mapper = MapperBuilder::buildFromMapping($this->mapping, $class);

        $newEntity = NULL;

        $query = "SELECT * FROM `" . $mapper->getTable() . "` WHERE id='$id'";
        $result = $this->conn->executeQuery($query);

        if ($result) {
            $class = $mapper->getClass();
            $newEntity = new $class();
            $this->populateEntity($newEntity, $result[0], $mapper);

            // populate relations
            foreach ($mapper->getRelations() as $relation) {

                $relMapper = MapperBuilder::buildFromName($this->mapping, $relation->getEntity());
                $queryRel = $this->buildSelectRelation($newEntity, $mapper, $relation, $relMapper);
                $resRel = $this->conn->executeQuery($queryRel);

                $classRel = $relMapper->getClass();
                $method = "set" . $relation->getName();
                if ($resRel) {
                    foreach ($resRel as $row) {
                        $newEntityRel = new $classRel();
                        $this->populateEntity($newEntityRel, $row, $relMapper, $relation->getForeignColumn());
                        $array[] = $newEntityRel;
                    }
                    $newEntity->$method($array);
                }
            }
        }
        return $newEntity;
    }
220033
final public function set(?string $id, string $class = null): ServiceConfigurator
    {
        $defaults = $this->defaults;
        $allowParent = !$defaults->getChanges() && empty($this->instanceof);

        $definition = new Definition();

        if (null === $id) {
            if (!$class) {
                throw new \LogicException('Anonymous services must have a class name.');
            }

            $id = sprintf('.%d_%s', ++$this->anonymousCount, preg_replace('/^.*\\\\/', '', $class).'~'.$this->anonymousHash);
            $definition->setPublic(false);
        } else {
            $definition->setPublic($defaults->isPublic());
        }

        $definition->setAutowired($defaults->isAutowired());
        $definition->setAutoconfigured($defaults->isAutoconfigured());
        $definition->setBindings($defaults->getBindings());
        $definition->setChanges([]);

        $configurator = new ServiceConfigurator($this->container, $this->instanceof, $allowParent, $this, $definition, $id, $defaults->getTags(), $this->path);

        return null !== $class ? $configurator->class($class) : $configurator;
    }
59296
public function getEntity($className, $id)
    {
        if (isset($this->entities[$className]) && isset($this->entities[$className][$id])) {
            return $this->entities[$className][$id];
        }

        if (isset($this->stashedEntities[$className]) && isset($this->stashedEntities[$className][$id])) {
            return $this->stashedEntities[$className][$id];
        }

        return null;
    }