@param string $class
@param Entity $entity

@return string
15838
protected function generateFileContent($class, $entity)
    {
        $generator  = new FileGenerator();
        $descriptor = $entity->getFileDescriptor();

        $generator->setClass($class);
        $generator->setDocblock(DocBlockGenerator::fromArray(array(
            'shortDescription' => 'Generated by Protobuf protoc plugin.',
            'longDescription'  => 'File descriptor : ' . $descriptor->getName(),
        )));

        return $generator->generate();
    }
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;
    }
105088
private function persistNew($class, $entity)
    {
        $oid    = spl_object_hash($entity);
        $invoke = $this->listenersInvoker->getSubscribedSystems($class, Events::prePersist);

        if ($invoke !== ListenersInvoker::INVOKE_NONE) {
            $this->listenersInvoker->invoke($class, Events::prePersist, $entity, new LifecycleEventArgs($entity, $this->em), $invoke);
        }

        $idGen = $class->idGenerator;

        if ( ! $idGen->isPostInsertGenerator()) {
            $idValue = $idGen->generate($this->em, $entity);

            if ( ! $idGen instanceof \Doctrine\ORM\Id\AssignedGenerator) {
                $idValue = array($class->identifier[0] => $idValue);

                $class->setIdentifierValues($entity, $idValue);
            }

            $this->entityIdentifiers[$oid] = $idValue;
        }

        $this->entityStates[$oid] = self::STATE_MANAGED;

        $this->scheduleForInsert($entity);
    }
571168
private function newInstance($class)
    {
        $entity = $class->newInstance();

        if ($entity instanceof \Doctrine\Common\Persistence\ObjectManagerAware) {
            $entity->injectObjectManager($this->em, $class);
        }

        return $entity;
    }
1029403
def _get_entity_by_class(self, entity_cls):
        """"""
        entity_qualname = fully_qualified_name(entity_cls)
        if entity_qualname in self._registry:
            return self._registry[entity_qualname]
        else:
            return self._find_entity_in_records_by_class_name(entity_cls.__name__)
819193
public function getPersister($class)
    {
        if (!array_key_exists($class, $this->persisters)) {
            $classMetadata = $this->entityManager->getClassMetadataFor($class);
            $this->persisters[$class] = new EntityPersister($this->entityManager, $class, $classMetadata);
        }

        return $this->persisters[$class];
    }
796917
public function createDeleteForm($entity, $entityClass)
    {
        return $this->createIdForm($entity, 'delete_', $this->adminRouter->generate($entity, $entityClass, AdminRouter::TYPE_DELETE));
    }
523286
public function transform($entity) {
    if ($entity === NULL) {
      return NULL;
    }

    $getter = 'get'.ucfirst($this->identifierName);

    return array(
      '__class' => $this->entityClass, // just for verbose
      $this->identifierName => $entity->$getter()
    );
  }
1207323
public function get(string $class, string $identity)
    {
        if (!$this->has($class, $identity)) {
            return null;
        }

        return $this->entities["{$class}:{$identity}"];
    }
1254755
public function generateBody(Entity $entity)
    {
        $body       = [];
        $descriptor = $entity->getDescriptor();
        $fields     = $descriptor->getFieldList() ?: [];

        foreach ($fields as $field) {
            if ( ! $field->hasDefaultValue()) {
                continue;
            }

            $name  = $field->getName();
            $value = $this->getDefaultFieldValue($field);

            $body[] = sprintf('$this->%s = %s;', $name, $value);
        }

        $body[] = null;
        $body[] = 'parent::__construct($stream, $configuration);';

        return $body;
    }
475090
public function getDocumentIndex($entity)
    {
        $annotation = $this->getClassAnnotation($entity, self::DOCUMENT_CLASS);
        if (!$annotation instanceof Document) {
            return null;
        }

        $indexHandler = $annotation->indexHandler;
        if ($indexHandler != '' && method_exists($entity, $indexHandler)) {
            return $entity->$indexHandler();
        }

        return $annotation->getIndex();
    }
824220
private function getHeaders(Entity $entity)
    {
        yield 'ccm_date_created' => 'dateCreated';

        $attributes = $entity->getAttributes();
        foreach ($attributes as $attribute) {
            yield $attribute->getAttributeKeyHandle() => $attribute->getAttributeKeyDisplayName();
        }
    }
92069
private static function makeObject($entity)
    {
        $methodsGet = get_class_methods($entity);
        $methodsGet = array_filter($methodsGet, function($value) {
            return (bool) preg_match('/^get.*$/', $value);
        });
        $std = new \stdClass();
        foreach ($methodsGet as $attribute) {
            $name = str_replace('get', '', $attribute);
            $name = lcfirst($name);
            $std->$name = $entity->$attribute();
        }
        return $std;
    }
1204038
protected function loadEntityClass(Entity $entity)
    {
        $type    = $entity->getType();
        $content = $entity->getContent();
        $class   = $entity->getNamespacedName();

        if (class_exists($class) || interface_exists($class)) {
            return false;
        }

        $this->logger->info(sprintf('Loading class "%s"', $class));

        $tempname = tempnam(sys_get_temp_dir(), 'proto') . '.php';

        file_put_contents($tempname, $content);

        include($tempname);
        @unlink($tempname);

        if ($type === Entity::TYPE_EXTENSION) {

            $this->logger->info(sprintf('Registering extension "%s"', $class));

            $config   = $this->config;
            $registry = $config->getExtensionRegistry();

            $class::registerAllExtensions($registry);

            return true;
        }

        return false;
    }
1127915
protected function getEntityName($entityClassName)
    {
        preg_match_all('/\\\([a-zA-Z]+)/', $entityClassName, $matches);
        if (!empty($matches[1])) {
            return $matches[1][count($matches[1]) - 1];
        }
        return $entityClassName;
    }
1137905
public function generateBody(Entity $entity)
    {
        $lines      = [];
        $addLine    = false;
        $descriptor = $entity->getDescriptor();
        $fields     = $descriptor->getFieldList() ?: [];
        $defaults   = $this->generateDefaultValues($entity);

        foreach ($fields as $field) {
            if ($field->getLabel() !== Label::LABEL_REQUIRED()) {
                continue;
            }

            if ($field->hasDefaultValue()) {
                continue;
            }

            $item  = $this->generateRequiredFieldException($entity, $field);
            $lines = array_merge($lines, $item, [null]);
        }

        $lines[] = '$message = new self();';
        $lines[] = '$values  = array_merge([';
        $lines   = array_merge($lines, $this->addIndentation($defaults, 1));
        $lines[] = '], $values);';
        $lines[] = null;

        foreach ($fields as $field) {
            if ($field->getLabel() === Label::LABEL_REPEATED()) {
                continue;
            }

            $item  = $this->generateSetValue($entity, $field);
            $lines = array_merge($lines, $item);

            $addLine = true;
        }

        if ($addLine) {
            $lines[] = null;
        }

        foreach ($fields as $field) {
            if ($field->getLabel() !== Label::LABEL_REPEATED()) {
                continue;
            }

            $item  = $this->generateAddValue($entity, $field);
            $lines = array_merge($lines, $item, [null]);
        }

        $lines[] = 'return $message;';

        return $lines;
    }
902794
public function getByEntity($entityClass, $id, $locale, $object = null)
    {
        $metadata = $this->structureMetadataFactory->getStructureMetadata('page', $object->getStructureType());

        return [
            '_controller' => $metadata->getController(),
            'view' => $metadata->getView(),
            'object' => $object,
            'structure' => $this->documentToStructure($object),
        ];
    }