示例#1
0
 /**
  * {@inheritdoc}
  */
 public function locate($name, $currentPath = null, $first = true)
 {
     if (empty($name)) {
         throw new \InvalidArgumentException('An empty file name is not valid to be located.');
     }
     if ($this->filesystem->isAbsolutePath($name)) {
         if (!$this->filesystem->exists($name)) {
             throw new \InvalidArgumentException(sprintf('The file "%s" does not exist.', $name));
         }
         return $name;
     }
     $directories = $this->paths;
     if (null !== $currentPath) {
         $directories[] = $currentPath;
         $directories = array_values(array_unique($directories));
     }
     $filepaths = [];
     $finder = new Finder();
     $finder->files()->name($name)->ignoreUnreadableDirs()->in($directories);
     /** @var SplFileInfo $file */
     if ($first && null !== ($file = $finder->getIterator()->current())) {
         return $file->getPathname();
     }
     foreach ($finder as $file) {
         $filepaths[] = $file->getPathname();
     }
     if (!$filepaths) {
         throw new \InvalidArgumentException(sprintf('The file "%s" does not exist (in: %s).', $name, implode(', ', $directories)));
     }
     return array_values(array_unique($filepaths));
 }
示例#2
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $fs = new Filesystem();
     $projectArg = $input->getOption('project');
     $drupalArg = $input->getOption('drupal');
     $project = !empty($projectArg) && $fs->isAbsolutePath($projectArg) ? $projectArg : implode('/', [getcwd(), $projectArg]);
     $drupal = $fs->isAbsolutePath($drupalArg) ? $drupalArg : implode('/', [getcwd(), $drupalArg]);
     $mapper = new Mapper($this->normalizePath($project), $this->normalizePath($drupal), $input->getOption('copy'));
     $mapper->clear();
     $mapper->mirror($mapper->getMap($this->getApplication()->getComposer(true)->getInstallationManager(), $this->getApplication()->getComposer(true)->getRepositoryManager()));
 }
 public function __invoke(Project $project)
 {
     $directory = $project->metadata['template.directory'];
     if ($directory === null) {
         $directory = $project->sourceDirectory . '/' . self::DEFAULT_TEMPLATE_DIRECTORY;
     }
     if (!$this->filesystem->isAbsolutePath($directory)) {
         $directory = $project->sourceDirectory . '/' . $directory;
     }
     $this->assertDirectoryExist($directory);
     $project->watchlist->watchDirectory($directory);
     $project->metadata['template.directory'] = $directory;
 }
示例#4
0
 /**
  * @param string                $workingDir
  * @param PackageInterface|null $package
  *
  * @return string
  */
 public function locate($workingDir, PackageInterface $package = null)
 {
     $defaultPath = $workingDir . DIRECTORY_SEPARATOR . self::APP_CONFIG_FILE;
     $defaultPath = $this->locateConfigFileWithDistSupport($defaultPath);
     if (null !== $package) {
         $defaultPath = $this->useConfigPathFromComposer($package, $defaultPath);
     }
     // Make sure to set the full path when it is declared relative
     // This will fix some issues in windows.
     if (!$this->filesystem->isAbsolutePath($defaultPath)) {
         $defaultPath = $workingDir . DIRECTORY_SEPARATOR . $defaultPath;
     }
     return $defaultPath;
 }
