Helper\Option::getConfig PHP Method

getConfig() public static method

public static getConfig ( $k )
    public static function getConfig($k)
    {
        if (!file_exists(DATA_PATH . "Config.php")) {
            return false;
        }
        $str = file_get_contents(DATA_PATH . "Config.php");
        preg_match("/define\\('" . preg_quote($k) . "', '(.*)'\\);/", $str, $res);
        if (count($res) > 0) {
            return $res[1];
        }
        return null;
    }

Usage Example

Beispiel #1
0
     @(include DATA_PATH . 'Config.php');
 } catch (PDOException $e) {
     echo colorize('Database not available! Please modify ./Data/Config.php and try again', 'WARNING') . PHP_EOL;
     break;
 }
 if (Option::getConfig('ENCRYPT_KEY') == 'Please generate key and paste here') {
     Option::setConfig('ENCRYPT_KEY', Option::createKey());
 }
 if (Option::getConfig('COOKIE_KEY') === null) {
     $str = file_get_contents(DATA_PATH . 'Config.php');
     preg_match("/define\\('ENCRYPT_KEY', '(.*)'\\);/", $str, $res);
     if (count($res) >= 1) {
         $str2 = preg_replace("/define\\('ENCRYPT_KEY', '(.*)'\\);/", $res[0] . PHP_EOL . "define('COOKIE_KEY', '" . Option::createKey() . "');", $str);
     }
     file_put_contents(DATA_PATH . 'Config.php', $str2);
 } elseif (Option::getConfig('COOKIE_KEY') == 'Please generate key and paste here' || Option::getConfig('COOKIE_KEY') == '') {
     Option::setConfig('COOKIE_KEY', Option::createKey());
 }
 echo 'Done!' . PHP_EOL;
 echo 'Now migrating database...' . PHP_EOL;
 if (PATH_SEPARATOR != ':') {
     $phinxCommand = ROOT_PATH . 'Package\\bin\\phinx.bat';
 } else {
     $phinxCommand = PHP_BINARY . ' ' . ROOT_PATH . 'Package/robmorgan/phinx/bin/phinx';
 }
 exec($phinxCommand . ' migrate', $return_arr, $return_arr2);
 print_arr($return_arr);
 if (stripos($return_arr[count($return_arr) - 1], 'All Done.') === false) {
     echo colorize(PHP_EOL . PHP_EOL . 'Failed to migrate database, you can try it manually: ', 'WARNING') . colorize('./Package/bin/phinx migrate', 'WARNING') . PHP_EOL;
     // rollback
     exec($phinxCommand . ' rollback', $return_arr, $return_arr2);