Gush\ConfigFactory::dumpToFile PHP Method

dumpToFile() public static method

The config-file is automatically determined using type.
public static dumpToFile ( Config $config, string $type ) : string
$config Config
$type string
return string
    public static function dumpToFile(Config $config, $type)
    {
        if ($type === Config::CONFIG_LOCAL) {
            $filename = $config->get('local_config');
            if (null === $filename) {
                throw new \RuntimeException('Local configuration is not loaded and therefore it cannot be dumped.');
            }
        } elseif ($type === Config::CONFIG_SYSTEM) {
            $filename = $config->get('home_config');
        } else {
            throw new \InvalidArgumentException(sprintf('Config slot "%s" is not valid for dumping to a file "%s", use either: ' . 'Config::CONFIG_SYSTEM or Config::CONFIG_LOCAL.', $type));
        }
        // Testing compatibility, write directly as there is no risk of problems
        if ('vfs://' === substr($filename, 0, 6)) {
            file_put_contents($filename, Yaml::dump($config->toArray($type)));
        } else {
            self::getFilesystem()->dumpFile($filename, "# Gush configuration file, any comments will be lost.\n" . Yaml::dump($config->toArray($type), 2));
        }
        return $filename;
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->getConfig()->set('meta-header', $this->getMetaHeader(), Config::CONFIG_LOCAL);
     ConfigFactory::dumpToFile($this->getConfig(), Config::CONFIG_LOCAL);
     $this->getHelper('gush_style')->success('Configuration file saved successfully.');
     return self::COMMAND_SUCCESS;
 }
All Usage Examples Of Gush\ConfigFactory::dumpToFile