示例#5
0
 /**
  * @param string $path
  *
  * @return $this
  */
 public function parse($path)
 {
     if (!$this->fileSystem->isAbsolutePath($path)) {
         $path = getcwd() . DIRECTORY_SEPARATOR . $path;
     }
     if (!is_file($path)) {
         $this->finder->files()->in($path)->ignoreDotFiles(true)->ignoreVCS(true)->ignoreUnreadableDirs(true);
         foreach ($this->finder as $file) {
             $this->parseFile($file);
         }
         return $this;
     }
     $this->parseFile($path);
     return $this;
 }
 /**
  * Execute command
  *
  * @param InputInterface  $input  Input
  * @param OutputInterface $output Output
  *
  * @return int|null|void
  *
  * @throws Exception
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $path = $input->getArgument('path');
     /**
      * We load the options to work with
      */
     $options = $this->getUsableConfig($input);
     /**
      * Building the real directory or file to work in
      */
     $filesystem = new Filesystem();
     if (!$filesystem->isAbsolutePath($path)) {
         $path = getcwd() . DIRECTORY_SEPARATOR . $path;
     }
     if (!is_file($path) && !is_dir($path)) {
         throw new Exception('Directory or file "' . $path . '" does not exist');
     }
     /**
      * Print dry-run message if needed
      */
     $this->printDryRunMessage($input, $output, $path);
     /**
      * Print all configuration block if verbose level allows it
      */
     $this->printConfigUsed($output, $options);
     $fileFinder = new FileFinder();
     $files = $fileFinder->findPHPFilesByPath($path);
     /**
      * Parse and fix all found files
      */
     $this->parseAndFixFiles($input, $output, $files, $options);
 }
 function it_should_locate_config_file_on_empty_composer_configuration(Filesystem $filesystem, PackageInterface $package)
 {
     $package->getExtra()->willReturn(array());
     $filesystem->exists($this->pathArgument('/composer/grumphp.yml'))->willReturn(true);
     $filesystem->isAbsolutePath($this->pathArgument('/composer/grumphp.yml'))->willReturn(true);
     $this->locate('/composer', $package)->shouldMatch($this->pathRegex('/composer/grumphp.yml'));
 }
