PHP Classes

File: src/View.php

Recommend this page to a friend!
  Classes of Thierry Feuzeu   Jaxon for Symfony   src/View.php   Download  
File: src/View.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Jaxon for Symfony
Jaxon integration for the Symfony framework
Author: By
Last change: Fixed typo in variable name.
Merge pull request #9 from jaxon-php/develop

Merge
Added parameter types for functions and vars.
Merge branch 'master' into develop
Fixed class declaration.
- upgrade symfony version constraint
- add some more folder to .gitignore for other IDE
- remove alias function and replace with origin php function
Adapted to the new class hierarchy is jaxon-core.
Date: 2 years ago
Size: 1,718 bytes
 

Contents

Class file image Download
<?php

namespace Jaxon\AjaxBundle;

use
Jaxon\Utils\View\Store;
use
Jaxon\Contracts\View as ViewContract;

use
Twig\Environment;

class
View implements ViewContract
{
   
/**
     * The Twig template renderer
     *
     * @var Environment
     */
   
protected $xRenderer;

   
/**
     * The view namespaces
     *
     * @var array
     */
   
protected $aNamespaces = [];

   
/**
     * The constructor
     *
     * @param Environment $xRenderer
     */
   
public function __construct(Environment $xRenderer)
    {
       
$this->xRenderer = $xRenderer;
    }

   
/**
     * Add a namespace to this view renderer
     *
     * @param string $sNamespace The namespace name
     * @param string $sDirectory The namespace directory
     * @param string $sExtension The extension to append to template names
     *
     * @return void
     */
   
public function addNamespace($sNamespace, $sDirectory, $sExtension = '')
    {
       
$this->aNamespaces[$sNamespace] = [
           
'directory' => $sDirectory,
           
'extension' => $sExtension,
        ];
    }

   
/**
     * Render a view
     *
     * @param Store $store A store populated with the view data
     *
     * @return string The string representation of the view
     */
   
public function render(Store $store)
    {
       
$sExtension = '';
        if(
array_key_exists($store->getNamespace(), $this->aNamespaces))
        {
           
$sExtension = $this->aNamespaces[$store->getNamespace()]['extension'];
        }
       
// Render the template
       
return trim($this->xRenderer->render($store->getViewName() . $sExtension, $store->getViewData()), " \t\n");
    }
}