Exemple #1
0
 public static function get($type)
 {
     $blueprints = new Data\Blueprints('plugin://' . $type);
     $blueprint = $blueprints->get('blueprints');
     $blueprint->name = $type;
     // Load default configuration.
     $file = File\Yaml::instance('plugin://' . "{$type}/{$type}" . YAML_EXT);
     $obj = new Data\Data($file->content(), $blueprint);
     // Override with user configuration.
     $file = File\Yaml::instance('plugin://' . "config/plugins/{$type}" . YAML_EXT);
     $obj->merge($file->content());
     // Save configuration always to user/config.
     $obj->file($file);
     return $obj;
 }
Exemple #2
0
 public function configure($name = null)
 {
     $name = $this->current($name);
     /** @var Config $config */
     $config = $this->grav['config'];
     $themeConfig = Yaml::instance(THEMES_DIR . "{$name}/{$name}.yaml")->content();
     $config->merge(['themes' => [$name => $themeConfig]]);
     /** @var ResourceLocator $locator */
     $locator = $this->grav['locator'];
     // TODO: move
     $registered = stream_get_wrappers();
     $schemes = $config->get("themes.{$name}.streams.schemes", ['theme' => ['paths' => ["user/themes/{$name}"]]]);
     foreach ($schemes as $scheme => $config) {
         if (isset($config['paths'])) {
             $locator->addPath($scheme, '', $config['paths']);
         }
         if (isset($config['prefixes'])) {
             foreach ($config['prefixes'] as $prefix => $paths) {
                 $locator->addPath($scheme, $prefix, $paths);
             }
         }
         if (in_array($scheme, $registered)) {
             stream_wrapper_unregister($scheme);
         }
         $type = !empty($config['type']) ? $config['type'] : 'ReadOnlyStream';
         if ($type[0] != '\\') {
             $type = '\\Grav\\Component\\Filesystem\\StreamWrapper\\' . $type;
         }
         if (!stream_wrapper_register($scheme, $type)) {
             throw new \InvalidArgumentException("Stream '{$type}' could not be initialized.");
         }
     }
 }
Exemple #3
0
 /**
  * Initialize object by loading all the configuration files.
  *
  * @param array $files
  */
 protected function init(array $files)
 {
     $this->updated = true;
     // Combine all configuration files into one larger lookup table (only keys matter).
     $allFiles = $files['user'] + $files['plugins'] + $files['system'];
     // Then sort the files to have all parent nodes first.
     // This is to make sure that child nodes override parents content.
     uksort($allFiles, function ($a, $b) {
         $diff = substr_count($a, '/') - substr_count($b, '/');
         return $diff ? $diff : strcmp($a, $b);
     });
     $systemBlueprints = new Blueprints(SYSTEM_DIR . 'blueprints');
     $pluginBlueprints = new Blueprints(USER_DIR);
     $items = array();
     foreach ($allFiles as $name => $dummy) {
         $lookup = array('system' => SYSTEM_DIR . 'config/' . $name . YAML_EXT, 'plugins' => USER_DIR . $name . '/' . basename($name) . YAML_EXT, 'user' => USER_DIR . 'config/' . $name . YAML_EXT);
         if (strpos($name, 'plugins/') === 0) {
             $blueprint = $pluginBlueprints->get("{$name}/blueprints");
         } else {
             $blueprint = $systemBlueprints->get($name);
         }
         $data = new Data(array(), $blueprint);
         foreach ($lookup as $key => $path) {
             if (is_file($path)) {
                 $data->merge(File\Yaml::instance($path)->content());
             }
         }
         //            $data->validate();
         //            $data->filter();
         // Find the current sub-tree location.
         $current =& $items;
         $parts = explode('/', $name);
         foreach ($parts as $part) {
             if (!isset($current[$part])) {
                 $current[$part] = array();
             }
             $current =& $current[$part];
         }
         // Handle both updated and deleted configuration files.
         $current = $data->toArray();
     }
     $this->items = $items;
     $this->files = $files;
 }
Exemple #4
0
 /**
  * Add meta file for the medium.
  *
  * @param $type
  * @return $this
  */
 public function addMetaFile($type)
 {
     $this->meta[$type] = $type;
     $path = $this->get('path') . '/' . $this->get('filename') . '.meta.' . $type;
     if ($type == 'yaml') {
         $this->merge(Yaml::instance($path)->content());
     } elseif (in_array($type, array('jpg', 'jpeg', 'png', 'gif'))) {
         $this->set('thumb', $path);
     }
     $this->reset();
     return $this;
 }