示例#8
0
 protected function fixRelativePath()
 {
     $fs = new Filesystem();
     if (!$fs->isAbsolutePath($this->scriptDirectory)) {
         $this->scriptDirectory = $this->workingDirectory . DIRECTORY_SEPARATOR . $this->scriptDirectory;
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $database = $input->getArgument('database');
     $namespace = $input->getArgument('namespace');
     $location = $input->getArgument('location');
     $configfile = $input->getArgument('config-file');
     $tablesAll = $input->getOption('tables-all');
     $tablesRegex = $input->getOption('tables-regex');
     $tablesPrefix = $input->getOption('tables-prefix');
     if (!file_exists($configfile)) {
         $output->writeln(sprintf('<error>Incorrect config file path "%s"</error>', $configfile));
         return false;
     }
     $config = (require_once $configfile);
     $db_type = $config['db.type'];
     switch ($db_type) {
         case 'Mysql':
             $dbAdapter = new MakeMysql($config, $database, $namespace);
             break;
         default:
             break;
     }
     $tables = $dbAdapter->getTablesNamesFromDb();
     if (empty($tables)) {
         $output->writeln(sprintf('<error>Please provide at least one table to parse.</error>'));
         return false;
     }
     // Check if a relative path
     $filesystem = new Filesystem();
     if (!$filesystem->isAbsolutePath($location)) {
         $location = getcwd() . DIRECTORY_SEPARATOR . $location;
     }
     $location .= DIRECTORY_SEPARATOR;
     $dbAdapter->addTablePrefixes($tablesPrefix);
     $dbAdapter->setLocation($location);
     foreach (array('Table', 'Entity') as $name) {
         $dir = $location . $name;
         if (!is_dir($dir)) {
             if (!@mkdir($dir, 0755, true)) {
                 $output->writeln(sprintf('<error>Could not create directory zf2 "%s"</error>', $dir));
                 return false;
             }
         }
     }
     $dbAdapter->setTableList($tables);
     $dbAdapter->addTablePrefixes($tablesPrefix);
     foreach ($tables as $table) {
         if ($tablesRegex && !preg_match("/{$tablesRegex}/", $table) > 0) {
             continue;
         }
         $dbAdapter->setTableName($table);
         try {
             $dbAdapter->parseTable();
             $dbAdapter->generate();
         } catch (Exception $e) {
             $output->writeln(sprintf('<error>Warning: Failed to process "%s" : %s ... Skipping</error>', $table, $e->getMessage()));
         }
     }
     $output->writeln(sprintf('<info>Done !!</info>'));
 }
示例#10
0
 /**
  * Clone a repository (clone is a reserved keyword).
  *
  * @param string $path
  * @param string $remote_url
  * @param null $repo
  * @param \Shell\Output\ProcessOutputInterface $output
  * @param bool $background
  * @return GitRepository|Process
  * @throws GitException
  */
 public static function copy($path, $remote_url, &$repo = null, $output = null, $background = false)
 {
     $fs = new Filesystem();
     if (!$fs->isAbsolutePath($path)) {
         throw new InvalidArgumentException('Path must be absolute.');
     }
     $fs->mkdir($path);
     $git = new Git($path);
     $repo = new GitRepository($git, $output);
     $args = [$remote_url, $path];
     if ($background) {
         $onSuccess = function () use(&$repo) {
             $repo->processGitConfig();
             $repo->setUpstream();
             $repo->initialized = true;
         };
         return $git->execNonBlocking('clone', $args, [], [], $onSuccess);
     } else {
         $git->exec('clone', $args, ['--verbose' => true]);
         $repo->processGitConfig();
         $repo->setUpstream();
         $repo->initialized = true;
         return $repo;
     }
 }
 /**
  * Set up our actions and filters
  */
 public function __construct()
 {
     // Create a Filesystem object.
     $this->filesystem = new \Symfony\Component\Filesystem\Filesystem();
     // Discover the correct relative path for the mu-plugins directory.
     $this->mu_plugin_dir = $this->filesystem->makePathRelative(WPMU_PLUGIN_DIR, WP_PLUGIN_DIR);
     if (!$this->filesystem->isAbsolutePath($this->mu_plugin_dir)) {
         $this->mu_plugin_dir = '/' . $this->mu_plugin_dir;
     }
     if ('/' === substr($this->mu_plugin_dir, -1)) {
         $this->mu_plugin_dir = rtrim($this->mu_plugin_dir, '/');
     }
     // Load the plugins
     add_action('muplugins_loaded', array($this, 'muplugins_loaded__requirePlugins'));
     // Adjust the MU plugins list table to show which plugins are MU
     add_action('after_plugin_row_muplugins-subdir-loader.php', array($this, 'after_plugin_row__addRows'));
 }
示例#12
0
 /**
  * @param string $rootConfig
  * @param bool   $environment
  * @param        $debug
  */
 public function __construct($rootConfig, $environment, $debug)
 {
     $fs = new Filesystem();
     if (!$fs->isAbsolutePath($rootConfig) && !is_file($rootConfig = __DIR__ . '/' . $rootConfig)) {
         throw new \InvalidArgumentException(sprintf('The root config "%s" does not exist.', $rootConfig));
     }
     $this->rootConfig = $rootConfig;
     parent::__construct($environment, $debug);
 }
 /**
  * @param array $config
  *
  * @return array
  */
 protected function processPidDirectoryConfiguration(array $config)
 {
     $pidDirectory = $config[$this->pidDirectorySetting];
     $fs = new Filesystem();
     if (!$fs->exists($pidDirectory)) {
         $fs->mkdir($pidDirectory);
     }
     $config[$this->pidDirectorySetting] = $fs->isAbsolutePath($pidDirectory) ? $pidDirectory : realpath($pidDirectory);
     return $config;
 }
 /**
  * Handles the "add-prefix" command.
  *
  * @param Args $args The console arguments.
  * @param IO   $io   The I/O.
  *
  * @return int Returns 0 on success and a positive integer on error.
  */
 public function handle(Args $args, IO $io)
 {
     $prefix = rtrim($args->getArgument('prefix'), '\\');
     $paths = $args->getArgument('path');
     foreach ($paths as $path) {
         if (!$this->filesystem->isAbsolutePath($path)) {
             $path = getcwd() . DIRECTORY_SEPARATOR . $path;
         }
         if (is_dir($path)) {
             $this->finder->files()->name('*.php')->in($path);
             foreach ($this->finder as $file) {
                 $this->scopeFile($file->getPathName(), $prefix, $io);
             }
         }
         if (!is_file($path)) {
             continue;
         }
         $this->scopeFile($path, $prefix, $io);
     }
     return 0;
 }
示例#15
0
 /**
  * Set up the object. Initialize the proper folder for storing the
  * files.
  *
  * @param  string                               $cacheDir
  * @throws \Exception|\InvalidArgumentException
  */
 public function __construct($cacheDir = null)
 {
     $filesystem = new Filesystem();
     if (!$filesystem->isAbsolutePath($cacheDir)) {
         $cacheDir = realpath(__DIR__ . "/" . $cacheDir);
     }
     try {
         parent::__construct($cacheDir, self::DEFAULT_EXTENSION);
     } catch (\InvalidArgumentException $e) {
         throw $e;
     }
 }
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     $this->fs = new Filesystem();
     $this->env = new ArrayCollection();
     $this->output = $output;
     $directory = rtrim(trim($input->getArgument('package')), DIRECTORY_SEPARATOR);
     $this->baseDir = $this->fs->isAbsolutePath($directory) ? $directory : getcwd() . DIRECTORY_SEPARATOR . $directory;
     $repo = $this->getRepository();
     $this->remoteFileUrl = $repo['glibc'];
     $projectName = str_replace(['.tar.gz', '.tar.bz2', '.tar.xz'], [''], basename($this->remoteFileUrl));
     $this->projectName = $projectName;
     $this->projectDir = $this->baseDir . DIRECTORY_SEPARATOR . 'build' . DIRECTORY_SEPARATOR . $this->projectName;
     $this->downloadedFilePath = getcwd() . DIRECTORY_SEPARATOR . '.' . uniqid(time()) . DIRECTORY_SEPARATOR . $this->projectName;
     $this->env->set('_packageDir', $this->baseDir);
     if (!$this->fs->exists($cc = $input->getArgument('toolchain') . '-gcc')) {
         throw new \Exception(sprintf('Unable to find "%s" with toolchain suffix : %s', $cc, $input->getArgument('toolchain')));
     }
     $this->env->set('_toolchainDir', dirname($input->getArgument('toolchain')));
     $this->env->set('_toolchainName', $toolChainName = basename($input->getArgument('toolchain')));
     $this->env->set('PATH', $_SERVER['PATH'] . ':' . $this->env->get('_toolchainDir'));
 }
