public function __construct()
 {
     $this->environment = isset($_SERVER['APPLICATION_ENV']) ? $_SERVER['APPLICATION_ENV'] : null;
     $config = new Config();
     $config->loadFromFile(CONFIG_DIR . 'cohesion-default-conf.json');
     $config->loadFromFile(CONFIG_DIR . 'default-conf.json');
     if ($this->environment) {
         $envConfFile = CONFIG_DIR . $this->environment . '-conf.json';
         if (file_exists($envConfFile)) {
             $config->loadFromFile($envConfFile);
         } else {
             throw new \Exception("Missing config file for {$this->environment} environment");
         }
     }
     $this->config = $config;
     $global = $config->get('global');
     $domain = $config->get('global.domain_name');
     if ($domain) {
         $global['abs_base_url'] = "http://{$domain}";
         $global['ssl_base_url'] = "https://{$domain}";
         $global['base_url'] = $global['abs_base_url'];
     }
     if ($this->environment == 'production' || $config->get('global.production')) {
         $global['production'] = true;
         $this->production = true;
     }
     if ($config->get('data_access.cache.driver') == 'APC') {
         $cache = new APC();
         $global['cache'] = $cache;
     }
     $config->merge('global', $global);
     RoutingFactory::$config = $this->getConfig('routing');
     ViewFactory::$config = $this->getConfig('view');
     ViewFactory::$environment = $this;
 }
 public function __construct()
 {
     parent::__construct();
     if (!isset($_SESSION)) {
         session_start();
     }
     $this->input = new Input($_REQUEST ?: array());
     $global = $this->config->get('global');
     $this->supportedMimeTypes = $this->config->get('view.mime_types');
     if (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']) {
         $global['protocol'] = 'https';
         $this->isSecure = true;
     } else {
         $global['protocol'] = 'http';
         $this->isSecure = false;
     }
     $domain = isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : ($_SERVER['SERVER_NAME'] ? $_SERVER['SERVER_NAME'] : null);
     if ($domain) {
         $global['domain'] = $domain;
         $global['abs_base_url'] = "http://{$domain}";
         $global['ssl_base_url'] = "https://{$domain}";
         $global['base_url'] = $global['protocol'] . '://' . $domain;
     }
     $global['web_root'] = $_SERVER['DOCUMENT_ROOT'];
     $global['base_dir'] = dirname($global['web_root']);
     $global['uri'] = explode('?', $_SERVER['REQUEST_URI'])[0];
     $this->config->merge('global', $global);
     RoutingFactory::$config = $this->getConfig('routing');
     ViewFactory::$config = $this->getConfig('view');
 }
Example #3
0
{
    throw new ErrorException($errstr, 0, $errno, $errfile, $errline);
}
set_error_handler("exceptionErrorHandler");
require_once BASE_DIR . 'vendor/autoload.php';
$env = new HTTPEnvironment();
$auth = new NoAuth();
/* To use the authentication feature you must implement a UserService
$auth = new HTTPAuth($serviceFactory->get('\\MyProject\\User\\UserService'));
*/
$user = $auth->getUser();
$env->setAuth($auth);
$daoFactory = new DataAccessFactory($env->getConfig()->getConfig('data_access'));
$serviceFactory = new ServiceFactory($daoFactory, $env->getConfig(), $user);
$format = $env->getFormat();
$route = RoutingFactory::getRoute();
// Check for redirect
if ($redirect = $route->getRedirect()) {
    header('Location: ' . $redirect, true, 301);
    exit;
    // File Not Found
} else {
    if (!($class = $route->getClassName())) {
        notFound($format, $route->getUri());
        exit;
    }
}
$function = $route->getFunctionName();
$params = $route->getParameterValues();
// Execute controller
try {