private function createConfig($root, $pearConfDir) { $old = error_reporting(0); $windows = $this->isWindows(); $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR; $root = preg_replace(array('!\\\\+!', '!/+!', "!{$ds2}+!"), array('/', '/', '/'), $root); if ($root[0] != '/') { if ($windows) { throw new Exception('Root directory must be an absolute path beginning ' . 'with "/", was: "' . $root . '"'); } if (!preg_match('/^[A-Za-z]:/', $root)) { throw new Exception('Root directory must be an absolute path beginning ' . 'with "\\" or "C:\\", was: "' . $root . '"'); } } if ($windows) { $root = str_replace('/', '\\', $root); } if (!file_exists($pearConfDir) && !@touch($pearConfDir)) { throw new Exception('Could not create "' . $pearConfDir . '"'); } $config = new PEAR_Config($pearConfDir, '#no#system#config#', false, false); if ($root[strlen($root) - 1] == '/') { $root = substr($root, 0, strlen($root) - 1); } $config->noRegistry(); $config->set('php_dir', $windows ? "{$root}" : "{$root}", 'user'); $config->set('data_dir', $windows ? "{$root}\\pear\\data" : "{$root}/data"); $config->set('www_dir', $windows ? "{$root}\\pear\\www" : "{$root}/pear/www"); $config->set('cfg_dir', $windows ? "{$root}\\pear\\cfg" : "{$root}/pear/cfg"); $config->set('ext_dir', $windows ? "{$root}\\pear\\ext" : "{$root}/pear/ext"); $config->set('doc_dir', $windows ? "{$root}\\pear\\docs" : "{$root}/pear/docs"); $config->set('test_dir', $windows ? "{$root}\\pear\\tests" : "{$root}/pear/tests"); $config->set('cache_dir', $windows ? "{$root}\\pear\\cache" : "{$root}/pear/cache"); $config->set('download_dir', $windows ? "{$root}\\pear\\download" : "{$root}/pear/download"); $config->set('temp_dir', $windows ? "{$root}\\pear\\temp" : "{$root}/pear/temp"); $config->set('bin_dir', $windows ? "{$root}\\" : "{$root}/"); $config->writeConfigFile(); error_reporting($old); return $config; }
function doConfigCreate($command, $options, $params) { if (count($params) != 2) { return PEAR::raiseError('config-create: must have 2 parameters, root path and ' . 'filename to save as'); } $root = $params[0]; // Clean up the DIRECTORY_SEPARATOR mess $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR; $root = preg_replace(array('!\\\\+!', '!/+!', "!{$ds2}+!"), array('/', '/', '/'), $root); if ($root[0] != '/') { if (!isset($options['windows'])) { return PEAR::raiseError('Root directory must be an absolute path beginning ' . 'with "/", was: "' . $root . '"'); } if (!preg_match('/^[A-Za-z]:/', $root)) { return PEAR::raiseError('Root directory must be an absolute path beginning ' . 'with "\\" or "C:\\", was: "' . $root . '"'); } } $windows = isset($options['windows']); if ($windows) { $root = str_replace('/', '\\', $root); } if (!file_exists($params[1]) && !@touch($params[1])) { return PEAR::raiseError('Could not create "' . $params[1] . '"'); } $params[1] = realpath($params[1]); $config = new PEAR_Config($params[1], '#no#system#config#', false, false); if ($root[strlen($root) - 1] == '/') { $root = substr($root, 0, strlen($root) - 1); } $config->noRegistry(); $config->set('php_dir', $windows ? "{$root}\\pear\\php" : "{$root}/pear/php", 'user'); $config->set('data_dir', $windows ? "{$root}\\pear\\data" : "{$root}/pear/data"); $config->set('www_dir', $windows ? "{$root}\\pear\\www" : "{$root}/pear/www"); $config->set('cfg_dir', $windows ? "{$root}\\pear\\cfg" : "{$root}/pear/cfg"); $config->set('ext_dir', $windows ? "{$root}\\pear\\ext" : "{$root}/pear/ext"); $config->set('doc_dir', $windows ? "{$root}\\pear\\docs" : "{$root}/pear/docs"); $config->set('test_dir', $windows ? "{$root}\\pear\\tests" : "{$root}/pear/tests"); $config->set('cache_dir', $windows ? "{$root}\\pear\\cache" : "{$root}/pear/cache"); $config->set('download_dir', $windows ? "{$root}\\pear\\download" : "{$root}/pear/download"); $config->set('temp_dir', $windows ? "{$root}\\pear\\temp" : "{$root}/pear/temp"); $config->set('bin_dir', $windows ? "{$root}\\pear" : "{$root}/pear"); $config->writeConfigFile(); $this->_showConfig($config); $this->ui->outputData('Successfully created default configuration file "' . $params[1] . '"', $command); }
public function create() { $old = error_reporting(0); $root = $this->root; $configFile = $root . '/.pearrc'; $config = new \PEAR_Config($configFile, '#no#system#config#', false, false); $config->noRegistry(); $config->set('php_dir', $root, 'user'); $config->set('data_dir', "{$root}/pear/data"); $config->set('www_dir', "{$root}/pear/www"); $config->set('cfg_dir', "{$root}/pear/cfg"); $config->set('ext_dir', "{$root}/pear/ext"); $config->set('doc_dir', "{$root}/pear/docs"); $config->set('test_dir', "{$root}/pear/tests"); $config->set('cache_dir', "{$root}/pear/cache"); $config->set('download_dir', "{$root}/pear/download"); $config->set('temp_dir', "{$root}/pear/temp"); $config->set('bin_dir', "{$root}/"); $config->writeConfigFile(); error_reporting($old); $this->prepare(); }