示例#17
0
 /**
  * @see Command
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     /** @var FormatterHelper $formatter */
     $formatter = $this->getHelperSet()->get('formatter');
     $path = $input->getArgument('path') ?: '';
     $filesystem = new Filesystem();
     if (!$filesystem->isAbsolutePath($path)) {
         $path = getcwd() . DIRECTORY_SEPARATOR . $path;
     }
     $path = rtrim(realpath($path), DIRECTORY_SEPARATOR);
     if (is_file($path)) {
         $files = new \ArrayIterator(array(new \SplFileInfo($path)));
     } else {
         $path .= DIRECTORY_SEPARATOR;
         $files = new Finder();
         $files->files()->name('*.php')->ignoreDotFiles(true)->ignoreVCS(true)->exclude('vendor')->in($path);
     }
     $output->writeln(sprintf("\rChecking %s", $path));
     $total = $files->count();
     $parser = Factory::createParser();
     $index = 1;
     /** @var \SplFileInfo $file */
     foreach ($files as $file) {
         $output->write(sprintf("\rParsing file %s/%s", $index, $total));
         $parser->parse($file);
         ++$index;
     }
     $output->writeln(PHP_EOL);
     $errorCollection = $parser->getErrorCollection();
     $errorCount = count($errorCollection);
     if ($errorCount > 0) {
         $message = $formatter->formatBlock(sprintf('%s %s found on your code.', $errorCount, $errorCount > 1 ? 'errors were' : 'error was'), 'error', true);
         $output->writeln($message);
         $output->writeln('');
         /** @var Error $error */
         foreach ($errorCollection as $error) {
             $output->writeln(sprintf('    %s', $error->getMessage()));
             if ($error->getHelp()) {
                 $output->writeln(sprintf('    > %s', $error->getHelp()));
             }
             $output->writeln(sprintf('        <fg=cyan>%s</fg=cyan> on line <fg=cyan>%s</fg=cyan>', str_replace($path, '', $error->getFilename()), $error->getLine()));
             $output->writeln('');
         }
         return 1;
     }
     $message = $formatter->formatBlock('No error was found when checking your code.', 'info', false);
     $output->writeln($message);
     $output->writeln('');
     $message = $formatter->formatBlock(array('Note:', '> As this tool only do a static analyze of your code, you cannot blindly rely on it.', '> The best way to ensure that your code can run on PHP 7 is still to run a complete test suite on the targeted version of PHP.'), 'comment', false);
     $output->writeln($message);
     $output->writeln(PHP_EOL);
     return 0;
 }
