Stores a config file

@param string      $group
@param string|null $destination

@throws \RuntimeException
198703
public function save($group, $destination = null)
	{
		if ($destination === null)
		{
			$destination = $group;
		}

		if ( ! $this->has($group))
		{
			throw new \RuntimeException('Unable to save non-existig config group: '.$group);
		}

		$destination = $this->ensureDefaultFormat($destination);
		$format = pathinfo($destination, PATHINFO_EXTENSION);
		$handler = $this->getHandler($format);
		$data = $this->get($group);
		$output = $handler->format($data);
		$path = $this->findDestination($destination);

		if ( ! $path)
		{
			throw new \RuntimeException(sprintf('Could not save group "%" as "%s".', $group, $destination));
		}

		return file_put_contents($path, $output);
	}
30976
public function write($contents, $group, $client = null)
	{
		$path = $this->getPath($client, $group);

		if (!$path)
		{
			return false;
		}

		$contents = $this->toContent($contents, $this->format, $this->options);

		return !($this->putContent($path, $contents) === false);
	}
575702
public function copyFile( $from, $to )
	{
		$this->connection->checkConnection();
		$temp	= uniqid( time() ).".temp";
		$reader	= new Net_FTP_Reader( $this->connection );
		$reader->setPath( $this->getPath() );
		if( !$reader->getFile( $from, $temp ) )
			throw new RuntimeException( 'File "'.$from.'" could not be received.' );
		if( !$this->putFile( $temp, $to ) )
		{
			unlink( $temp );
			throw new RuntimeException( 'File "'.$from.'" could not be stored.' );
		}
		unlink( $temp );
		return TRUE;
	}
1355557
public function getConfigFilename($group)
    {
        $conf_files = $this->config->get('conf_files');
        if (!isset($conf_files[$group])) {
            $filename = $this->config['conf_dir'] . '/' . $group . '.json';
            $conf_files[$group] = $filename;
        }
        $this->config->set('conf_files', $conf_files);
        return $conf_files[$group];
    }
59259
protected function createConfigGroupForm(ConfigGroup $group = null)
    {
        $formBuilder = $this->createFormBuilder();
        if ($group) {
            $values = $this->container->get('admin.configuration.configvalue_manager')->getRepository()->findByConfigGroupId($group->getId());
            foreach ($values as $configValue) {
                $sub = $this->container->get('form.factory')->createNamedBuilder(
                    str_replace(':', '___', $configValue->getPath()),
                    'admin_configuration_configvalue_'.$configValue->getConfigType()->getFormType(),
                    $configValue
                );
                $formBuilder->add($sub);
            }
        }

        return $formBuilder->getForm();
    }
764625
public function upload($file, $destination = null)
    {
        if (!file_exists($file)) {
            return;
        }

        // Get contents and destination
        $destination = $destination ?: basename($file);

        $this->put($destination, file_get_contents($file));
    }
916099
protected function loadGroupConfig($group)
    {
        // data from files
        $res = $this->loader->load($group);

        // mark pool dirty
        if (count($res)) {
            $this->setPoolDirty();
        }

        $config = [];
        foreach($res as $grp => $grpData) {
            if (!isset($config[$grp])) {
                $config[$grp] = [];
            }
            foreach ($grpData as $data) {
                $config[$grp] = array_replace_recursive(
                    $config[$grp], $this->fixValue($data)
                );
            }
        }

        // set the whole pool
        if (null === $group) {
            $this->pool = $config;

        // set a group
        } else {
            $this->pool[$group] = $config[$group];
        }
    }
8191
public function saveConfig($group, $environment = '')
    {
        // Path do arquivo
        $path = config_path();

        // Itens
        $items = config($group, []);

        // Nome do arquivo
        $file = (! $environment || ($environment == 'production'))
            ? "{$path}/{$group}.php"
            : "{$path}/{$environment}/{$group}.php";

        // Salvar arquivo
        $code = '<?php' . "\r\n\r\n";
        $code .= 'return ' . var_export($items, true) . ';';
        $this->put($file, $code);
    }
97797
public function setConfigurationFile($configurationFile)
    {
        $search = [$configurationFile, getcwd() . DIRECTORY_SEPARATOR . $configurationFile];
        $found = array_filter($search, 'file_exists');

        if (count($found) == 0) {
            throw new \RuntimeException("Configuration file specified but does not exist");
        }

        $this->write('configurationFile', $found[0]);

        return $this;
    }
