protected function loadGlobal() { $file = CompiledYamlFile::instance(PRIME_ROOT . '/config/global.yaml'); $data = (array) $file->setCachePath(PRIME_ROOT . '/cache/global')->content(); $file->free(); return $data; }
/** * Read layout from yaml file and return parsed version of it. * * @param string $file * @return array */ public static function read($file) { if (!$file) { return []; } $file = CompiledYamlFile::instance($file); $content = (array) $file->content(); $file->free(); return static::data($content); }
public function __construct($theme) { $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $this->items = CompiledYamlFile::instance($locator("gantry-themes://{$theme}/gantry/theme.yaml"))->content(); $this->offsetSet('name', $theme); $parent = $this->offsetGet('configuration.theme.parent') ?: $theme; $this->offsetSet('parent', $theme !== $parent ? $parent : null); }
public function get($id) { if ($this->content[$id]) { return $this->content[$id]; } $files = $this->locateBlueprints(); if (empty($files[$id])) { throw new \RuntimeException("Settings for '{$id}' not found.", 404); } $filename = key($files[$id]); $item = CompiledYamlFile::instance(GANTRY5_ROOT . '/' . $filename)->content(); return $item; }
public function __construct($theme) { $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $filename = $locator->findResource("gantry-themes://{$theme}/gantry/theme.yaml"); $cache = $locator->findResource("gantry-cache://{$theme}/compiled/yaml", true, true); $file = CompiledYamlFile::instance($filename); $this->items = $file->setCachePath($cache)->content(); $this->offsetSet('name', $theme); $file->free(); $parent = $this->offsetGet('configuration.theme.parent') ?: $theme; $this->offsetSet('parent', $theme !== $parent ? $parent : null); }
public function get($id) { if ($this->particles[$id]) { return $this->particles[$id]; } $files = $this->locateParticles(); if (empty($files[$id])) { throw new \RuntimeException("Settings for '{$id}' not found.", 404); } $filename = key($files[$id]); $particle = CompiledYamlFile::instance(GANTRY5_ROOT . '/' . $filename)->content(); $particle['subtype'] = $id; // TODO: can this be done better or is it fine like that? return $particle; }
public function get($id) { if ($this->blocks[$id]) { return $this->blocks[$id]; } $files = $this->locateBlocks(); if (empty($files[$id])) { throw new \RuntimeException("Settings for '{$id}' not found.", 404); } $filename = key($files[$id]); $file = CompiledYamlFile::instance(GANTRY5_ROOT . '/' . $filename); $particle = $file->content(); $file->free(); return $particle; }
protected function load($language, $section) { $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $section = strtolower($section); $filename = 'gantry-admin://translations/' . $language . '/' . $section . '.yaml'; $file = CompiledYamlFile::instance($filename); if (!$file->exists() && ($pos = strpos($language, '-')) > 0) { $filename = 'gantry-admin://translations/' . substr($language, 0, $pos) . '/' . $section . '.yaml'; $file = CompiledYamlFile::instance($filename); } $cachePath = $locator->findResource('gantry-cache://translations', true, true); $translations = (array) $file->setCachePath($cachePath)->content(); $file->free(); return $translations; }
/** * Create new theme details. * * @param string $theme */ public function __construct($theme) { $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $filename = $locator->findResource("gantry-themes://{$theme}/gantry/theme.yaml"); if (!$filename) { throw new \RuntimeException(sprintf('Theme %s not found', $theme), 404); } $cache = $locator->findResource("gantry-cache://{$theme}/compiled/yaml", true, true); $file = CompiledYamlFile::instance($filename); $this->items = $file->setCachePath($cache)->content(); $file->free(); $this->offsetSet('name', $theme); $parent = (string) $this->offsetGet('configuration.theme.parent', $theme); $parent = $parent != $theme ? $parent : null; $this->offsetSet('parent', $parent); }
/** * Returns style presets for the theme. * * @return Config */ public function presets() { static $presets; if (!$presets) { $gantry = static::gantry(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $filename = $locator->findResource("gantry-theme://gantry/presets.yaml"); $presets = new Config(CompiledYamlFile::instance($filename)->content()); } return $presets; }
/** * Load blueprints. * * @param string $name * * @return BlueprintsForm */ protected function loadBlueprints($name = 'menu') { /** @var UniformResourceLocator $locator */ $locator = $this->container['locator']; $filename = $locator("gantry-admin://blueprints/menu/{$name}.yaml"); $file = CompiledYamlFile::instance($filename); $content = new BlueprintsForm($file->content()); $file->free(); return $content; }
/** * @param string $name * @return static */ public static function loadIndex($name, $autoSave = false) { $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; // Attempt to load the index file. $indexFile = $locator("gantry-config://{$name}/index.yaml"); if ($indexFile) { $file = CompiledYamlFile::instance($indexFile); $index = $file->content(); $file->free(); } // Find out the currently used layout file. $layoutFile = $locator("gantry-config://{$name}/layout.yaml"); if (!$layoutFile) { /** @var Outlines $configurations */ $configurations = $gantry['configurations']; $preset = isset($index['preset']['name']) ? $index['preset']['name'] : $configurations->preset($name); $layoutFile = $locator("gantry-layouts://{$preset}.yaml"); } // Get timestamp for the layout file. $timestamp = $layoutFile ? filemtime($layoutFile) : 0; // If layout index file doesn't exist or is not up to date, build it. if (!isset($index['timestamp']) || $index['timestamp'] != $timestamp) { $layout = isset($preset) ? new static($name, static::preset($preset)) : static::instance($name); $layout->timestamp = $timestamp; $index = $layout->buildIndex(); } if ($autoSave && isset($layout)) { $layout->saveIndex(); } $index += ['name' => $name, 'timestamp' => $timestamp, 'preset' => ['name' => '', 'image' => 'gantry-admin://images/layouts/default.png'], 'positions' => []]; return $index; }
/** * Load single configuration file and append it to the correct position. * * @param string $name Name of the position. * @param string $filename File to be loaded. */ protected function loadFile($name, $filename) { $file = CompiledYamlFile::instance($filename); $this->object->join($name, $file->content(), '/'); }
public function validate($particle) { // Validate only exists for JSON. if (empty($this->params['ajax'])) { $this->undefined(); } // Load particle blueprints and default settings. $validator = new Blueprints(); $name = $particle; if (in_array($particle, ['wrapper', 'section', 'container', 'grid', 'offcanvas'])) { $type = $particle; $particle = null; $file = CompiledYamlFile::instance("gantry-admin://blueprints/layout/{$type}.yaml"); $validator->embed('options', $file->content()); $file->free(); $defaults = []; } else { $type = in_array($particle, ['spacer', 'system', 'position']) ? $particle : 'particle'; $validator->embed('options', $this->container['particles']->get($particle)); $defaults = (array) $this->container['config']->get("particles.{$particle}"); } // Create configuration from the defaults. $data = new Config(['type' => $type], function () use($validator) { return $validator; }); // Join POST data. $data->join('options', $this->request->post->getArray("particles." . $name)); if ($particle) { $data->set('options.enabled', (int) $data->get('options.enabled', 1)); } if ($particle) { if ($type != $particle) { $data->set('subtype', $particle); } $data->join('title', $this->request->post['title'] ?: ucfirst($particle)); } $block = $this->request->post->getArray('block'); if ($block) { // TODO: remove empty items in some other way: foreach ($block as $key => $param) { if ($param === '') { unset($block[$key]); continue; } if ($key == 'size') { $param = round($param, 4); if ($param < 5) { $param = 5; } elseif ($param > 100) { $param = 100; } $block[$key] = $param; } } $data->join('block', $block); } // TODO: validate return new JsonResponse(['data' => $data->toArray()]); }
/** * Get menu configuration. * * @return Config */ public function config() { if (!$this->config) { $gantry = static::gantry(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $menu = $this->params['menu']; $file = CompiledYamlFile::instance($locator("gantry-config://menu/{$menu}.yaml")); $this->config = new Config($file->content()); $this->config->def('settings.title', ucfirst($menu)); $file->free(); } return $this->config; }
/** * Get menu configuration. * * @return Config */ public function config() { if (!$this->config) { $gantry = static::gantry(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $menu = $this->params['menu']; $this->config = new Config(CompiledYamlFile::instance($locator("gantry-config://menu/{$menu}.yaml"))->content()); } return $this->config; }