FOF30\View\View::__construct PHP Method

__construct() public method

The $config array can contain the following overrides: name string The name of the view (defaults to the view class name) template_path string The path of the layout directory layout string The layout for displaying the view viewFinder ViewTemplateFinder The object used to locate view templates in the filesystem viewEngineMap array Maps view template extensions to view engine classes
public __construct ( Container $container, array $config = [] ) : View
$container FOF30\Container\Container The container we belong to
$config array The configuration overrides for the view
return View
    public function __construct(Container $container, array $config = array())
    {
        $this->container = $container;
        $this->config = $config;
        // Get the view name
        if (isset($this->config['name'])) {
            $this->name = $this->config['name'];
        }
        $this->name = $this->getName();
        // Set the default template search path
        if (array_key_exists('template_path', $this->config)) {
            // User-defined dirs
            $this->setTemplatePath($this->config['template_path']);
        } else {
            $this->setTemplatePath($this->container->thisPath . '/View/' . ucfirst($this->name) . '/tmpl');
        }
        // Set the layout
        if (array_key_exists('layout', $this->config)) {
            $this->setLayout($this->config['layout']);
        }
        // Apply the viewEngineMap
        if (isset($config['viewEngineMap'])) {
            if (!is_array($config['viewEngineMap'])) {
                $temp = explode(',', $config['viewEngineMap']);
                $config['viewEngineMap'] = array();
                foreach ($temp as $assignment) {
                    $parts = explode('=>', $assignment, 2);
                    if (count($parts) != 2) {
                        continue;
                    }
                    $parts = array_map(function ($x) {
                        return trim($x);
                    }, $parts);
                    $config['viewEngineMap'][$parts[0]] = $parts[1];
                }
            }
            $this->viewEngineMap = array_merge($this->viewEngineMap, $config['viewEngineMap']);
        }
        // Set the ViewFinder
        $this->viewFinder = $this->container->factory->viewFinder($this);
        if (isset($config['viewFinder']) && !empty($config['viewFinder']) && is_object($config['viewFinder']) && $config['viewFinder'] instanceof ViewTemplateFinder) {
            $this->viewFinder = $config['viewFinder'];
        }
        // Apply the registered view template extensions to the view finder
        $this->viewFinder->setExtensions(array_keys($this->viewEngineMap));
        // Apply the base URL
        $this->baseurl = $this->container->platform->URIbase();
    }

Usage Example

Esempio n. 1
0
 /**
  * Assigns callback functions to the class, the $methods array should be an associative one, where
  * the keys are the method names, while the values are the closure functions, e.g.
  *
  * array(
  *    'foobar' => function(){ return 'Foobar'; }
  * )
  *
  * @param           $container
  * @param array     $config
  * @param array     $methods
  */
 public function __construct(Container $container, array $config = array(), array $methods = array())
 {
     foreach ($methods as $method => $function) {
         $this->methods[$method] = $function;
     }
     parent::__construct($container, $config);
 }
All Usage Examples Of FOF30\View\View::__construct