예제 #1
0
 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;
 }
예제 #2
0
 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');
 }
예제 #3
0
 public function generateView($name = null)
 {
     if ($name === null) {
         $name = $this->config->get('class.default');
     }
     $name = $this->config->get('class.prefix') . $name . $this->config->get('class.suffix');
     return ViewFactory::createView($name, $this->config->get('default_layout_template'));
 }
 public function index()
 {
     $view = ViewFactory::createView('Home');
     return $view->generateView();
 }
예제 #5
0
function serverError($format, $e, $production = false)
{
    http_response_code(500);
    if ($format == 'plain') {
        echo "Server Error\n";
        if (!$production) {
            echo $e->getMessage() . "\n";
        }
    } else {
        if ($format == 'html') {
            $view = ViewFactory::createView('Error\\ServerError');
        } else {
            $view = ViewFactory::createDataView();
            if ($production) {
                $view->setError('Server Error');
            }
        }
        if (!$production) {
            $errors = array($e->getMessage());
            foreach ($e->getTrace() as $i => $trace) {
                if ($i === 0) {
                    $file = $e->getFile();
                    $line = $e->getLine();
                } else {
                    if (isset($trace['file'])) {
                        $file = str_replace(BASE_DIR, '', $trace['file']);
                        $line = $trace['line'];
                    }
                }
                $errors[] = "{$file}({$line}): {$trace['function']}";
            }
            $view->setErrors($errors);
        }
        echo $view->generateView();
    }
}