本文整理汇总了PHP中Icinga\Application\Icinga类的典型用法代码示例。如果您正苦于以下问题:PHP Icinga类的具体用法?PHP Icinga怎么用?PHP Icinga使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Icinga类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addLoadedModules
public function addLoadedModules()
{
foreach (Icinga::app()->getModuleManager()->getLoadedModules() as $name => $module) {
$this->addModule($name, $module);
}
return $this;
}
示例2: send
public static function send($minified = false)
{
header('Content-Type: application/javascript');
$basedir = Icinga::app()->getBootstrapDirecory();
$js = $out = '';
$min = $minified ? '.min' : '';
// TODO: Cache header
header('Content-Type: application/javascript');
$cacheFile = '/tmp/cache_icinga' . $min . '.js';
if (file_exists($cacheFile)) {
readfile($cacheFile);
exit;
}
// We do not minify vendor files
foreach (self::$vendorFiles as $file) {
$out .= file_get_contents($basedir . '/' . $file . $min . '.js');
}
foreach (self::$jsFiles as $file) {
$js .= file_get_contents($basedir . '/' . $file);
}
foreach (Icinga::app()->getModuleManager()->getLoadedModules() as $name => $module) {
if ($module->hasJs()) {
$js .= file_get_contents($module->getJsFilename());
}
}
if ($minified) {
require_once 'IcingaVendor/JShrink/Minifier.php';
$out .= Minifier::minify($js, array('flaggedComments' => false));
} else {
$out .= $js;
}
// Not yet, this is for tests only. Waiting for Icinga\Web\Cache
// file_put_contents($cacheFile, $out);
echo $out;
}
示例3: getView
/**
* Get the view this menu item is being rendered to
*
* @return View
*/
protected function getView()
{
if ($this->view === null) {
$this->view = Icinga::app()->getViewRenderer()->view;
}
return $this->view;
}
示例4: imgAction
/**
* Return an image from the application's or the module's public folder
*/
public function imgAction()
{
// TODO(el): I think this action only retrieves images from modules
$module = $this->_getParam('module_name');
$file = $this->_getParam('file');
$basedir = Icinga::app()->getModuleManager()->getModule($module)->getBaseDir();
$filePath = realpath($basedir . '/public/img/' . $file);
if ($filePath === false) {
$this->httpNotFound('%s does not exist', $filePath);
}
if (preg_match('/\\.([a-z]+)$/i', $file, $m)) {
$extension = $m[1];
if ($extension === 'svg') {
$extension = 'svg+xml';
}
} else {
$extension = 'fixme';
}
$s = stat($filePath);
header('Content-Type: image/' . $extension);
header(sprintf('ETag: "%x-%x-%x"', $s['ino'], $s['size'], (double) str_pad($s['mtime'], 16, '0')));
header('Cache-Control: public, max-age=3600');
header('Pragma: cache');
header('Last-Modified: ' . gmdate('D, d M Y H:i:s', $s['mtime']) . ' GMT');
readfile($filePath);
}
示例5: serveAction
public function serveAction()
{
$minVersion = '5.4.0';
if (version_compare(PHP_VERSION, $minVersion) < 0) {
throw new IcingaException('You are running PHP %s, internal webserver requires %s.', PHP_VERSION, $minVersion);
}
$fork = $this->params->get('daemonize');
$documentRoot = $this->params->shift();
$socket = $this->params->shift();
// TODO: Sanity check!!
if ($socket === null) {
$socket = '0.0.0.0:80';
// throw new IcingaException('Socket is required');
}
if ($documentRoot === null) {
$documentRoot = Icinga::app()->getBaseDir('public');
if (!file_exists($documentRoot) || !is_dir($documentRoot)) {
throw new IcingaException('Document root directory is required');
}
}
$documentRoot = realpath($documentRoot);
if ($fork) {
$this->forkAndExit();
}
echo "Serving Icingaweb from {$documentRoot}\n";
$cmd = sprintf('%s -S %s -t %s %s', readlink('/proc/self/exe'), $socket, $documentRoot, Icinga::app()->getLibraryDir('/Icinga/Application/webrouter.php'));
// TODO: Store webserver log, switch uid, log index.php includes, pid file
if ($fork) {
exec($cmd);
} else {
passthru($cmd);
}
}
示例6: fromConfig
/**
* Create menu from the application's menu config file plus the config files from all enabled modules
*
* @return self
*/
public static function fromConfig()
{
$menu = new static('menu');
$manager = Icinga::app()->getModuleManager();
try {
$menuConfigs = array(Config::app('menu'));
} catch (NotReadableError $e) {
Logger::error($e);
$menuConfigs = array();
}
try {
$modules = $manager->listEnabledModules();
} catch (NotReadableError $e) {
Logger::error($e);
$modules = array();
}
foreach ($modules as $moduleName) {
try {
$moduleMenuConfig = Config::module($moduleName, 'menu');
} catch (NotReadableError $e) {
Logger::error($e);
$moduleMenuConfig = array();
}
if (!empty($moduleMenuConfig)) {
$menuConfigs[] = $moduleMenuConfig;
}
}
return $menu->loadMenuItems($menu->flattenConfigs($menuConfigs));
}
示例7: getConfigDir
public function getConfigDir()
{
if ($this->configDir === null) {
$dir = Icinga::app()->getModuleManager()->getModule('businessprocess')->getConfigDir();
// TODO: This is silly. We need Config::requireDirectory().
if (!is_dir($dir)) {
if (!is_dir(dirname($dir))) {
if (!@mkdir(dirname($dir))) {
throw new SystemPermissionException('Could not create config directory "%s"', dirname($dir));
}
}
if (!mkdir($dir)) {
throw new SystemPermissionException('Could not create config directory "%s"', $dir);
}
}
$dir = $dir . '/processes';
if (!is_dir($dir)) {
if (!mkdir($dir)) {
throw new SystemPermissionException('Could not create config directory "%s"', $dir);
}
}
$this->configDir = $dir;
}
return $this->configDir;
}
示例8: init
/**
* {@inheritdoc}
*/
public function init()
{
$this->providedPermissions = array('*' => $this->translate('Allow everything') . ' (*)', 'application/stacktraces' => $this->translate('Allow to adjust in the preferences whether to show stacktraces') . ' (application/stacktraces)', 'config/*' => $this->translate('Allow config access') . ' (config/*)');
$helper = new Zend_Form_Element('bogus');
$mm = Icinga::app()->getModuleManager();
foreach ($mm->listInstalledModules() as $moduleName) {
$modulePermission = $mm::MODULE_PERMISSION_NS . $moduleName;
$this->providedPermissions[$modulePermission] = sprintf($this->translate('Allow access to module %s') . ' (%s)', $moduleName, $modulePermission);
$module = $mm->getModule($moduleName, false);
foreach ($module->getProvidedPermissions() as $permission) {
/** @var object $permission */
$this->providedPermissions[$permission->name] = $permission->description . ' (' . $permission->name . ')';
}
foreach ($module->getProvidedRestrictions() as $restriction) {
/** @var object $restriction */
// Zend only permits alphanumerics, the underscore, the circumflex and any ASCII character in range
// \x7f to \xff (127 to 255)
$name = $helper->filterName($restriction->name);
while (isset($this->providedRestrictions[$name])) {
// Because Zend_Form_Element::filterName() replaces any not permitted character with the empty
// string we may have duplicate names, e.g. 're/striction' and 'restriction'
$name .= '_';
}
$this->providedRestrictions[$name] = array('description' => $restriction->description, 'name' => $restriction->name);
}
}
}
示例9: load
public static function load($name, Module $module = null)
{
if ($module === null) {
$basedir = Icinga::app()->getApplicationDir('forms');
$ns = '\\Icinga\\Web\\Forms\\';
} else {
$basedir = $module->getFormDir();
$ns = '\\Icinga\\Module\\' . ucfirst($module->getName()) . '\\Forms\\';
}
if (preg_match('~^[a-z0-9/]+$~i', $name)) {
$parts = preg_split('~/~', $name);
$class = ucfirst(array_pop($parts)) . 'Form';
$file = sprintf('%s/%s/%s.php', rtrim($basedir, '/'), implode('/', $parts), $class);
if (file_exists($file)) {
require_once $file;
$class = $ns . $class;
$options = array();
if ($module !== null) {
$options['icingaModule'] = $module;
}
return new $class($options);
}
}
throw new ProgrammingError(sprintf('Cannot load %s (%s), no such form', $name, $file));
}
示例10: view
/**
* Access the current view
*
* Will instantiate a new one if none exists
* // TODO: App->getView
*
* @return Zend_View_Abstract
*/
protected function view()
{
if (self::$view === null) {
self::$view = Icinga::app()->getViewRenderer()->view;
}
return self::$view;
}
示例11: Module
/**
* Return this controller's module
*
* @return Module
*/
public function Module()
{
if ($this->module === null) {
$this->module = Icinga::app()->getModuleManager()->getModule($this->getModuleName());
}
return $this->module;
}
示例12: render
/**
* {@inheritdoc}
*/
public function render()
{
$repo = new AnnouncementIniRepository();
$etag = $repo->getEtag();
$cookie = new AnnouncementCookie();
if ($cookie->getEtag() !== $etag) {
$cookie->setEtag($etag);
$cookie->setNextActive($repo->findNextActive());
Icinga::app()->getResponse()->setCookie($cookie);
}
$acked = array();
foreach ($cookie->getAcknowledged() as $hash) {
$acked[] = Filter::expression('hash', '!=', $hash);
}
$acked = Filter::matchAll($acked);
$announcements = $repo->findActive();
$announcements->applyFilter($acked);
if ($announcements->hasResult()) {
$html = '<ul role="alert" id="announcements">';
foreach ($announcements as $announcement) {
$ackForm = new AcknowledgeAnnouncementForm();
$ackForm->populate(array('hash' => $announcement->hash));
$html .= '<li><div>' . $this->view()->escape($announcement->message) . '</div>' . $ackForm . '</li>';
}
$html .= '</ul>';
return $html;
}
// Force container update on XHR
return '<div style="display: none;"></div>';
}
示例13: getResponse
/**
* Get the response
*
* @return Response
*/
public function getResponse()
{
if ($this->response === null) {
$this->response = Icinga::app()->getResponse();
}
return $this->response;
}
示例14: getRequest
/**
* Get the request
*
* @return Request
*/
public function getRequest()
{
if ($this->request === null) {
$this->request = Icinga::app()->getRequest();
}
return $this->request;
}
示例15: send
/**
* Send the client side script code to the client
*
* Does not cache the client side script code if the HTTP header Cache-Control or Pragma is set to no-cache.
*
* @param bool $minified Whether to compress the client side script code
*/
public static function send($minified = false)
{
header('Content-Type: application/javascript');
$basedir = Icinga::app()->getBootstrapDirectory();
$js = $out = '';
$min = $minified ? '.min' : '';
// Prepare vendor file list
$vendorFiles = array();
foreach (self::$vendorFiles as $file) {
$vendorFiles[] = $basedir . '/' . $file . $min . '.js';
}
// Prepare Icinga JS file list
$jsFiles = array();
foreach (self::$jsFiles as $file) {
$jsFiles[] = $basedir . '/' . $file;
}
foreach (Icinga::app()->getModuleManager()->getLoadedModules() as $name => $module) {
if ($module->hasJs()) {
foreach ($module->getJsFiles() as $path) {
if (file_exists($path)) {
$jsFiles[] = $path;
}
}
}
}
$files = array_merge($vendorFiles, $jsFiles);
$request = Icinga::app()->getRequest();
$noCache = $request->getHeader('Cache-Control') === 'no-cache' || $request->getHeader('Pragma') === 'no-cache';
if (!$noCache && FileCache::etagMatchesFiles($files)) {
header("HTTP/1.1 304 Not Modified");
return;
} else {
$etag = FileCache::etagForFiles($files);
}
header('Cache-Control: public');
header('ETag: "' . $etag . '"');
header('Content-Type: application/javascript');
$cacheFile = 'icinga-' . $etag . $min . '.js';
$cache = FileCache::instance();
if (!$noCache && $cache->has($cacheFile)) {
$cache->send($cacheFile);
return;
}
// We do not minify vendor files
foreach ($vendorFiles as $file) {
$out .= ';' . ltrim(trim(file_get_contents($file)), ';') . "\n";
}
foreach ($jsFiles as $file) {
$js .= file_get_contents($file) . "\n\n\n";
}
if ($minified) {
require_once 'JShrink/Minifier.php';
$out .= Minifier::minify($js, array('flaggedComments' => false));
} else {
$out .= $js;
}
$cache->store($cacheFile, $out);
echo $out;
}