protected function __construct() { parent::__construct(); $gantry = Gantry::instance(); if (isset($gantry['file.yaml.cache.path'])) { $this->setCachePath($gantry['file.yaml.cache.path']); } }
protected function loadYaml($test, $type = 'blueprint') { $file = YamlFile::instance(__DIR__ . "/data/{$type}/{$test}.yaml"); $content = $file->content(); $file->free(); return $content; }
/** * Save assignments for the configuration. * * @param array $data */ public function save(array $data) { $data = $data['assignments']; foreach ($data as $tname => &$type) { foreach ($type as $gname => &$group) { foreach ($group as $key => $value) { if (!$value) { unset($group[$key]); } else { $group[$key] = (bool) $value; } } if (empty($group)) { unset($type[$gname]); } } if (empty($type)) { unset($data[$tname]); } } $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; // Save layout into custom directory for the current theme. $save_dir = $locator->findResource("gantry-config://{$this->configuration}", true, true); $filename = "{$save_dir}/assignments.yaml"; $file = YamlFile::instance($filename); $file->save($data); $file->free(); }
/** * @param string $filename * @return string */ protected function loadFile($filename) { $file = YamlFile::instance(__DIR__ . "/data/blueprint/{$filename}.yaml"); $content = $file->content(); $file->free(); return $content; }
public function onGlobalSave(Event $event) { $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; $filename = 'config://plugins/gantry5.yaml'; $file = YamlFile::instance($locator->findResource($filename, true, true)); $content = $file->content(); $content['production'] = (bool) $event->data['production']; $file->save($content); $file->free(); }
protected function __construct() { parent::__construct(); $gantry = Gantry::instance(); /** @var Config $global */ $global = $gantry['global']; if (!$global->get('compile_yaml', 1)) { $this->caching(false); } if (isset($gantry['file.yaml.cache.path'])) { $this->setCachePath($gantry['file.yaml.cache.path']); } }
/** * Persists to disk the theme parameters currently stored in the Grav Config object * * @param string $theme_name The name of the theme whose config it should store. * * @return true */ public static function saveConfig($theme_name) { if (!$theme_name) { return false; } $locator = Grav::instance()['locator']; $filename = 'config://themes/' . $theme_name . '.yaml'; $file = YamlFile::instance($locator->findResource($filename, true, true)); $content = Grav::instance()['config']->get('themes.' . $theme_name); $file->save($content); $file->free(); return true; }
protected function saveItem($group, $id, $data) { /** @var UniformResourceLocator $locator */ $locator = $this->container['locator']; // Save layout into custom directory for the current theme. $configuration = $this->params['configuration']; $save_dir = $locator->findResource("gantry-config://{$configuration}/content", true, true); $filename = "{$save_dir}/{$group}/{$id}.yaml"; $file = YamlFile::instance($filename); if (!is_array($data)) { if ($file->exists()) { $file->delete(); } } else { $blueprints = new BlueprintsForm($this->container['content']->get("{$group}/{$id}")); $config = new Config($data, function () use($blueprints) { return $blueprints; }); $file->save($config->toArray()); } $file->free(); }
public function save($id = null) { $resource = $this->loadResource($id); $data = $this->build($this->request->post); /** @var UniformResourceLocator $locator */ $locator = $this->container['locator']; $filename = $locator->findResource("gantry-config://menu/{$resource->name()}.yaml", true, true); // Fire save event. $event = new Event(); $event->gantry = $this->container; $event->theme = $this->container['theme']; $event->controller = $this; $event->resource = $id; $event->menu = $data; $this->container->fireEvent('admin.menus.save', $event); $file = YamlFile::instance($filename); $file->settings(['inline' => 99]); $file->save($data->toArray()); $file->free(); }
public function save($id = null) { /** @var Config $config */ $config = $this->container['config']; if ($id) { $data = (array) $config->get('styles'); $data[$id] = $this->request->post->getArray(); } else { $data = $this->request->post->getArray('styles'); } /** @var UniformResourceLocator $locator */ $locator = $this->container['locator']; // Save layout into custom directory for the current theme. $configuration = $this->params['configuration']; $save_dir = $locator->findResource("gantry-config://{$configuration}", true, true); $filename = "{$save_dir}/styles.yaml"; $file = YamlFile::instance($filename); $file->save($data); // Fire save event. $event = new Event(); $event->gantry = $this->container; $event->theme = $this->container['theme']; $event->controller = $this; $event->data = $data; $this->container->fireEvent('admin.styles.save', $event); // Apply new styles to the current configuration and compile CSS. $config->join('styles', $data); $this->compileSettings(); return $id ? $this->display($id) : $this->index(); }
/** * Save layout. * * @param bool $cascade * @return $this */ public function save($cascade = true) { if (!$this->name) { throw new \LogicException('Cannot save unnamed layout'); } $name = strtolower(preg_replace('|[^a-z\\d_-]|ui', '_', $this->name)); $gantry = Gantry::instance(); /** @var UniformResourceLocator $locator */ $locator = $gantry['locator']; // If there are atoms in the layout, copy them into outline configuration. $atoms = $this->atoms(); if (is_array($atoms)) { if ($cascade) { // Save layout into custom directory for the current theme. $filename = $locator->findResource("gantry-config://{$name}/page/head.yaml", true, true); $file = YamlFile::instance($filename); $config = new Config($file->content()); $file->save($config->set('atoms', json_decode(json_encode($atoms), true))->toArray()); $file->free(); } } // Remove atoms from the layout. foreach ($this->items as $key => $section) { if ($section->type === 'atoms') { unset($this->items[$key]); } } $filename = $locator->findResource("gantry-config://{$name}/layout.yaml", true, true); $file = CompiledYamlFile::instance($filename); $file->settings(['inline' => 20]); $file->save(LayoutReader::store($this->preset, $this->items)); $file->free(); $this->exists = true; return $this; }
/** * @param UniformResourceLocator $locator * @throws \InvalidArgumentException */ protected function check(UniformResourceLocator $locator) { $streams = isset($this->items['streams']['schemes']) ? $this->items['streams']['schemes'] : null; if (!is_array($streams)) { throw new \InvalidArgumentException('Configuration is missing streams.schemes!'); } $diff = array_keys(array_diff_key($this->streams, $streams)); if ($diff) { throw new \InvalidArgumentException(sprintf('Configuration is missing keys %s from streams.schemes!', implode(', ', $diff))); } if (!$locator->findResource('environment://config', true)) { // If environment does not have its own directory, remove it from the lookup. $this->set('streams.schemes.environment.prefixes', ['config' => []]); $this->initializeLocator($locator); } // Create security.yaml if it doesn't exist. $filename = $locator->findResource('config://security.yaml', true, true); $file = YamlFile::instance($filename); if (!$file->exists()) { $file->save(['salt' => Utils::generateRandomString(14)]); $file->free(); } }
public function installMenus(array $menus = null, $parent = 1) { if ($menus === null) { $name = $this->extension->name; $path = JPATH_SITE . '/templates/' . $name; $file = YamlFile::instance($path . '/install/menus.yaml'); $menus = (array) $file->content(); $file->free(); } foreach ($menus as $menutype => $menu) { $title = !empty($menu['title']) ? $menu['title'] : ucfirst($menutype); $description = !empty($menu['description']) ? $menu['description'] : ''; $exists = $this->getMenu($menutype)->id; // If $parent = 0, do dry run. if ((int) $parent && !$exists) { $this->deleteMenu($menutype, true); $this->createMenu($menutype, $title, $description); } if (!empty($menu['items'])) { $this->addMenuItems($menutype, $menu['items'], (int) $parent); } } }
/** * Persists to disk the plugin parameters currently stored in the Grav Config object * * @param string $plugin_name The name of the plugin whose config it should store. * * @return true */ public static function saveConfig($plugin_name) { if (!$plugin_name) { return false; } $grav = Grav::instance(); $locator = $grav['locator']; $filename = 'config://plugins/' . $plugin_name . '.yaml'; $file = YamlFile::instance($locator->findResource($filename, true, true)); $content = $grav['config']->get('plugins.' . $plugin_name); $file->save($content); $file->free(); return true; }
public function save($id = null) { /** @var Config $config */ $config = $this->container['config']; if ($id) { $data = (array) $config->get('styles'); $data[$id] = $this->request->post->getArray(); } else { $data = $this->request->post->getArray('styles'); } /** @var UniformResourceLocator $locator */ $locator = $this->container['locator']; // Save layout into custom directory for the current theme. $configuration = $this->params['configuration']; $save_dir = $locator->findResource("gantry-config://{$configuration}", true, true); $filename = "{$save_dir}/styles.yaml"; $file = YamlFile::instance($filename); $file->save($data); $file->free(); // Fire save event. $event = new Event(); $event->gantry = $this->container; $event->theme = $this->container['theme']; $event->controller = $this; $event->data = $data; $this->container->fireEvent('admin.styles.save', $event); // Compile CSS. $warnings = $this->compileSettings(); if (empty($this->params['ajax'])) { // FIXME: HTML request: Output compiler warnings!! return $id ? $this->display($id) : $this->index(); } if ($warnings) { $this->params += ['warnings' => $warnings]; return new JsonResponse(['html' => $this->container['admin.theme']->render('@gantry-admin/layouts/css-warnings.html.twig', $this->params), 'warning' => true, 'title' => 'CSS Compiled With Warnings']); } else { return new JsonResponse(['html' => 'The CSS was successfully compiled', 'title' => 'CSS Compiled']); } }
public function save($id = null) { $resource = $this->loadResource($id); $data = $this->build($_POST); /** @var UniformResourceLocator $locator */ $locator = $this->container['locator']; $filename = $locator->findResource("gantry-config://menu/{$resource->name()}.yaml", true, true); $file = YamlFile::instance($filename); $file->settings(['inline' => 99]); $file->save($data->toArray()); }