/** * * @param Resources $context * @return self */ public static function generate(Resources $context) { $request = $context->getRequest(); $config = $context->config('session'); // Sets the cookie path (aka session namespace) $site = $config->value('site'); $path = rtrim($request->getRoot(), '/') . '/'; // Creates the save handler $key = trim($config->value('save_handler')); $pre = substr($key, 0, 1); if ($pre == '#') { $resource = trim(substr($key, 1)); $handler = $context->get($resource); } elseif ($key) { if ($pre == '~') { $key = static::getDefaultNamespace() . '\\' . trim(substr($key, 1)); } $handler = $context->create($key); } else { $handler = null; } if ($handler instanceof DbSaveHandler) { $handler->setSite($site)->setPath($path); } // Create the manager and registers the save handler $manager = new static(); if ($handler) { $manager->registerSaveHandler($handler); } return $manager; }
/** * @param Resources $context */ public static function generate(Resources $context) { $config = $context->config('i18n'); $instance = new static(); $instance->setBaseDir($config->value('base_dir')); return $instance; }
/** * Factory function * @param Resources $context */ public static function generate(Resources $context) { /* @var $config Node\Param */ $config = $context->config('view'); $renderer = new static(); $renderer->setScriptDir($config->value('template_dir'))->setScriptsuffix($config->value('script_suffix', '.phtml'))->setHelpers($context->get('helpers')); return $renderer; }
/** * @param Resources $context * @return Closure */ public static function getUriFactory($context) { return function () use($context) { $router = $context->get('router'); $request = $context->getRequest(); $base = $request->getRoot(); $gen = new UriFactory(); $gen->setBase($base)->setRouter($router); return $gen; }; }
/** * Factory function * @param Resources $context * @return self */ public static function create(Resources $context, $databaseKey = 'database') { /* @var $config Param */ $config = $context->config('session.database'); $logger = $context->get('logger'); $database = $context->get($databaseKey); $path = ini_get('session.cookie_path'); $handler = new static($database, $config); $handler->setLogger($logger)->setPath($path); return $handler; }
/** * @param Resources $context */ public static function generate(Resources $context) { $config = $context->config('view'); $helpers = $context->get('helpers'); $engine = new Engine(); $engine->setEscape($helpers->get('escape')); $engine->getScriptLoader()->setBaseDir($config->value('template_dir'))->setFileSuffix($config->value('script_suffix', '.mustache')); $renderer = new static(); $renderer->setEngine($engine)->setHelpers($helpers)->setLogger($context->get('logger')); return $renderer; }
/** * Factory method * @param Resources $context * @return \static */ public static function generate(Resources $context) { $fuse = new static(); if ($context->has('logger')) { $fuse->setLogger($context->get('logger')); } $env = $context->config('application.environment'); if ($env->exists()) { $fuse->setEnvironment($env->str()); } return $fuse; }
/** * Creates an error model * @throws Exception\RuntimeException */ protected function createError(Resources $context, $message, $status = 404) { $response = $context->getResponse(); $config = $context->getConfig(); $layout = $config->value('view.error_layout'); if (!$layout) { throw new Exception\RuntimeException("[ERROR LAYOUT NOT SET] {$message}", 2); } $debug = $config->value('application.environment') == 'development'; $error = array('status' => array('code' => $status, 'text' => Message\HttpStatus::message($status)), 'debug' => $debug); if ($debug) { $error['message'] = $message; $error['backtrace'] = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS); } $response->setStatusCode($status); $model = new ViewModel(); $model->setLayout($layout)->setTemplate(false)->setData(['errors' => [$error]]); return $model; }
/** * @param Resources $context * @return boolean */ public static function autostart(Resources $context) { $config = $context->get('config'); // [php] $ini = $config->node('php'); foreach (Param\Util::leaves($ini) as $key => $value) { if (!is_scalar($value) && !is_null($value)) { $type = is_object($value) ? get_class($value) : gettype($value); throw new Exception\RuntimeException("INI parameter '{$key}' is of wrong type ({$type})"); } ini_set($key, $value); } // [locale] $info = array(); $locale = $config->node('locale'); foreach ($locale as $category => $spec) { $info[$category] = setlocale($category, $spec->getData()); } $context->setResource('locale', $info); return true; }
/** * @param Resources $mvc * http://localhost/dev/okapi/test/instance/session */ public function sessionAction(Resources $mvc) { /* @var $sess Session */ $req = $mvc->get('request'); $uri = $mvc->helper('uri'); $sess = $mvc('session'); $post = $mvc->input('POST'); $ttl = $mvc->config('php.session.gc_maxlifetime'); if ($req->isMethod('POST')) { $action = $post->get('action'); if ($action == 'open') { $sess->open('Testinator'); $sess['content'] = $post->get('content'); } else { $sess->resume(); } if ($action == 'close') { $sess->close(); } elseif ($action == 'update') { $sess['content'] = $post->get('content'); } } else { $sess->resume(); } $content = isset($sess['content']) ? $sess['content'] : null; return ['base' => $uri->route('tests', ['action' => 'session', '**' => '']), 'content' => $content, 'ttl' => $ttl, 'dump' => $this->jsonDump($sess->data())]; }
/** * * @param Resources $resources */ public static function generate(Resources $resources) { $config = $resources->config('routes'); return new static($config); }