Determines what template should be used to
render the view. Template is determined
by the type of entity.

@param Entity $entity
@param array  $params The view params

@return View

@throws \LogicException
320152
protected function getView(Entity $entity, array $params = [])
    {
        switch (true) {
            case $entity instanceof ContentItem:
                $template = $entity->isIndex() ? 'index.twig' : 'entry.twig';
                $params['entry'] = $entity;
                break;
            case $entity instanceof Taxonomy:
                $template = 'taxonomy.twig';
                $params['taxonomy'] = $entity;
                break;
            case $entity instanceof Term:
                $template = 'term.twig';
                $params['term'] = $entity;
                break;
            default:
                throw new \LogicException('Cannot render entity of type '.get_class($entity));
        }

        return new View($template, $params);
    }
1349610
public function generateBody(Entity $entity)
    {
        $lines      = [];
        $descriptor = $entity->getDescriptor();
        $class      = $entity->getNamespacedName();
        $fields     = $descriptor->getFieldList() ?: [];
        $message    = var_export("Argument 1 passed to %s must be a %s, %s given", true);
        $exception  = 'sprintf(' . $message . ', __METHOD__, __CLASS__, get_class($message))';

        $lines[] = 'if ( ! $message instanceof ' . $class . ') {';
        $lines[] = '    throw new \InvalidArgumentException(' . $exception . ');';
        $lines[] = '}';
        $lines[] = null;

        foreach ($fields as $field) {
            $item  = $this->generateFieldMerge($entity, $field);
            $lines = array_merge($lines, $item);
        }

        return $lines;
    }
280408
protected function buildMetadata($entity, $rawData = null)
    {
        $metadata = new ClassMetadata(get_class($entity));

        try {
            $template = $this->chooser->record($entity, $rawData);
            $template = $this->twig->resolveTemplate($template)->getSourceContext()->getName();
        } catch (LoaderError $e) {
            $template = null;
        }

        if ($template && isset($this->mapping['config'][$template])) {
            $mappings = $this->em->getMapper()->loadMetadataForFields($this->mapping['config'][$template]['fields']);
            $metadata->setFieldMappings((array) $mappings);
        }

        return $metadata;
    }
281421
public function onKernelView(GetResponseForControllerResultEvent $event)
    {
        /* @var Template $template */
        $request = $event->getRequest();
        $template = $request->attributes->get('_template');

        if (!$template instanceof Template) {
            return;
        }

        if (null === $this->twig) {
            throw new \LogicException('You can not use the "@Template" annotation if the Twig Bundle is not available.');
        }

        $parameters = $event->getControllerResult();
        $owner = $template->getOwner();
        list($controller, $action) = $owner;

        // when the annotation declares no default vars and the action returns
        // null, all action method arguments are used as default vars
        if (null === $parameters) {
            $parameters = $this->resolveDefaultParameters($request, $template, $controller, $action);
        }

        // attempt to render the actual response
        if ($template->isStreamable()) {
            $callback = function () use ($template, $parameters) {
                $this->twig->display($template->getTemplate(), $parameters);
            };

            $event->setResponse(new StreamedResponse($callback));
        } else {
            $event->setResponse(new Response($this->twig->render($template->getTemplate(), $parameters)));
        }

        // make sure the owner (controller+dependencies) is not cached or stored elsewhere
        $template->setOwner([]);
    }
209575
public function transform($name, $entity, array $params = array()) {
        $transformer = $this->transformers[$name];

        if (!is_object($entity) || !$transformer->isCached()) {
            return $transformer->transform($entity, $params);
        }

        $id = spl_object_hash($entity) . '-' . spl_object_hash($this->groupContext);
        if ($this->arrayCache->contains($id)) {
            return $this->arrayCache->fetch($id);
        }
        $transformation = $transformer->transform($entity, $params);
        $this->arrayCache->save($id, $transformation);

        return $transformation;
    }
954737
protected function generateFields(Entity $entity)
    {
        $properties = [];
        $descriptor = $entity->getDescriptor();
        $fields     = $descriptor->getFieldList() ?: [];
        $extensions = $descriptor->getExtensionList() ?: [];

        $properties[] = PropertyGenerator::fromArray([
            'name'       => $this->getUniqueFieldName($descriptor, 'unknownFieldSet'),
            'visibility' => PropertyGenerator::VISIBILITY_PROTECTED,
            'docblock'   => [
                'tags'   => [
                    [
                        'name'        => 'var',
                        'description' => '\Protobuf\UnknownFieldSet',
                    ]
                ]
            ]
        ]);

        $properties[] = PropertyGenerator::fromArray([
            'name'       => $this->getUniqueFieldName($descriptor, 'extensions'),
            'visibility' => PropertyGenerator::VISIBILITY_PROTECTED,
            'docblock'   => [
                'tags'   => [
                    [
                        'name'        => 'var',
                        'description' => '\Protobuf\Extension\ExtensionFieldMap',
                    ]
                ]
            ]
        ]);

        foreach ($fields as $field) {
            $properties[] = $this->generateField($entity, $field);
        }

        return $properties;
    }