示例#18
0
 public function __construct($config)
 {
     parent::__construct('test', true);
     $fs = new Filesystem();
     if (!$fs->isAbsolutePath($config)) {
         $config = __DIR__ . '/config/' . $config;
     }
     if (!file_exists($config)) {
         throw new \RuntimeException(sprintf('The config file "%s" does not exist.', $config));
     }
     $this->config = $config;
 }
示例#19
0
 public function __construct($testCase, $rootConfig, $environment, $debug)
 {
     if (!is_dir(__DIR__ . '/' . $testCase)) {
         throw new \InvalidArgumentException(sprintf('The test case "%s" does not exist.', $testCase));
     }
     $this->testCase = $testCase;
     $fs = new Filesystem();
     if (!$fs->isAbsolutePath($rootConfig) && !file_exists($rootConfig = __DIR__ . '/' . $testCase . '/' . $rootConfig)) {
         throw new \InvalidArgumentException(sprintf('The root config "%s" does not exist.', $rootConfig));
     }
     $this->rootConfig = $rootConfig;
     parent::__construct($environment, $debug);
 }
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     $this->loadLibrary();
     $this->input = $input;
     $this->output = $output;
     $this->fs = new Filesystem();
     $this->env = $this->getEnv();
     $directory = rtrim(trim($input->getArgument('package')), DIRECTORY_SEPARATOR);
     $this->baseDir = $this->fs->isAbsolutePath($directory) ? $directory : getcwd() . DIRECTORY_SEPARATOR . $directory;
     $requireDirs = [$this->baseDir . '/build', $this->baseDir . '/source', $this->baseDir . '/rootfs', $this->baseDir . '/rootfs/include', $this->baseDir . '/rootfs/lib'];
     $this->findDirs = [$this->baseDir . '/rootfs/lib', $this->baseDir . '/rootfs/include', $this->baseDir . '/rootfs/usr/lib', $this->baseDir . '/rootfs/usr/include', $this->baseDir . '/rootfs/php/bin', $this->baseDir . '/rootfs/msmtp/bin', $this->baseDir . '/rootfs/lighttpd/sbin', $this->baseDir . '/rootfs/nginx/sbin'];
     $this->fs->mkdir($requireDirs);
     $this->fs->mkdir($this->findDirs);
     $yaml = new Parser();
     try {
         $env = $yaml->parse(file_get_contents($this->baseDir . '/environment.yml'));
     } catch (ParseException $e) {
         throw new \Exception(sprintf('Unable to parse the YAML string: %s', $e->getMessage()));
     }
     $this->env = new ArrayCollection($env);
     $this->env->set('ROOTFS', $this->baseDir . '/rootfs');
 }
 public function __construct($config)
 {
     $this->rootDir = __DIR__ . DIRECTORY_SEPARATOR;
     parent::__construct('test', true);
     $fs = new Filesystem();
     if (!$fs->isAbsolutePath($config)) {
         $config = $this->getRootDir() . '/TestBundle/Resources/config/' . $config;
     }
     if (!file_exists($config)) {
         throw new \RuntimeException(sprintf('The config file "%s" does not exist.', $config));
     }
     $this->config = $config;
 }
 public function __construct($config, $debug)
 {
     parent::__construct('config', $debug);
     $fs = new Filesystem();
     if (!$fs->isAbsolutePath($config)) {
         $config = __DIR__ . '/config/' . $config . ".yml";
     }
     if (!file_exists($config)) {
         throw new \RuntimeException(sprintf('The config file "%s" does not exist.', $config));
     }
     $this->config = $config;
     file_put_contents('/tmp/log.f', $this->getCacheDir() . PHP_EOL, FILE_APPEND);
 }
