private static function loadConfig(Container $container) { global $argv; $configPaths = array(); $bootstrapOverride = null; foreach ($argv as $arg) { if ($configFile = self::parseOption($arg, 'config')) { if (!file_exists($configFile)) { echo sprintf('Config file "%s" does not exist', $configFile) . PHP_EOL; exit(1); } $configPaths = array($configFile); } if ($value = self::parseOption($arg, 'bootstrap', 'b')) { $bootstrapOverride = $value; } } if (empty($configPaths)) { $configPaths = array(getcwd() . '/phpbench.json', getcwd() . '/phpbench.json.dist'); } foreach ($configPaths as $configPath) { if (!file_exists($configPath)) { continue; } $config = file_get_contents($configPath); try { $parser = new JsonParser(); $parser->parse($config); } catch (ParsingException $e) { echo 'Error parsing config file:' . PHP_EOL . PHP_EOL; echo $e->getMessage(); exit(1); } $config = json_decode($config, true); $config['config_path'] = $configPath; if (isset($config['bootstrap'])) { $config['bootstrap'] = self::getBootstrapPath(dirname($configPath), $config['bootstrap']); } $container->mergeParameters($config); } if ($bootstrapOverride) { $container->setParameter('bootstrap', self::getBootstrapPath(getcwd(), $bootstrapOverride)); } }
private function relativizeConfigPath(Container $container) { if (null === ($path = $container->getParameter('path'))) { return; } if (substr($path, 0, 1) === '/') { return; } $container->setParameter('path', sprintf('%s/%s', dirname($container->getParameter('config_path')), $path)); }