icingaweb2/library/Icinga/Web/View.php

131 lines
3.3 KiB
PHP
Raw Normal View History

2013-07-12 14:33:17 +02:00
<?php
2013-08-20 19:26:44 +02:00
// {{{ICINGA_LICENSE_HEADER}}}
/**
2013-10-23 15:10:33 +02:00
* This file is part of Icinga Web 2.
2013-08-20 19:26:44 +02:00
*
2013-10-23 15:10:33 +02:00
* Icinga Web 2 - Head for multiple monitoring backends.
2013-08-20 19:26:44 +02:00
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
2013-10-23 15:10:33 +02:00
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*
2013-08-20 19:26:44 +02:00
*/
// {{{ICINGA_LICENSE_HEADER}}}
2013-07-12 14:33:17 +02:00
namespace Icinga\Web;
2013-08-20 19:26:44 +02:00
use \Zend_View_Abstract;
use \Icinga\Web\Url;
use \Icinga\Util\Format;
2013-07-12 14:33:17 +02:00
2013-08-20 19:26:44 +02:00
/**
* Icinga view
*/
class View extends Zend_View_Abstract
2013-07-12 14:33:17 +02:00
{
2013-08-20 19:26:44 +02:00
/**
* Flag to register stream wrapper
*
* @var bool
*/
private $useViewStream = false;
2013-07-12 14:33:17 +02:00
2013-08-20 19:26:44 +02:00
/**
* Create a new view object
*
* @param array $config
* @see Zend_View_Abstract::__construct
*/
2013-07-12 14:33:17 +02:00
public function __construct($config = array())
{
2013-08-20 19:26:44 +02:00
$this->useViewStream = (bool) ini_get('short_open_tag') ? false : true;
if ($this->useViewStream) {
2013-07-12 14:33:17 +02:00
if (!in_array('zend.view', stream_get_wrappers())) {
stream_wrapper_register('zend.view', '\Icinga\Web\ViewStream');
}
}
parent::__construct($config);
}
2013-08-20 19:26:44 +02:00
/**
* Initialize the view
*
* @see Zend_View_Abstract::init
*/
2013-07-12 14:33:17 +02:00
public function init()
{
$this->loadGlobalHelpers();
}
2013-08-20 19:26:44 +02:00
/**
* Load helpers
*/
private function loadGlobalHelpers()
2013-07-12 14:33:17 +02:00
{
$pattern = dirname(__FILE__) . '/View/helpers/*.php';
$files = glob($pattern);
foreach ($files as $file) {
require_once $file;
}
}
2013-08-20 19:26:44 +02:00
// @codingStandardsIgnoreStart
/**
* Use to include the view script in a scope that only allows public
* members.
*
* @return mixed
*
* @see Zend_View_Abstract::run
*/
2013-07-12 14:33:17 +02:00
protected function _run()
{
foreach ($this->getVars() as $k => $v) {
// Exporting global variables to view scripts:
$$k = $v;
}
2013-08-20 19:26:44 +02:00
if ($this->useViewStream) {
include 'zend.view://' . func_get_arg(0);
2013-07-12 14:33:17 +02:00
} else {
include func_get_arg(0);
}
}
2013-08-20 19:26:44 +02:00
// @codingStandardsIgnoreEnd
2013-07-12 14:33:17 +02:00
2013-08-20 19:26:44 +02:00
/**
* Accesses a helper object from within a script
*
* @param string $name
* @param array $args
*
* @return string
*/
2013-07-12 14:33:17 +02:00
public function __call($name, $args)
{
$namespaced = '\\Icinga\\Web\\View\\' . $name;
if (function_exists($namespaced)) {
return call_user_func_array(
$namespaced,
$args
);
} else {
return parent::__call($name, $args);
}
}
}