示例#23
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // App
     $helper = $this->getHelper('question');
     $app_name = $input->getArgument('app');
     if (empty($app_name)) {
         $question = new ChoiceQuestion('For which app? ', array_keys($this->getApplication()->getTerra()->getConfig()->get('apps')), 0);
         $app_name = $helper->ask($input, $output, $question);
     }
     $app = $this->getApplication()->getTerra()->getConfig()->get('apps', $app_name);
     // Environment Name
     $environment_name = $input->getArgument('name');
     if (empty($environment_name)) {
         $question = new Question('Environment Name: ', '');
         $environment_name = $helper->ask($input, $output, $question);
     }
     // Path
     $path = $input->getArgument('path');
     if (empty($path)) {
         $default_path = realpath('.') . '/' . $app_name . '/' . $environment_name;
         $question = new Question("Path: ({$default_path})", '');
         $path = $helper->ask($input, $output, $question);
         if (empty($path)) {
             $path = $default_path;
         }
     }
     // Check for path
     $fs = new Filesystem();
     if (!$fs->isAbsolutePath($path)) {
         $path = getcwd() . '/' . $path;
     }
     // Environment object
     $environment = array('name' => $environment_name, 'path' => $path, 'document_root' => '', 'url' => '', 'version' => '');
     // Prepare the environment factory.
     // Clone the apps source code to the desired path.
     $environmentFactory = new EnvironmentFactory($environment, $this->getApplication()->getTerra()->getConfig()->get('apps', $app_name));
     // Save environment to config.
     if ($environmentFactory->init($path)) {
         // Load config from file.
         $environmentFactory->getConfig();
         $environment['document_root'] = $environmentFactory->config['document_root'];
         // Save current branch
         $environment['version'] = $environmentFactory->getRepo()->getCurrentBranch();
         // Save to registry.
         $this->getApplication()->getTerra()->getConfig()->add('apps', array($app_name, 'environments', $environment_name), $environment);
         $this->getApplication()->getTerra()->getConfig()->save();
         $output->writeln('<info>Environment saved to registry.</info>');
     } else {
         $output->writeln('<error>Unable to clone repository. Check app settings and try again.</error>');
     }
 }
示例#24
0
文件: Runner.php 项目: slince/runner
 /**
  * 转换files到multipart格式
  * @param $files
  * @return array
  */
 protected function convertFilesToMultipart($files)
 {
     $posts = [];
     foreach ($files as $name => $file) {
         if (!$this->filesystem->isAbsolutePath($file)) {
             $file = getcwd() . DIRECTORY_SEPARATOR . $file;
         }
         if (!file_exists($file)) {
             throw new InvalidArgumentException(sprintf("File [%s] does not exists", $file));
         }
         $posts[] = ['name' => $name, 'contents' => fopen($file, 'r')];
     }
     return $posts;
 }
示例#25
0
 public function __construct($config, $testEnv = 'default')
 {
     //separate generated container
     parent::__construct($testEnv . '_' . substr(md5($config), 0, 3), true);
     $fs = new Filesystem();
     if (!$fs->isAbsolutePath($config)) {
         $config = __DIR__ . '/config/' . $config;
     }
     if (!file_exists($config)) {
         throw new \RuntimeException(sprintf('The config file "%s" does not exist.', $config));
     }
     $this->config = $config;
     $this->testEnv = $testEnv;
 }
示例#26
0
 /**
  * @param ContainerBuilder $container
  * @param string           $bundleName
  * @param array            $cacheConfig
  * @param string           $baseDir
  *
  * @return Reference
  */
 protected function createCache(ContainerBuilder $container, $bundleName, array $cacheConfig, $baseDir)
 {
     $cacheServiceId = $cacheConfig['id'];
     if (null !== $cacheServiceId) {
         return new Reference($cacheServiceId);
     }
     $cacheDir = $this->parseDirectory($container, $cacheConfig['directory']);
     if (!$this->filesystem->isAbsolutePath($cacheDir)) {
         $cacheDir = $baseDir . DIRECTORY_SEPARATOR . $cacheDir;
     }
     $def = new DefinitionDecorator('sp_bower.filesystem_cache');
     $def->replaceArgument(0, $cacheDir);
     $container->setDefinition($defId = 'sp_bower.filesystem_cache.' . $bundleName, $def);
     return new Reference($defId);
 }
