示例#1
0
 public function WebRoute(Application $application, $path = "/", $method = "GET", $cookies = "")
 {
     foreach (explode(";", $cookies) as $cookie) {
         $cookie = explode("=", $cookie, 2);
         $_COOKIE[$cookie[0]] = isset($cookie[1]) ? $cookie[1] : "";
     }
     try {
         $application->route($method, $path);
     } catch (NotFoundException $e) {
         $this->help();
         throw $e;
     }
 }
示例#2
0
 public static function compose(...$calls)
 {
     foreach ($calls as &$call) {
         if (is_callable($call)) {
             continue;
         }
         if (!isset(self::$middlewares[$call])) {
             // Try autoloading middleware
             class_exists(Application::getInstance()->getApplicationNamespace() . "\\Middleware\\" . $call);
             if (!isset(self::$middlewares[$call])) {
                 class_exists(__NAMESPACE__ . "\\Middleware\\" . $call);
                 if (!isset(self::$middlewares[$call])) {
                     throw new UnknownMiddlewareException("Middleware '{$call}' is unknown");
                 }
             }
         }
         $call = self::$middlewares[$call];
     }
     return function (...$arguments) use($calls) {
         foreach ($calls as $call) {
             if (is_array($retval = $call(...$arguments))) {
                 $arguments = $retval;
             }
         }
     };
 }
示例#3
0
 public static function getEnvironment()
 {
     if (!self::$environment) {
         $applicationReflector = new \ReflectionClass(Application::getInstance());
         $loader = new \Twig_Loader_Filesystem();
         self::$environment = new Twig_Environment($loader);
         // ppFramework built-in views
         $loader->addPath(__DIR__ . DIRECTORY_SEPARATOR . "View", "ppFramework");
         // Application view namespace
         $path = dirname($applicationReflector->getFileName()) . DIRECTORY_SEPARATOR . $applicationReflector->getShortName() . DIRECTORY_SEPARATOR . "View";
         if (is_dir($path)) {
             $loader->addPath($path, $applicationReflector->getShortName());
         }
     }
     return self::$environment;
 }