src/Core.php
/**
     * Generate a php config file to have the setting provided. This is useful 
     * if we want to be able to update our config file through code, such as a 
     * web ui to upadate settings. Platforms like wordpress allow updating the 
     * settings, but do this through a database.
     * @param mixed $settings       - array or variable that we want to save to 
     *                                the file
     * @param string $variableName  - name of the settings variable so that it 
     *                                is reloaded correctly
     * @param string $filePath      - path to the file where we want to save the 
     *                                settings. (overwritten)
     * @return void - creates a config file, or throws an exception if failed.
     * @throws Exception if failed to write to the specified filePath, e.g dont 
     *                   have permissions.
     */
Generate a php config file to have the setting provided. This is useful
if we want to be able to update our config file through code, such as a
web ui to upadate settings. Platforms like wordpress allow updating the
settings, but do this through a database.
@param mixed $settings       - array or variable that we want to save to
the file
@param string $variableName  - name of the settings variable so that it
is reloaded correctly
@param string $filePath      - path to the file where we want to save the
settings. (overwritten)
@return void - creates a config file, or throws an exception if failed.
@throws Exception if failed to write to the specified filePath, e.g dont
have permissions.
Generate a php config file to have the setting provided . This is useful if we want to be able to update our config file through code such as a web ui to upadate settings . Platforms like wordpress allow updating the settings but do this through a database . @param mixed $settings - array or variable that we want to save to the file @param string $variableName - name of the settings variable so that it is reloaded correctly @param string $filePath - path to the file where we want to save the settings . ( overwritten ) @return void - creates a config file or throws an exception if failed . @throws Exception if failed to write to the specified filePath e . g dont have permissions .
public static function generateConfig($settings, $variableName, $filePath)
    {
        $varStr = var_export($settings, true);
        $output = 
            '<?php' . PHP_EOL .
            '$' . $variableName . ' = ' . $varStr . ';';
        $wroteFile = file_put_contents($filePath, $output);
        if ($wroteFile === FALSE)
        {
            $msg = "Failed to generate config file. Check permissions!";
            throw new \Exception($msg);
        }
    }
public static function generateConfig ( $ settings , $ variableName , $ filePath ) { $ varStr = var_export ( $ settings , true ) ; $ output = '<?php' . PHP_EOL . '$' . $ variableName . ' = ' . $ varStr . ';' ; $ wroteFile = file_put_contents ( $ filePath , $ output ) ; if ( $ wroteFile === FALSE ) { $ msg = " Failed to generate config file. Check permissions! " ; throw new \ Exception ( $ msg ) ; } }
Generate a php config file to have the setting provided.
Generate a php config file to have the setting provided .
# file_put_contents returns num bytes written or boolean false if fail