예제 #1
0
 /**
  * Register a new plugin for autoloading.
  * 
  */
 private function addPlugin($pluginName)
 {
     //    nbLogger::getInstance()->logLine('Loading Plugin <comment>' . $pluginName . '</comment>...');
     if (key_exists($pluginName, $this->plugins)) {
         return true;
     }
     foreach ($this->pluginDirs as $dir) {
         $path = $dir . '/' . $pluginName;
         if (is_dir($path)) {
             $this->plugins[$pluginName] = $path;
         }
     }
     if (!key_exists($pluginName, $this->plugins)) {
         throw new Exception(sprintf('Plugin %s not found', $pluginName));
     }
     nbAutoload::getInstance()->addDirectory($this->plugins[$pluginName] . '/lib', '*.php', true);
     nbAutoload::getInstance()->addDirectory($this->plugins[$pluginName] . '/command', '*Command.php', true);
     nbAutoload::getInstance()->addDirectory($this->plugins[$pluginName] . '/vendor');
     self::$commandLoader->addCommandsFromDir($this->plugins[$pluginName] . '/command');
     if (is_dir($this->plugins[$pluginName] . '/test/unit')) {
         $testDirs = nbConfig::get('nb_plugin_test_dirs', array());
         $testDirs[] = $this->plugins[$pluginName] . '/test/unit';
         nbConfig::set('nb_plugin_test_dirs', array_unique($testDirs));
     }
     if (!file_exists($this->plugins[$pluginName] . '/config/config.yml')) {
         return true;
     }
     $yamlParser = new nbYamlConfigParser();
     $yamlParser->parseFile($this->plugins[$pluginName] . '/config/config.yml', '', true);
 }
예제 #2
0
function getBuildVersion($versionFile)
{
    if (file_exists($versionFile)) {
        $configParser = new nbYamlConfigParser();
        $configParser->parseFile($versionFile);
        $version = nbConfig::get('version');
        $arrayVersion = array();
        $arrayVersion = preg_split('/\\./', $version);
        return $arrayVersion[3];
    }
}
예제 #3
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     $versionFile = $arguments['version-file'];
     if (!file_exists($versionFile)) {
         throw new Exception('Version file: ' . $versionFile . ' does not exist');
     }
     $configParser = new nbYamlConfigParser();
     $configParser->parseFile($versionFile);
     $initialVersion = nbConfig::get('version');
     $arrayVersion = array();
     $arrayVersion = preg_split('/\\./', $initialVersion);
     $arrayVersion[3]++;
     $finalVersion = join('.', $arrayVersion);
     nbFileSystem::replaceTokens($initialVersion, $finalVersion, $versionFile);
     return true;
 }
예제 #4
0
<?php

