function extend($extensions) { if (!isset($extensions->filters)) { $extensions->filters = []; } if (!isset($extensions->functions)) { $extensions->functions = []; } $extensions->filters += ['array' => function ($object) { return (array) $object; }, 'ceil' => function ($value) { return ceil($value); }, 'local' => function ($alias) { return $this->locale->get($alias); }, 'md5' => function ($value) { return md5($value); }]; $extensions->functions += ['json' => function ($filename) { return \json\decode(\fs\read($this->data . $filename)); }]; foreach ($extensions->filters as $name => $closure) { if ($closure instanceof \Closure) { $this->twig->addFilter(new \Twig_SimpleFilter($name, $closure->bindTo($this, $this))); } else { $options = []; if (isset($closure->escape) and !$closure->escape) { $options['is_safe'] = ['html']; } $this->twig->addFilter(new \Twig_SimpleFilter($name, $closure->function->bindTo($this, $this), $options)); } } foreach ($extensions->functions as $name => $closure) { $this->twig->addFunction(new \Twig_SimpleFunction($name, $closure)); } }
static function create($options, $extensions) { if (isset($options->cache)) { $cache = $options->cache . 'cache.tmp'; if ($www = @fs\read($cache)) { $www = unserialize($www); } else { $www = new www($options); fs\write($cache, serialize($www)); } $www->locale->setup($options->language, $options->country); } else { $www = new www($options); } foreach ($www->templaters as $name => $templater) { $templater->extend(isset($extensions[$name]) ? $extensions[$name] : []); } return $www; }
static function create($options) { if (isset($options->cache)) { $cache = $options->cache . 'cache.tmp'; if ($www = @fs\read($cache)) { $www = unserialize($www); } else { $www = new www($options); fs\write($cache, serialize($www)); } } else { $www = new www($options); } $www->router->bind($options->access->method->bindTo($www, $www)); $www->bind(); if (isset($options->access)) { $www->resolve = $options->access->resolve->bindTo($www, $www); } return $www; }
<?php $this->api = new api($config->schema); $this->locale = new locale($options->language, $options->country); $this->locale->load($config->locale); $this->vars = json\decode(fs\read($config->vars)); if ($config->engine == 'twig') { $this->templaters[$config->engine] = new twig\engine($config->templates, isset($options->cache) ? ['cache' => $options->cache] : [], $config->data, $this->locale); } foreach ($config->pages as $page) { $templater = isset($page->engine) ? $page->engine : $config->engine; $this->router->attach(isset($page->method) ? $page->method : 'GET', new page($page->uri, $page->params, isset($page->template) ? $this->templaters[$templater]->load($page->template) : null, isset($page->script) ? new script($this, $page->script) : null, $this->api)); } foreach ($config->schemas as $name => $src) { $this->schemas[$name] = json\schema::load($src); }
private static function load_schema($filename) { $schema = decode(\fs\read($filename), true); if (isset($schema['extends'])) { $extends = $schema['extends']; unset($schema['extends']); $schema = join(self::load_schema(\fs\path($filename) . '/' . $extends), $schema); } return $schema; }