PHP Classes
elePHPant
Icontem

File: src/View/Namespaces.php

Recommend this page to a friend!
  Classes of Thierry Feuzeu  >  Jaxon Sentry  >  src/View/Namespaces.php  >  Download  
File: src/View/Namespaces.php
Role: Class source
Content type: text/plain
Description: Class source
Class: Jaxon Sentry
Common classes for Jaxon based Ajax applications
Author: By
Last change:
Date: 2 years ago
Size: 1,995 bytes
 

 

Contents

Class file image Download
<?php

/**
 * Namespaces.php - A trait for managing namespaces in view/template renderers.
 *
 * @package jaxon-sentry
 * @author Thierry Feuzeu <thierry.feuzeu@gmail.com>
 * @copyright 2016 Thierry Feuzeu <thierry.feuzeu@gmail.com>
 * @license https://opensource.org/licenses/BSD-3-Clause BSD 3-Clause License
 * @link https://github.com/jaxon-php/jaxon-sentry
 */

namespace Jaxon\Sentry\View;

trait
Namespaces
{
   
/**
     * The template directories
     *
     * @var array
     */
   
protected $aDirectories = array();

   
/**
     * The directory of the current template
     *
     * @var string
     */
   
protected $sDirectory = '';

   
/**
     * The extension of the current template
     *
     * @var string
     */
   
protected $sExtension = '';

   
/**
     * Add a namespace to this template 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->aDirectories[$sNamespace] = array('path' => $sDirectory, 'ext' => $sExtension);
    }

   
/**
     * Find the namespace of the template being rendered
     *
     * @param string $sNamespace The namespace name
     *
     * @return void
     */
   
public function setCurrentNamespace($sNamespace)
    {
       
$this->sDirectory = '';
       
$this->sExtension = '';
        if(
key_exists($sNamespace, $this->aDirectories))
        {
           
// Make sure there's only one '/' at the end of the string
           
$this->sDirectory = rtrim($this->aDirectories[$sNamespace]['path'], '/') . '/';
           
// Make sure there's only one '.' at the beginning of the string
           
$this->sExtension = '.' . ltrim($this->aDirectories[$sNamespace]['ext'], '.');
        }
    }
}