require_once dirname(__FILE__) . '/../../../bootstrap/unit.php';
$dataDir = dirname(__FILE__) . '/../../../data/config';
$applicationFile = $dataDir . '/application.config.yml';
$machineFile = $dataDir . '/machine.config.yml';
$configFile1 = $dataDir . '/parser1.config.yml';
$configFile2 = $dataDir . '/parser2.config.yml';
$t = new lime_test(16);
$configuration = new nbConfiguration();
$parser = new nbYamlConfigParser($configuration);
$t->comment('Test get');
$yaml = <<<EOF
key1: value
key2: %key1%
key3_subkey1: %key2%
EOF;
$t->comment('Test parse');
$parser->parse($yaml);
$t->is($configuration->get('key1'), 'value', '->parse() parse a yaml string and set configuration keys');
$t->is($configuration->get('key2'), '%key1%', '->parse() by default does not replace tokens');
$t->is($configuration->get('key3_subkey1'), '%key2%', '->parse() by default does not replace tokens');
$configuration->reset();
$parser->parse($yaml, 'myprefix');
$t->is($configuration->get('myprefix_key1'), 'value', '->parse() can accept a prefix for config keys');
$t->is($configuration->get('myprefix_key2'), '%key1%', '->parse() can accept a prefix for config keys');
$configuration->reset();
$parser->parse($yaml, '', true);
$t->is($configuration->get('key2'), $configuration->get('key1'), '->parse() can replace tokens');
$t->is($configuration->get('key2'), 'value', '->parse() can replace tokens');
$t->is($configuration->get('key3_subkey1'), $configuration->get('key1'), '->parse() can replace tokens');
예제 #5
0
 protected function execute(array $arguments = array(), array $options = array())
 {
     $this->logLine('Diem Deploy');
     $configParser = new nbYamlConfigParser();
     $configParser->parseFile($arguments['config-file']);
     $symfonyExePath = nbConfig::get('symfony_project-deploy_symfony-root-dir');
     // Put website offline
     if (nbConfig::has('symfony_project-deploy_site-applications')) {
         foreach (nbConfig::get('symfony_project-deploy_site-applications') as $key => $value) {
             $cmd = new nbSymfonyGoOfflineCommand();
             $application = nbConfig::get('symfony_project-deploy_site-applications_' . $key . "_name");
             $environment = nbConfig::get('symfony_project-deploy_site-applications_' . $key . "_env");
             $cmd->run(new nbCommandLineParser(), sprintf('%s %s %s', $symfonyExePath, $application, $environment));
         }
     }
     // Archive site directory
     if (nbConfig::has('archive_inflate-dir')) {
         $cmd = new nbInflateDirCommand();
         $commandLine = '--config-file=' . $arguments['config-file'];
         $cmd->run(new nbCommandLineParser(), $commandLine);
     }
     // Dump database
     if (nbConfig::has('mysql_dump')) {
         $cmd = new nbMysqlDumpCommand();
         $commandLine = '--config-file=' . $arguments['config-file'];
         $cmd->run(new nbCommandLineParser(), $commandLine);
     }
     // Sync project
     if (nbConfig::has('filesystem_dir-transfer')) {
         $cmd = new nbDirTransferCommand();
         $commandLine = '--doit --delete --config-file=' . $arguments['config-file'];
         $cmd->run(new nbCommandLineParser(), $commandLine);
     }
     // Check dirs
     $cmd = new nbSymfonyCheckDirsCommand();
     $commandLine = $symfonyExePath;
     $cmd->run(new nbCommandLineParser(), $commandLine);
     // Check permissions
     $cmd = new nbSymfonyCheckPermissionsCommand();
     $commandLine = $symfonyExePath;
     $cmd->run(new nbCommandLineParser(), $commandLine);
     // Change ownership
     $cmd = new nbSymfonyChangeOwnershipCommand();
     $commandLine = sprintf('%s %s %s', nbConfig::get('symfony_project-deploy_site-dir'), nbConfig::get('symfony_project-deploy_site-user'), nbConfig::get('symfony_project-deploy_site-group'));
     $cmd->run(new nbCommandLineParser(), $commandLine);
     // Restore database
     if (nbConfig::has('mysql_restore')) {
         $cmd = new nbMysqlRestoreCommand();
         $commandLine = '--config-file=' . $arguments['config-file'];
         $cmd->run(new nbCommandLineParser(), $commandLine);
     }
     // Diem setup
     $cmd = new nbSymfonyDiemSetupCommand();
     $commandLine = $symfonyExePath;
     $cmd->run(new nbCommandLineParser(), $commandLine);
     // Clear cache
     $cmd = new nbSymfonyClearCacheCommand();
     $commandLine = $symfonyExePath;
     $cmd->run(new nbCommandLineParser(), $commandLine);
     // Put site online
     if (nbConfig::has('symfony_project-deploy_site-applications')) {
         foreach (nbConfig::get('symfony_project-deploy_site-applications') as $key => $value) {
             $cmd = new nbSymfonyGoOnlineCommand();
             $application = nbConfig::get('symfony_project-deploy_site-applications_' . $key . "_name");
             $environment = nbConfig::get('symfony_project-deploy_site-applications_' . $key . "_env");
             $cmd->run(new nbCommandLineParser(), sprintf('%s %s %s', $symfonyExePath, $application, $environment));
         }
     }
     $this->logLine('Done - Diem Deploy');
     return true;
 }
예제 #6
0
파일: unit.php 프로젝트: nubee/bee
<?php

