php-censor/PHPCI/Application.php

72 lines
1.8 KiB
PHP
Raw Normal View History

2013-05-03 17:02:53 +02:00
<?php
2013-05-16 03:16:56 +02:00
/**
* PHPCI - Continuous Integration for PHP
*
* @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;
use b8;
use b8\Registry;
2013-05-03 17:02:53 +02:00
2013-05-16 03:16:56 +02:00
/**
* PHPCI Front Controller
* @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
{
public function __construct()
{
if (isset($_SERVER['REDIRECT_PATH_INFO'])) {
$_SERVER['REQUEST_URI'] = $_SERVER['REDIRECT_PATH_INFO'];
}
return parent::__construct();
}
/**
* Handle an incoming web request.
*/
public function handleRequest()
{
$controllerName = \b8\Registry::getInstance()->get('ControllerName');
// Validate the user's session unless it is a login/logout action or a web hook:
$sessionAction = ($controllerName == 'Session' && in_array($this->action, array('login', 'logout')));
$externalAction = in_array($controllerName, array('Bitbucket', 'Github', 'BuildStatus'));
if (!$externalAction && !$sessionAction) {
$this->validateSession();
}
// Render content into layout and return:
$view = new b8\View('Layout');
$view->content = parent::handleRequest();
return $view->render();
}
/**
* Validate whether or not the remote user has a valid session:
*/
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;
}
}