Example #1
4
<?php

use Inphinit\App;
use Inphinit\View;
use Inphinit\Request;
use Inphinit\Routing\Route;
App::on('changestatus', function ($status, $msg) {
    if ($status === 503) {
        echo 'This site is currently down for maintenance and should be back soon!';
    } elseif (in_array($status, array(401, 403, 404, 500, 501))) {
        View::forceRender();
        View::render('httpview', array('title' => $msg ? $msg : 'Página inacessível', 'method' => $_SERVER['REQUEST_METHOD'], 'path' => Request::path(), 'route' => Request::path(true), 'status' => $status));
        exit;
    }
});
Route::set('ANY', '/', 'Home:index');
// Navitate to http://[server]/user/[YOUR NAME] like: http://[server]/user/mary
Route::set('ANY', 're:#^/user/([a-z0-9_]+)$#', 'Users.Profile:view');
// Navitate to http://[server]/info
Route::set('ANY', '/info', 'Examples:info');
// Navitate to http://[server]/closure
Route::set('ANY', '/closure', 'Examples:arrayClosure');
Example #2
3
 public function arrayClosure()
 {
     $args = array('foo' => 'Foo', 'bar' => 'bar', 'baz' => 'baz');
     App::on('ready', function ($args) {
         print_r($args);
     }, array($args));
 }
Example #3
3
 public static function exec()
 {
     if (self::$initiate) {
         return null;
     }
     self::trigger('init');
     self::$initiate = true;
     if (self::env('maintenance') === true) {
         self::stop(503);
     }
     self::trigger('changestatus', array(\UtilsStatusCode(), null));
     $route = Route::get();
     if ($route) {
         $mainController = $route['controller'];
         $parsed = explode(':', $mainController, 2);
         $mainController = '\\Controller\\' . strtr($parsed[0], '.', '\\');
         $action = $parsed[1];
         $run = new $mainController();
         call_user_func_array(array($run, $action), is_array($route['args']) ? $route['args'] : array());
         $run = null;
     } else {
         App::stop(404, 'Invalid route');
     }
     if (class_exists('\\Inphinit\\Response', false)) {
         Response::dispatchHeaders();
     }
     if (class_exists('\\Inphinit\\View', false)) {
         View::dispatch();
     }
     self::trigger('ready');
     self::trigger('finish');
 }
Example #4
2
 public static function view($type, $view)
 {
     if ($view !== null && View::exists($view) === false) {
         Exception::raise($view . ' view is not found', 2);
     }
     $callRender = array('\\Experimental\\Debug', 'render' . ucfirst($type));
     switch ($type) {
         case 'error':
             self::$views[$type] = $view;
             App::on('error', $callRender);
             break;
         case 'classes':
         case 'performance':
             self::$views[$type] = $view;
             App::on('terminate', $callRender);
             break;
         default:
             Exception::raise($type . ' is not valid event', 2);
     }
     self::register();
 }
Example #5
2
 public static function view($type, $view)
 {
     if ($view !== null && View::exists($view) === false) {
         Exception::raise($view . ' view is not found', 2);
     }
     $callRender = array('\\' . get_called_class(), 'render' . ucfirst($type));
     switch ($type) {
         case 'error':
             self::$views[$type] = $view;
             App::on('error', $callRender);
             if (empty(self::$displayErrors)) {
                 self::$displayErrors = ini_get('display_errors');
                 ini_set('display_errors', '0');
             }
             break;
         case 'classes':
         case 'performance':
             self::$views[$type] = $view;
             App::on('terminate', $callRender);
             break;
         default:
             Exception::raise($type . ' is not valid event', 2);
     }
 }
Example #6
1
 public function __construct($namecontroller)
 {
     $this->format = Quick::BOTH;
     $controller = parent::$prefixNS . strtr($namecontroller, '.', '\\');
     $fc = '\\Controller\\' . $controller;
     if (class_exists($fc) === false) {
         Exception::raise('Invalid class ' . $fc, 2);
     }
     $this->classMethods = self::parseVerbs(get_class_methods($fc));
     $this->controller = $namecontroller;
     $this->fullController = $fc;
     App::on('init', array($this, 'prepare'));
 }
Example #7
1
 public function __construct($namecontroller)
 {
     $controller = parent::$prefixNS . strtr($namecontroller, '.', '\\');
     $fc = '\\Controller\\' . $controller;
     if (class_exists($fc) === false) {
         Exception::raise('Invalid class ' . $fc, 2);
     }
     $this->valids = array('index' => array('GET', '/'), 'create' => array('GET', '/create'), 'store' => array('POST', '/'), 'show' => array('GET', 're:#^/([a-z0-9_\\-]+)$#i'), 'edit' => array('GET', 're:#^/([a-z0-9_\\-]+)/edit$#i'), 'update' => array(array('PUT', 'PATCH'), 're:#^/([a-z0-9_\\-]+)$#i'), 'destroy' => array('DELETE', 're:#^/([a-z0-9_\\-]+)$#i'));
     $this->controller = $namecontroller;
     $this->fullController = $fc;
     $allowedMethods = array_keys($this->valids);
     $this->classMethods = array_intersect(get_class_methods($fc), $allowedMethods);
     App::on('init', array($this, 'prepare'));
 }
Example #8
1
function UtilsConfig()
{
    define('REQUEST_TIME', time());
    define('EOL', chr(10));
    App::config('config');
    $dev = App::env('developer') === true;
    error_reporting($dev ? E_ALL | E_STRICT : E_ALL & ~E_STRICT & ~E_DEPRECATED);
    ini_set('display_errors', $dev ? 1 : 0);
    register_shutdown_function('UtilsShutDown');
    set_error_handler('UtilsError', E_ALL | E_STRICT);
}
Example #9
1
<?php

/*
 * Inphinit
 *
 * Copyright (c) 2016 Guilherme Nascimento (brcontainer@yahoo.com.br)
 *
 * Released under the MIT license
 */
use Inphinit\App;
define('INPHINIT_START', microtime(true));
define('INPHINIT_ROOT', rtrim(strtr(dirname(__FILE__), '\\', '/'), '/') . '/');
define('INPHINIT_PATH', INPHINIT_ROOT . 'system/');
define('INPHINIT_COMPOSER', false);
require_once INPHINIT_PATH . 'boot/start.php';
if (App::env('developer') === true) {
    require_once INPHINIT_PATH . 'dev.php';
}
require_once INPHINIT_PATH . 'main.php';
App::exec();
Example #10
1
 public function __construct()
 {
     App::on('init', array($this, 'prepare'));
 }