require_once dirname(__FILE__) . '/../../lib/core/autoload/nbAutoload.php';
$autoload = nbAutoload::getInstance();
$autoload->register();
$autoload->addDirectory('vendor/', '*.php', true);
$autoload->addDirectory('lib/', '*.php', true);
$autoload->addDirectory('test/lib/', '*.php', true);
// Configures bee variables
$configParser = new nbYamlConfigParser();
nbConfig::set('nb_bee_dir', dirname(__FILE__) . '/../..');
nbConfig::set('nb_config_dir', nbConfig::get('nb_bee_dir') . '/config');
nbConfig::set('nb_test_config_dir', dirname(__FILE__) . '/../config/');
$configParser->parseFile(nbConfig::get('nb_bee_dir') . '/.bee/config.yml', '', true);
$configParser->parseFile(nbConfig::get('nb_config_dir') . '/config.yml', '', true);
$configParser->parseFile(nbConfig::get('nb_test_config_dir') . '/config.yml', '', true);
$serviceContainer = new sfServiceContainerBuilder();
$serviceContainer->register('pluginLoader', 'nbPluginLoader')->addArgument(nbConfig::get('nb_plugins_dir'))->addArgument(new sfServiceReference('commandLoader'))->setShared(true);
$serviceContainer->register('commandLoader', 'nbCommandLoaderWithReset')->setShared(true);
$output = new nbConsoleOutput();
$logger = nbLogger::getInstance();
$logger->setOutput($output);
예제 #7
0
파일: bee.php 프로젝트: nubee/bee
<?php