654492
protected function _checkEntity($entity)
    {
        if (!$entity instanceof ArrayAccess && !is_array($entity)) {
            throw new RuntimeException(sprintf(
                'Route `%s` expects the URL option `_entity` to be an array or object implementing \ArrayAccess, but `%s` passed.',
                $this->template,
                getTypeName($entity)
            ));
        }
    }
196495
public function EntityContexts( $entity, $scheme = null )
	{
		$filtered = array_filter( $this->contexts, function ( $context ) use( $entity, $scheme ) {

			// The context may be invalid in which case exclude
			if ( ! isset( $context['entity']['identifier']['value'] ) ) return false;

			if ( $context['entity']['identifier']['value'] == $entity )
			{
				// If supplied also check the scheme
				return $scheme != null && isset( $context['entity']['identifier']['scheme'] )
				? ( strtolower( $scheme ) == strtolower( $context['entity']['identifier']['scheme'] ) )
				: true;
			}

			return false;
		} );

		return new ContextsFilter( $this->instance, $filtered );
	}
287260
public function template($name, array $params = []): ResponseInterface
    {
        if (\is_array($name)) {
            $params = $name;
            $name = null;
        }

        if ($name === null) {
            $handler = $this->app->handler();
            if ($handler instanceof \Closure) {
                throw new \LogicException('Con not build the template from closure handler!');
            }

            $name = \ltrim($handler['app'] . '/' . $handler['controller'] . '/' . $handler['action'], '/');
        } elseif (!\is_string($name)) {
            throw new \InvalidArgumentException('Template name not found!');
        }

        $response = $this->response();

        return $this->app->render($response, $name, $params);
    }
976426
public function execute($entity, $method = 'get', $options = [])
    {

        $this->cleanQueryParams($entity);
        $configuration = $this->_getEntityConfiguration($entity);

        if ($method != 'get'){
            foreach ($configuration->attributes as $key => $attribute) {
                $this->validateAttribute($entity, $key, ['required']);
            } 
        }

        $this->processOptions($options, $configuration);

        $this->_setDefaultHeaders($configuration->query);
        $this->_setCustomHeaders($entity, $configuration->query);
        //$this->_setIdempotencyHeader($configuration->query, $configuration, $method);
        $this->setQueryParams($entity);
        
        return $this->_client->{$method}($configuration->url, $configuration->query);
    }
934906
public function formList($entity)
    {
        if ($entity = Entity::fromYamlFile($entity)) {
            $list = new FormList($entity);

            return $list->view();
        } else {
            abort(404);
        }
    }
261498
public function fill(EntityContract $entity, $parameters)
    {
        $result = new Result();

        foreach ($this->getAttributes() as $attribute) {
            $result->addErrors($attribute->update($entity, $parameters));
        }

        return $result;
    }
618002
public function page($entity) {
		if ($entity->type !== 'namespace') {
			return false;
		}
		return Pages::find('first', [
			'conditions' => [
				'index' => $entity->index,
				'name' => $entity->name
			]
		]);
	}
64368
private function filterFields(\stdClass $params, ApiInterface $entity, $isCreating) {
        $automaticFields = $this->lookUpAutomaticFields($entity, $isCreating);
        $customParentRelationshipFields = [];
        foreach($entity->getCustomParentRelationships() as $customParentRelationshipField) {
            $customParentRelationshipFields[] = $customParentRelationshipField->getFields();
        }
        $fields = array();
        foreach($params as $key => $value) {
            if(!(is_object($value) && get_class($value) == 'stdClass')) {
                if(array_key_exists($key, $entity->getChildrenUpdaters())) {
                    $fields[$key] = $value;
                } elseif(in_array($key, $entity->getModelsMetaData()->getColumnMap($entity)) || in_array($key, $customParentRelationshipFields)) {
                    if(array_key_exists($key, $automaticFields) && $entity->readAttribute($key) != $value) {
                        throw new Exception('The field of: ' . $key . ' cannot be manually updated', 409);
                    }
                    $fields[$key] = $value;
                } else {
                    throw new Exception('Could not find the field: ' . $key, 400);
                }
            }
        }
        return $fields;
    }
451967
public function createForm($entity, $options = [])
    {
        $options = array_merge($this->type()['formFields']['_create'], $options);

        return $this->Form->create($entity, $options);
    }
47650
public function applyView($view_path, array $params)
    {
        $out = $this->_container
                ->get('templating')
                ->render($view_path, $params);
        return html_entity_decode($out);
    }
1345472
protected function parseToDocument($entity)
    {
        $schemaMapper = $this->getSchemaMapper();
        $parsedDocument = $schemaMapper->map($entity);

        if (is_object($entity)) {
            foreach ($parsedDocument as $field => $value) {
                $entity->$field = $value;
            }
        }

        return $parsedDocument;
    }