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();
}