Пример #1
0
 public function __construct(string $viewPath = null, $loader = null)
 {
     $this->viewPath = rtrim($viewPath, '/ ') . '/';
     if (!is_null($loader)) {
         $this->loader = $loader;
     } else {
         $this->loader = Services::loader(true);
     }
 }
Пример #2
0
 /**
  * Loads a helper file into memory. Supports namespaced helpers,
  * both in and out of the 'helpers' directory of a namespaced directory.
  *
  * @param string $filename
  *
  * @return string
  */
 function load_helper(string $filename) : string
 {
     $loader = \App\Config\Services::loader(true);
     $path = $loader->locateFile($filename, 'helpers');
     if (!empty($path)) {
         include $path;
     }
 }
if ($config->CSRFProtection === true && !is_cli()) {
    $security = \App\Config\Services::security($config);
    $security->CSRFVerify();
}
//--------------------------------------------------------------------
// Get our Request and Response objects
//--------------------------------------------------------------------
$request = is_cli() ? \App\Config\Services::clirequest($config) : \App\Config\Services::request($config);
$response = \App\Config\Services::response();
// Assume success until proven otherwise.
$response->setStatusCode(200);
//--------------------------------------------------------------------
// Try to Route It
//--------------------------------------------------------------------
require APPPATH . 'config/Routes.php';
$router = \App\Config\Services::router($routes, true);
$path = is_cli() ? $request->getPath() : $request->uri->getPath();
$controller = $router->handle($path);
ob_start();
// Is it routed to a Closure?
if (is_callable($controller)) {
    echo $controller(...$router->params());
} else {
    if (empty($controller)) {
        // Show the 404 error page
        if (is_cli()) {
            require APPPATH . 'views/errors/cli/error_404.php';
        } else {
            require APPPATH . 'views/errors/html/error_404.php';
        }
        $response->setStatusCode(404);
Пример #4
0
 * --------------------------------------------------------------------
 * This file lets you re-map URI requests to specific controller functions.
 *
 * Typically there is a one-to-one relationship between a URL string
 * and its corresponding controller class/method. The segments in a
 * URL normally follow this pattern:
 *
 *    example.com/class/method/id
 *
 * In some instances, however, you may want to remap this relationship
 * so that a different class/function is called than the one
 * corresponding to the URL.
 *
 */
// Create a new instance of our RouteCollection class.
$routes = \App\Config\Services::routes();
/**
 * --------------------------------------------------------------------
 * Router Setup
 * --------------------------------------------------------------------
 * The RouteCollection object allows you to modify the way that the
 * Router works, by acting as a holder for it's configuration settings.
 * The following methods can be called on the object to modify
 * the default operations.
 *
 *    $routes->defaultNamespace()
 *
 * Modifies the namespace that is added to a controller if it doesn't
 * already have one. By default this is the global namespace (\).
 *
 *    $routes->defaultController()