2013-05-03 17:02:53 +02:00
|
|
|
<?php
|
2013-05-16 03:16:56 +02:00
|
|
|
/**
|
|
|
|
* PHPCI - Continuous Integration for PHP
|
|
|
|
*
|
2013-05-16 03:57:02 +02:00
|
|
|
* @copyright Copyright 2013, Block 8 Limited.
|
|
|
|
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
|
|
|
* @link http://www.phptesting.org/
|
2013-05-16 03:16:56 +02:00
|
|
|
*/
|
2013-05-03 17:02:53 +02:00
|
|
|
|
|
|
|
namespace PHPCI;
|
2013-05-16 03:57:02 +02:00
|
|
|
|
|
|
|
use b8;
|
|
|
|
use b8\Registry;
|
2013-05-03 17:02:53 +02:00
|
|
|
|
2013-05-16 03:16:56 +02:00
|
|
|
/**
|
|
|
|
* PHPCI Front Controller
|
2013-05-16 03:57:02 +02:00
|
|
|
* @author Dan Cryer <dan@block8.co.uk>
|
2013-05-16 03:16:56 +02:00
|
|
|
*/
|
2013-05-03 17:02:53 +02:00
|
|
|
class Application extends b8\Application
|
|
|
|
{
|
2013-05-17 18:34:31 +02:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
if (isset($_SERVER['REDIRECT_PATH_INFO'])) {
|
|
|
|
$_SERVER['REQUEST_URI'] = $_SERVER['REDIRECT_PATH_INFO'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::__construct();
|
|
|
|
}
|
|
|
|
|
2013-05-16 17:46:30 +02:00
|
|
|
/**
|
|
|
|
* Handle an incoming web request.
|
|
|
|
*/
|
2013-05-16 03:57:02 +02:00
|
|
|
public function handleRequest()
|
|
|
|
{
|
|
|
|
$controllerName = \b8\Registry::getInstance()->get('ControllerName');
|
2013-05-16 17:46:30 +02:00
|
|
|
|
|
|
|
// Validate the user's session unless it is a login/logout action or a web hook:
|
2013-05-16 03:57:02 +02:00
|
|
|
$sessionAction = ($controllerName == 'Session' && in_array($this->action, array('login', 'logout')));
|
2013-05-17 17:10:54 +02:00
|
|
|
$externalAction = in_array($controllerName, array('Bitbucket', 'Github', 'BuildStatus'));
|
2013-05-16 03:57:02 +02:00
|
|
|
|
2013-05-17 17:10:54 +02:00
|
|
|
if (!$externalAction && !$sessionAction) {
|
2013-05-16 03:57:02 +02:00
|
|
|
$this->validateSession();
|
|
|
|
}
|
|
|
|
|
2013-05-16 17:46:30 +02:00
|
|
|
// Render content into layout and return:
|
2013-05-16 03:57:02 +02:00
|
|
|
$view = new b8\View('Layout');
|
|
|
|
$view->content = parent::handleRequest();
|
|
|
|
|
|
|
|
return $view->render();
|
|
|
|
}
|
|
|
|
|
2013-05-16 17:46:30 +02:00
|
|
|
/**
|
|
|
|
* Validate whether or not the remote user has a valid session:
|
|
|
|
*/
|
2013-05-16 03:57:02 +02:00
|
|
|
protected function validateSession()
|
|
|
|
{
|
|
|
|
if (!empty($_SESSION['user_id'])) {
|
|
|
|
$user = b8\Store\Factory::getStore('User')->getByPrimaryKey($_SESSION['user_id']);
|
|
|
|
|
|
|
|
if ($user) {
|
|
|
|
Registry::getInstance()->set('user', $user);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
unset($_SESSION['user_id']);
|
|
|
|
}
|
|
|
|
|
|
|
|
header('Location: /session/login');
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
}
|