require_once dirname(__FILE__) . '/lib/core/autoload/nbAutoload.php';
$autoload = nbAutoload::getInstance();
$autoload->register();
$autoload->addDirectory(dirname(__FILE__) . '/lib/', '*.php', true);
$autoload->addDirectory(dirname(__FILE__) . '/vendor/', '*.php', true);
$beeDir = nbFileSystem::sanitizeDir(dirname(__FILE__));
nbConfig::set('nb_bee_dir', $beeDir);
if ('WIN' === strtoupper(substr(PHP_OS, 0, 3))) {
    nbConfig::set('nb_user_dir', getenv('APPDATA') . '/.bee');
} else {
    nbConfig::set('nb_user_dir', getenv('HOME') . '/.bee');
}
nbConfig::set('nb_user_config', nbConfig::get('nb_user_dir') . '/config.yml');
$yaml = new nbYamlConfigParser();
$yaml->parseFile(nbConfig::get('nb_bee_dir') . '/config/config.yml', '', true);
if (file_exists(nbConfig::get('nb_user_config'))) {
    $yaml->parseFile(nbConfig::get('nb_user_config'), '', true);
}
if (file_exists('.bee/config.yml')) {
    $yaml->parseFile('.bee/config.yml', '', true);
}
if (file_exists('./.bee/' . nbConfig::get('nb_project_config'))) {
    $projectConfigurationFile = './.bee/' . nbConfig::get('nb_project_config');
} else {
    if (file_exists('./' . nbConfig::get('nb_project_config'))) {
        $projectConfigurationFile = './' . nbConfig::get('nb_project_config');
    } else {
        if (file_exists(nbConfig::get('nb_bee_dir') . '/' . nbConfig::get('nb_project_config'))) {
            $projectConfigurationFile = nbConfig::get('nb_bee_dir') . '/' . nbConfig::get('nb_project_config');
예제 #8
0
 public function addConfigurationFile($filename)
 {
     $yamlParser = new nbYamlConfigParser($this->configuration);
     $yamlParser->parseFile($filename, '', true);
 }
예제 #9
0
파일: nbCommand.php 프로젝트: nubee/bee
 public function loadConfiguration($configDir, $configFilename)
 {
     $configFile = $this->checkConfiguration($configDir, $configFilename);
     $yamlParser = new nbYamlConfigParser();
     $yamlParser->parseFile($configFile, '', true);
 }
예제 #10
0
 /**
  * Parses command line arguments.
  *
  * @param mixed $arguments A string or an array of command line parameters
  */
 public function parse($commandLine = null, $namespace = '', $commandName = '')
 {
     if (null === $commandLine) {
         $this->commandLineTokens = $_SERVER['argv'];
         // we strip command line program
         if (count($this->commandLineTokens) && '-' != $this->commandLineTokens[0][0]) {
             array_shift($this->commandLineTokens);
         }
     } else {
         if (!is_array($commandLine)) {
             $commandLine = trim($commandLine);
             // hack to split arguments with spaces : --test="with some spaces"
             $commandLine = preg_replace('/(\'|")(.+?)\\1/e', "str_replace(' ', '__PLACEHOLDER__', '\\2')", $commandLine);
             $this->commandLineTokens = preg_split('/\\s+/', $commandLine);
             $this->commandLineTokens = str_replace('__PLACEHOLDER__', ' ', $this->commandLineTokens);
         } else {
             $this->commandLineTokens = $commandLine;
         }
     }
     $this->argumentValues = array();
     $this->optionValues = array();
     $this->parsedArgumentValues = array();
     $this->errors = array();
     // get default values for optional arguments
     $this->argumentValues = $this->arguments->getDefaultValues();
     // parse option and arguments from $commandLineArguments
     while (!in_array($argument = array_shift($this->commandLineTokens), array('', null))) {
         if ('--' == $argument) {
             // stop options parsing
             //$this->parsedArgumentValues = array_merge($this->parsedArgumentValues, $this->commandLineArguments);
             $this->commandLineTokens = array();
             break;
         }
         if ('--' == substr($argument, 0, 2)) {
             $this->parseLongOption(substr($argument, 2));
         } else {
             if ('-' == $argument[0]) {
                 $this->parseShortOption(substr($argument, 1));
             } else {
                 $this->parsedArgumentValues[] = $argument;
             }
         }
     }
     // If option config-file is set, get all arguments and parameters from the configuration file
     if (isset($this->parsedLongOptionValues['config-file']) && $this->options->hasOption('config-file')) {
         $option = $this->parsedLongOptionValues['config-file'];
         $configFilename = isset($option[0]) && !is_bool($option[0]) ? $option[0] : null;
         if (!$configFilename) {
             $configFilename = $this->options->getOption('config-file')->getValue();
         }
         if (!$configFilename) {
             throw new InvalidArgumentException('Config filename not defined (and no default provided)');
         }
         $configFile = $this->checkDefaultConfigurationDirs($configFilename);
         if (!$configFile) {
             throw new InvalidArgumentException(sprintf('Config file: %s not found (checked in %s)', $configFilename, implode(', ', $this->getDefaultConfigurationDirs())));
         }
         $configParser = new nbYamlConfigParser();
         $configParser->parseFile($configFile, '', true);
         $ymlPath = $namespace . '_' . $commandName;
         if (nbConfig::has($ymlPath)) {
             $configurationValues = nbConfig::get($ymlPath);
             foreach ($configurationValues as $name => $value) {
                 if (!$this->getArguments()->hasArgument($name) || '' == $value) {
                     continue;
                 }
                 $this->argumentValues[$name] = $value;
             }
             foreach ($configurationValues as $name => $value) {
                 if (!$this->getOptions()->hasOption($name)) {
                     continue;
                 }
                 $option = $this->getOptions()->getOption($name);
                 if ($value !== false && $value !== null) {
                     $this->setOption($option, $value);
                 }
             }
         }
     }
     //set argumentValues parsed from command line
     $position = 0;
     foreach ($this->arguments->getArguments() as $argument) {
         if (array_key_exists($position, $this->parsedArgumentValues)) {
             if ($argument->isArray()) {
                 $this->argumentValues[$argument->getName()] = array_slice($this->parsedArgumentValues, $position);
                 break;
             } else {
                 $this->argumentValues[$argument->getName()] = $this->parsedArgumentValues[$position];
             }
         }
         ++$position;
     }
     // set long option values parsed from command line
     foreach ($this->options->getOptions() as $option) {
         $name = $option->getName();
         if (isset($this->parsedLongOptionValues[$name])) {
             foreach ($this->parsedLongOptionValues[$name] as $key => $value) {
                 $this->setOption($option, $value);
             }
         } else {
             if ($option->hasShortcut() && isset($this->parsedShortOptionValues[$option->getShortcut()])) {
                 foreach ($this->parsedShortOptionValues[$option->getShortcut()] as $key => $value) {
                     $this->setOption($option, $value);
                 }
             }
         }
     }
     // get default values for option with optional parameter not set
     foreach ($this->getOptionValues() as $optionName => $optionValue) {
         $option = $this->options->getOption($optionName);
         if ($option->hasOptionalParameter() && ($this->optionValues[$optionName] == '' || $this->optionValues[$optionName] === true)) {
             $this->setOption($option, $option->getValue());
         }
     }
 }