Exemplo n.º 1
0
 protected static function load(array $values)
 {
     $container = new static($values);
     $container['config_path'] = CACHE_DIR . 'config.php';
     $container['grav'] = $container;
     $container['events'] = function ($c) {
         return new EventDispatcher();
     };
     $container['uri'] = function ($c) {
         return new Uri($c);
     };
     $container['config'] = function ($c) {
         return Config::instance($c);
     };
     $container['cache'] = function ($c) {
         return new Cache($c);
     };
     $container['plugins'] = function ($c) {
         return new Plugins($c);
     };
     $container['themes'] = function ($c) {
         return new Themes($c);
     };
     $container['twig'] = function ($c) {
         return new Twig($c);
     };
     $container['taxonomy'] = function ($c) {
         return new Taxonomy($c);
     };
     $container['pages'] = function ($c) {
         return new Page\Pages($c);
     };
     $container['assets'] = function ($c) {
         return new Assets();
     };
     $container['page'] = function ($c) {
         $page = $c['pages']->dispatch($c['uri']->route());
         if (!$page || !$page->routable()) {
             $event = $c->fireEvent('onPageNotFound');
             if (isset($event->page)) {
                 $page = $event->page;
             } else {
                 throw new \RuntimeException('Page Not Found', 404);
             }
         }
         return $page;
     };
     $container['output'] = function ($c) {
         return $c['twig']->processSite($c['uri']->extension());
     };
     $container['browser'] = function ($c) {
         return new Browser();
     };
     $container->register(new StreamsServiceProvider());
     return $container;
 }
Exemplo n.º 2
0
 /**
  * Encode configuration object into RAW string (PHP class).
  *
  * @param \Grav\Common\Config $var
  * @return string
  * @throws \RuntimeException
  */
 protected function encode($var)
 {
     if (!$var instanceof \Grav\Common\Config) {
         throw new \RuntimeException('Provided data is not configuration');
     }
     // Build the object variables string
     $vars = array();
     $options = $var->toArray();
     foreach ($options as $k => $v) {
         if (is_int($v)) {
             $vars[] = "\tpublic \$" . $k . " = " . $v . ";";
         } elseif (is_bool($v)) {
             $vars[] = "\tpublic \$" . $k . " = " . ($v ? 'true' : 'false') . ";";
         } elseif (is_scalar($v)) {
             $vars[] = "\tpublic \$" . $k . " = '" . addcslashes($v, '\\\'') . "';";
         } elseif (is_array($v) || is_object($v)) {
             $vars[] = "\tpublic \$" . $k . " = " . $this->encodeArray((array) $v) . ";";
         }
     }
     $vars = implode("\n", $vars);
     return "<?php\nnamespace Grav;\n\nclass Config extends \\Grav\\Common\\Config {\n {$vars}\n}";
 }