Skip to content

Commit

Permalink
Add basic application structure
Browse files Browse the repository at this point in the history
refs #3761
  • Loading branch information
Johannes Meyer committed Oct 1, 2013
1 parent 0d6dc0c commit 8bf28d1
Show file tree
Hide file tree
Showing 8 changed files with 382 additions and 0 deletions.
179 changes: 179 additions & 0 deletions install/Application/Wizard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* 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.
*
* @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>
*/
// {{{ICINGA_LICENSE_HEADER}}}

namespace Icinga\Installer;

require_once 'Zend/View.php';
require_once 'Zend/Layout.php';
require_once 'Zend/Controller/Front.php';
require_once 'Zend/Controller/Action/HelperBroker.php';

use \Zend_View;
use \Zend_Layout;
use \Zend_Controller_Front;
use \Zend_Controller_Action_HelperBroker;

class Wizard
{
/**
* Application directory
*
* @var string
*/
private $appDir;

/**
* Configuration directory
*
* @var string
*/
private $configDir;

/**
* View object
*
* @var View
*/
private $viewRenderer;

/**
* Zend front controller instance
*
* @var Zend_Controller_Front
*/
private $frontController;

/**
* Initialise a new wizard
*
* @param string $configDir The path to the configuration directory to use
*/
public function __construct($configDir)
{
$this->configDir = $configDir;
}

/**
* Return the actual application directory
*
* @return string
*/
public function getApplicationDir()
{
if (!isset($this->appDir)) {
$this->appDir = realpath('Application');
}
return $this->appDir;
}

/**
* Return the actual front controller
*
* @return Zend_Controller_Front
*/
public function getFrontController()
{
return $this->frontController;
}

/**
* Return the actual view object
*
* @return View
*/
public function getViewRenderer()
{
return $this->viewRenderer;
}

/**
* Start and setup a new install wizard
*
* @param string $configDir The path to the configuration directory to use
* @return self
*/
public static function start($configDir)
{
$wizard = new Wizard($configDir);
$wizard->setup();
return $wizard;
}

/**
* Finalise this wizard's initialisation
*/
private function setup()
{
Zend_Layout::startMvc(
array(
'layout' => 'layout',
'layoutPath' => $this->getApplicationDir() . '/layouts/scripts'
)
);
$this->setupFrontController();
$this->setupViewRenderer();
}

/**
* Instantiate front controller
*/
private function setupFrontController()
{
$this->frontController = Zend_Controller_Front::getInstance();
$this->frontController->setControllerDirectory($this->getApplicationDir() . '/controllers');
$this->frontController->setParams(
array(
'displayExceptions' => true
)
);
}

/**
* Register helper paths and views for renderer
*/
private function setupViewRenderer()
{
$view = Zend_Controller_Action_HelperBroker::getStaticHelper('viewRenderer');
$view->setView(new Zend_View());
$view->view->setEncoding('UTF-8');
$view->view->addHelperPath($this->getApplicationDir() . '/views/helpers');

$view->view->headTitle()->prepend('Icinga');
$view->view->headTitle()->setSeparator(' :: ');

$this->viewRenderer = $view;
}

/**
* Dispatch public interface
*/
public function dispatch()
{
$this->frontController->dispatch();
}
}
64 changes: 64 additions & 0 deletions install/Application/controllers/ErrorController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* 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.
*
* @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>
*/
// {{{ICINGA_LICENSE_HEADER}}}

require_once 'Zend/Controller/Action.php';
require_once 'Zend/Controller/Plugin/ErrorHandler.php';

use \Zend_Controller_Action;
use \Zend_Controller_Plugin_ErrorHandler;

/**
* Error controller to display exceptions occured in the install wizard
*/
class ErrorController extends Zend_Controller_Action
{
/**
* Display exception
*/
public function errorAction()
{
$errors = $this->_getParam('error_handler');
switch ($errors->type)
{
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ROUTE:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_CONTROLLER:
case Zend_Controller_Plugin_ErrorHandler::EXCEPTION_NO_ACTION:
$this->getResponse()->setHttpResponseCode(404);
$this->view->message = 'Page not found';
break;
default:
$this->getResponse()->setHttpResponseCode(500);
$this->view->message = 'Application error';
break;
}

if ($this->getInvokeArg('displayExceptions') == true) {
$this->view->exception = $errors->exception;
}
}
}
45 changes: 45 additions & 0 deletions install/Application/controllers/IndexController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* 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.
*
* @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>
*/
// {{{ICINGA_LICENSE_HEADER}}}

require_once 'Zend/Controller/Action.php';

use \Zend_Controller_Action;

/**
* Install index controller
*/
class IndexController extends Zend_Controller_Action
{
/**
* The start page of the install wizard
*/
public function indexAction()
{

}
}
16 changes: 16 additions & 0 deletions install/Application/layouts/scripts/body.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<div class="row">
<div class="col-sm-12 col-xs-12 col-md-10 col-lg-10">
<?php echo $this->layout()->content; ?>

</div>
</div>
<br/>
<div class="row">
<div class="col-md-12">
<div class="panel">
<div class="panel-body text-center">
Icinga 2 Web &copy; 2013 Icinga Team
</div>
</div>
</div>
</div>
22 changes: 22 additions & 0 deletions install/Application/layouts/scripts/layout.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Icinga 2 Web Install Wizard</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">

<link rel="stylesheet" href="<?php echo $this->baseUrl('../public/css/vendor/bootstrap/bootstrap.min.css') ?>" media="screen">

<!--
Not used until styling is clear (see #4550)
<link rel="stylesheet" href="<?php echo $this->baseUrl('../public/css.php') ?>">
-->
</head>
<body>
<?php echo $this->render('body.phtml'); ?>

</body>
</html>
19 changes: 19 additions & 0 deletions install/Application/views/scripts/error/error.phtml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="alert alert-error">
<h1>An error occurred</h1>
<p><?php echo $this->message; ?></p>

<?php if (isset($this->exception)): ?>
<div style="text-align: left;">
<h3>Exception information:</h3>

<p><b>Message:</b> <?php echo $this->exception->getMessage(); ?></p>

<h3>Stack trace:</h3>
<pre><?php echo $this->exception->getTraceAsString(); ?></pre>

<h3>Request Parameters:</h3>
<pre><?php echo var_export(Zend_Controller_Front::getInstance()->getParams(), true); ?></pre>
</div>
<?php endif; ?>

</div>
Empty file.
37 changes: 37 additions & 0 deletions install/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* 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.
*
* @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>
*/
// {{{ICINGA_LICENSE_HEADER}}}

/**
* @TODO Evaluate how Zend can be properly recognised
*/

require_once realpath(__DIR__ . '/Application/Wizard.php');

use \Icinga\Installer\Wizard;

Wizard::start(realpath(__DIR__ . '/../config/'))->dispatch();

0 comments on commit 8bf28d1

Please sign in to comment.