public function __construct($settings, $argc) { parent::__construct(); // Building the USAGE output of the command line version $help = "Moodle Data Generator. Generates Data for Moodle sites. Good for benchmarking and other tests.\n\n" . "FOR DEVELOPMENT PURPOSES ONLY! DO NOT USE ON A PRODUCTION SITE!\n\n" . "Note: By default the script attempts to fill DB tables prefixed with tst_\n" . "To override the prefix, use the -P (--database_prefix) setting.\n\n" . "Usage: {$settings[0]}; [OPTION] ...\n" . "Options:\n" . " -h, -?, -help, --help This output\n"; foreach ($this->settings as $argument) { $equal = ''; if (!empty($argument->type)) { $equal = "={$argument->type}"; } $padding1 = 5 - strlen($argument->short); $padding2 = 30 - (strlen($argument->long) + strlen($equal)); $paddingstr1 = ''; for ($i = 0; $i < $padding1; $i++) { $paddingstr1 .= ' '; } $paddingstr2 = ''; for ($i = 0; $i < $padding2; $i++) { $paddingstr2 .= ' '; } $help .= " -{$argument->short},{$paddingstr1}--{$argument->long}{$equal}{$paddingstr2}{$argument->help}\n"; } $help .= "\nEmail nicolas@moodle.com for any suggestions or bug reports.\n"; if ($argc == 1 || in_array($settings[1], array('--help', '-help', '-h', '-?'))) { echo $help; die; } else { $this->do_generation = true; $settings = $this->_arguments($settings); $argscount = 0; foreach ($this->settings as $argument) { $value = null; if (in_array($argument->short, array_keys($settings))) { $value = $settings[$argument->short]; unset($settings[$argument->short]); } elseif (in_array($argument->long, array_keys($settings))) { $value = $settings[$argument->long]; unset($settings[$argument->long]); } if (!is_null($value)) { if (!empty($argument->type) && ($argument->type == 'mod1,mod2...' || $argument->type == 'SELECT')) { $value = explode(',', $value); } $this->set($argument->long, $value); $argscount++; } } // If some params are left in argv, it means they are not supported if ($argscount == 0 || count($settings) > 0) { echo $help; die; } } $this->connect(); }