/**
  * Please bootstrap first, than run the application!
  *
  * Run a application, let application accept a request, route the request,
  * dispatch to controller/action, render response and return response to client finally.
  *
  * @param array $get    Array of variables passed to the current script via the URL parameters.
  * @param array $post   Array of variables passed to the current script via the HTTP POST method.
  * @param array $cookie Array of variables passed to the current script via HTTP Cookies.
  *
  * @throws \LogicException If application not bootstrapped.
  * @return void
  */
 public static function run(array $get, array $post, array $cookie)
 {
     $cli = array();
     if (Sapi::isCli()) {
         $cli = Cli::parse((array) Registry::get('env')->argv);
         if (count($cli) < 1 || isset($cli['list'])) {
             Cli::absorb();
             exit(0);
         }
     }
     $conf = Registry::get('conf');
     $prefix = Str::ensureTrailing('\\', $conf['app']['name']);
     $repository = BASE_PATH . 'app/' . $conf['app']['name'] . '/Controller';
     if (isset($cli['controller']) && $cli['controller'] == 'core') {
         $prefix = 'Pimf\\';
         $repository = BASE_PATH . 'pimf-framework/core/Pimf/Controller';
     }
     $resolver = new Resolver(new Request($get, $post, $cookie, $cli), $repository, $prefix);
     $sessionized = Sapi::isWeb() && $conf['session']['storage'] !== '';
     if ($sessionized) {
         Session::load();
     }
     $pimf = $resolver->process();
     if ($sessionized) {
         Session::save();
         Cookie::send();
     }
     $pimf->render();
 }
Пример #2
0
 /**
  * Create a new cache storage instance.
  *
  * @param string $storage
  *
  * @return CS\Apc|CS\Dba|CS\File|CS\Memcached|CS\Memory|CS\Pdo|CS\Redis|CS\WinCache
  * @throws \RuntimeException
  */
 protected static function factory($storage)
 {
     $conf = Registry::get('conf');
     switch ($storage) {
         case 'apc':
             return new CS\Apc($conf['cache']['key']);
         case 'file':
             return new CS\File($conf['cache']['storage_path']);
         case 'pdo':
             return new CS\Pdo(Pdo\Factory::get($conf['cache']['database']), $conf['cache']['key']);
         case 'memcached':
             return new CS\Memcached(Memcached::connection(), $conf['cache']['key']);
         case 'memory':
             return new CS\Memory();
         case 'redis':
             return new CS\Redis(Redis::database());
         case 'wincache':
             return new CS\WinCache($conf['cache']['key']);
         case 'dba':
             return new CS\Dba(String::ensureTrailing('/', $conf['cache']['storage_path']) . $conf['cache']['key']);
         default:
             throw new \RuntimeException("Cache storage {$storage} is not supported.");
     }
 }
Пример #3
0
 /**
  * Get cleaner URLs or old-fashioned » RFC 3986 URL-query string.
  *
  * @param string $route controller/action
  * @param array  $params
  * @param null   $https
  * @param bool   $asset
  *
  * @return string
  */
 public static function compute($route = '', array $params = array(), $https = null, $asset = false)
 {
     // if your application should work with RFC 3986 URL-query strings
     $conf = Registry::get('conf');
     if ($conf['app']['routeable'] === false) {
         list($controller, $action) = explode('/', $route);
         $params = array_merge(compact('controller', 'action'), $params);
         return Str::ensureTrailing('/', self::format($https, $asset)) . '?' . http_build_query($params, null, '&');
     }
     // otherwise PIMF will serve you cleaner URLs
     $slug = implode('/', $params);
     if ($slug != '') {
         $slug = '/' . $slug;
     }
     return self::to($route, $https, $asset) . $slug;
 }