123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- <?php
- /**
- * @package Grav\Common\Config
- *
- * @copyright Copyright (C) 2015 - 2019 Trilby Media, LLC. All rights reserved.
- * @license MIT License; see LICENSE file for details.
- */
- namespace Grav\Common\Config;
- use Grav\Common\File\CompiledYamlFile;
- class CompiledConfig extends CompiledBase
- {
- /**
- * @var callable Blueprints loader.
- */
- protected $callable;
- /**
- * @var bool
- */
- protected $withDefaults;
- public function __construct($cacheFolder, array $files, $path)
- {
- parent::__construct($cacheFolder, $files, $path);
- $this->version = 1;
- }
- /**
- * Set blueprints for the configuration.
- *
- * @param callable $blueprints
- * @return $this
- */
- public function setBlueprints(callable $blueprints)
- {
- $this->callable = $blueprints;
- return $this;
- }
- /**
- * @param bool $withDefaults
- * @return mixed
- */
- public function load($withDefaults = false)
- {
- $this->withDefaults = $withDefaults;
- return parent::load();
- }
- /**
- * Create configuration object.
- *
- * @param array $data
- */
- protected function createObject(array $data = [])
- {
- if ($this->withDefaults && empty($data) && \is_callable($this->callable)) {
- $blueprints = $this->callable;
- $data = $blueprints()->getDefaults();
- }
- $this->object = new Config($data, $this->callable);
- }
- /**
- * Finalize configuration object.
- */
- protected function finalizeObject()
- {
- $this->object->checksum($this->checksum());
- $this->object->timestamp($this->timestamp());
- }
- /**
- * Function gets called when cached configuration is saved.
- */
- public function modified()
- {
- $this->object->modified(true);
- }
- /**
- * 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(), '/');
- $file->free();
- }
- }
|