728360
private function addGroup($group)
	{
		if($group != null)
		{
			if($this->groups == null)
				$this->groups = array();
			$this->groups[] = $group;
		}
	}
31801
public function load(array $files, Config $config = null)
    {
        if (is_null($config)) {
            $config = new Config();
        }

        if (!$this->isValidFileList($files)) {
            throw new \RuntimeException('Invalid config file list given. At least one config file must exist.');
        }

        foreach ($files as $file) {
            if ($this->isFileExisting($file)) {
                $config->merge(
                    $this->loadFile($file)
                );
            }
        }

        return $config;
    }
1249288
private function ensuredCopyDir($source, $destination)
    {
        try
        {
            $filesList = $this->getContents($source);

            foreach ($filesList as $file)
            {
                $path = $file['path'];
                $dest = explode(DIRECTORY_SEPARATOR, $path, 2);
                $dest = $destination . DIRECTORY_SEPARATOR . $dest[1];

                if ($file['type'] === Filesystem::TYPE_DIRECTORY)
                {
                    $this->copyDir($path, $dest);
                }
                else if ($file['type'] === Filesystem::TYPE_FILE)
                {
                    $this->copyFile($path, $dest);
                }
            }

            return;
        }
        catch (Error $ex)
        {}
        catch (Exception $ex)
        {}

        throw new WriteException("Directory $source could not be copied to $destination.");
    }
105423
public function copy($destination) {
		$destination = $this->getDestination($destination);

		if (!@copy($this->getPathname(), $destination)) {
			throw new FileException(sprintf('Failed to copy %s to %s', $this->pathname, $destination));
		}
	}
434243
public function setConfig(array $config, $file = null)
    {
        $file = !empty($file) ? $file : $this->fileCache;
        if (file_exists($file)) {
            unlink($file);
        }
        (new PhpArray())
                ->setUseBracketArraySyntax(true)
                ->toFile($file, $config);
    }
1035985
public function prepareStore($fieldset = null, $group = null)
    {
        foreach ($this->getFields($fieldset, $group) as $field) {
            $field->prepareStore();
        }
    }
183157
protected function _writeFile($destination, $data)
    {
        $destination = trim($destination);
        if(false === file_put_contents($destination, $data)) {
            throw new Mage_Exception("Can't write to file: " . $destination);
        }
        return true;
    }
406818
private void storeGroup(final Group nextGroup, final RepositoryConnection conn, final boolean isRootGroup)
        throws RepositoryException
    {
        if(conn.hasStatement(null, SesameRealmConstants.OAS_GROUPNAME, this.vf.createLiteral(nextGroup.getName()),
                true, this.getContexts()))
        {
            // TODO: Create an update method
            throw new RuntimeException(
                    "A user with the given identifier already exists. Cannot add a new user with that identifier.");
        }
        
        final URI nextGroupUUID =
                this.vf.createURI("urn:oas:group:", nextGroup.getName() + ":" + UUID.randomUUID().toString());
        
        conn.add(this.vf.createStatement(nextGroupUUID, RDF.TYPE, SesameRealmConstants.OAS_GROUP), this.getContexts());
        
        if(isRootGroup)
        {
            conn.add(this.vf.createStatement(nextGroupUUID, RDF.TYPE, SesameRealmConstants.OAS_ROOTGROUP),
                    this.getContexts());
        }
        
        conn.add(
                this.vf.createStatement(nextGroupUUID, SesameRealmConstants.OAS_GROUPNAME,
                        this.vf.createLiteral(nextGroup.getName())), this.getContexts());
        conn.add(
                this.vf.createStatement(nextGroupUUID, SesameRealmConstants.OAS_GROUPDESCRIPTION,
                        this.vf.createLiteral(nextGroup.getDescription())), this.getContexts());
        conn.add(
                this.vf.createStatement(nextGroupUUID, SesameRealmConstants.OAS_GROUPINHERITINGROLES,
                        this.vf.createLiteral(nextGroup.isInheritingRoles())), this.getContexts());
        
        // only store users who cannot be found based on their identifier
        for(final User nextUser : nextGroup.getMemberUsers())
        {
            if(this.findUser(nextUser.getIdentifier()) == null)
            {
                final URI nextUserUri = this.addUser(nextUser);
            }
        }
        
        if(!nextGroup.getMemberGroups().isEmpty())
        {
            for(final Group nextMemberGroup : nextGroup.getMemberGroups())
            {
                // always set rootGroup parameter to false when recursing into member groups
                this.storeGroup(nextMemberGroup, conn, false);
            }
        }
        
    }