示例#27
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // App
     $helper = $this->getHelper('question');
     $app_name = $input->getArgument('app');
     if (empty($app_name)) {
         $question = new ChoiceQuestion('For which app? ', array_keys($this->director->config['apps']), 0);
         $app_name = $helper->ask($input, $output, $question);
     }
     $app = $this->director->getApp($app_name);
     // Environment Name
     $environment_name = $input->getArgument('name');
     if (empty($environment_name)) {
         $question = new Question('Environment Name: ', '');
         $environment_name = $helper->ask($input, $output, $question);
     }
     // Path
     $path = $input->getArgument('path');
     if (empty($path)) {
         $default_path = realpath('.') . '/' . $app_name . '/' . $environment_name;
         $question = new Question("Path: ({$default_path})", '');
         $path = $helper->ask($input, $output, $question);
         if (empty($path)) {
             $path = $default_path;
         }
     }
     // Check for path
     $fs = new Filesystem();
     if (!$fs->isAbsolutePath($path)) {
         $path = getcwd() . '/' . $path;
     }
     $environment = new Environment($environment_name, $path, $app->getSourceUrl());
     $this->director->config['apps'][$app_name]['environments'][$environment_name] = (array) $environment;
     // Save config
     $this->director->saveData();
     $output->writeln("OK Saving environment {$environment_name}");
     // Clone the apps source code to the desired path.
     $environmentFactory = new EnvironmentFactory($environment, $app_name, $this->director);
     $environmentFactory->init($path);
     // Assign Servers!
     // for each environment->config->services,
     //    lookup all servers that have the required service available.
     //    ask user which server to use for each service.
     //    save the environment's service stack.
     // Save data
     // Prompt user to run director direct to deploy the services.
 }
示例#28
0
文件: Cache.php 项目: LeonB/site
 /**
  * Set up the object. Initialize the proper folder for storing the
  * files.
  *
  * @param  string                               $cacheDir
  * @throws \Exception|\InvalidArgumentException
  */
 public function __construct($cacheDir = null)
 {
     if (!isset($cacheDir)) {
         $cacheDir = BOLT_CACHE_DIR;
     } else {
         // We don't have $app here, so we use the filesystem component
         // directly here.
         $filesystem = new Filesystem();
         if (!$filesystem->isAbsolutePath($cacheDir)) {
             $cacheDir = realpath(__DIR__ . "/" . $cacheDir);
         }
     }
     try {
         parent::__construct($cacheDir, self::DEFAULT_EXTENSION);
     } catch (\InvalidArgumentException $e) {
         throw $e;
     }
 }
示例#29
0
 /**
  * @return \Symfony\Component\DependencyInjection\ContainerBuilder
  */
 protected function getContainer()
 {
     if ($this->container) {
         return $this->container;
     }
     // Load cli options:
     $input = new ArgvInput();
     $input->bind($this->getDefaultInputDefinition());
     $configPath = $input->getOption('config');
     // Make sure to set the full path when it is declared relative
     // This will fix some issues in windows.
     $filesystem = new Filesystem();
     if (!$filesystem->isAbsolutePath($configPath)) {
         $configPath = getcwd() . DIRECTORY_SEPARATOR . $configPath;
     }
     // Build the service container:
     $this->container = ContainerFactory::buildFromConfiguration($configPath);
     return $this->container;
 }
示例#30
0
文件: Command.php 项目: bopo/website
 protected function initialize(InputInterface $input, OutputInterface $output)
 {
     $this->input = $input;
     $this->output = $output;
     $config = $input->getArgument('config');
     $filesystem = new Filesystem();
     if (!$filesystem->isAbsolutePath($config)) {
         $config = getcwd() . '/' . $config;
     }
     if (!file_exists($config)) {
         throw new \InvalidArgumentException(sprintf('Configuration file "%s" does not exist.', $config));
     }
     $this->sami = (require $config);
     if ($input->getOption('version')) {
         $this->sami['version'] = $input->getOption('version');
     }
     if (!$this->sami instanceof Sami) {
         throw new \RuntimeException(sprintf('Configuration file "%s" must return a Sami instance.', $config));
     }
 }