protected function processOptions() { if (!isset($this->options['environment'])) { $this->options['environment'] = getenv('SYMFONY_ENV') ?: 'prod'; } if (null !== $this->input) { $this->options['environment'] = $this->input->getParameterOption(['--env', '-e'], $this->options['environment']); } if (!isset($this->options['localhost_only']) || $this->options['environment'] == 'prod') { $this->options['localhost_only'] = false; } if (getenv('SYMFONY_DEBUG') === '0' || null !== $this->input && $this->input->hasParameterOption(['--no-debug', ''])) { $this->options['debug'] = false; } if (!isset($this->options['debug'])) { $this->options['debug'] = $this->options['environment'] == 'dev'; } $this->options['umask_fix'] = isset($this->options['umask_fix']) ? (bool) $this->options['umask_fix'] : false; if (empty($this->options['apc_cache_id']) || $this->options['environment'] != 'prod') { $this->options['apc_cache_id'] = false; } if (!isset($this->options['http_cache']) || $this->options['environment'] != 'prod') { $this->options['http_cache'] = false; } }
/** * Configures container based on providen config file and profile. * * @param ContainerInterface $container * @param InputInterface $input */ protected function loadConfiguration(ContainerInterface $container, InputInterface $input) { $file = $input->getParameterOption(array('--config', '-c')); $profile = $input->getParameterOption(array('--profile', '-p')) ?: 'default'; $cwd = getcwd(); // if config file is not provided if (!$file) { // then use behat.yml if (is_file($cwd . DIRECTORY_SEPARATOR . 'behat.yml')) { $file = $cwd . DIRECTORY_SEPARATOR . 'behat.yml'; // or behat.yml.dist } elseif (is_file($cwd . DIRECTORY_SEPARATOR . 'behat.yml.dist')) { $file = $cwd . DIRECTORY_SEPARATOR . 'behat.yml.dist'; // or config/behat.yml } elseif (is_file($cwd . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'behat.yml')) { $file = $cwd . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'behat.yml'; } } // read configuration $loader = new Loader($file); $configs = $loader->loadConfiguration($profile); // locate base path $basePath = $cwd; if (file_exists($file)) { $basePath = realpath(dirname($file)); } // load core extension into temp container $extension = new BehatExtension($basePath); $extension->load($configs, $container); $container->addObjectResource($extension); }
/** * {@inheritdoc} */ public function doRun(InputInterface $input, OutputInterface $output) { $drupal_root = $input->getParameterOption(['--drupal', '-d'], false); $env = $input->getParameterOption(array('--env', '-e'), getenv('DRUPAL_ENV') ?: 'prod'); $debug = getenv('DRUPAL_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod'; if ($this->isBooted()) { if (true === $input->hasParameterOption(array('--shell', '-s'))) { $this->runShell($input); return 0; } } if (!$this->commandsRegistered) { $this->commandsRegistered = $this->registerCommands(); } if ($input) { $commandName = $this->getCommandName($input); } if ($commandName && $this->has($commandName)) { $this->searchSettingsFile = false; } if ($this->isRunningOnDrupalInstance($drupal_root)) { $this->setup($env, $debug); $this->bootstrap(); } parent::doRun($input, $output); if ($this->isBooted()) { $kernelHelper = $this->getHelperSet()->get('kernel'); if ($kernelHelper) { $kernelHelper->terminate(); } } }
public function doRun(InputInterface $input, OutputInterface $output) { // introspect input without definition $config = $input->getParameterOption(array('--config', '-c')); $verbose = $input->getParameterOption(array('--verbose', '-v')); $bootstrap = $input->getParameterOption(array('--bootstrap', '-b')); $profile = $input->getParameterOption(array('--profile', '-p')); if (true == $verbose) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); } $container = $this->getContainer(); // event dispatcher $container['dispatcher'] = new EventDispatcher(); $container['input'] = $input; $container['output'] = $output; // config /** * Process options */ $this->register(new ConfigServiceProvider(), array('config.path' => $config)); if ($profile) { $container['config.profile'] = $profile; } $overrides = array(); if ($input->hasParameterOption(array('--verbose', '-v'))) { $overrides['verbose'] = true; } if ($bootstrap) { $overrides['bootstrap'] = $bootstrap; } $container['config.overrides'] = $overrides; /** * Should overwrite the profile with command line options here */ $profile = $container['profile']; if ($profile->bootstrap) { $inc = function () use($profile) { require $profile->bootstrap; }; $inc(); } // extensions foreach ($profile->extensions as $name => $options) { $class = "\\DSpec\\Provider\\" . ucfirst($name) . "ServiceProvider"; if (!class_exists($class)) { $class = $name; if (!class_exists($class)) { throw new \InvalidArgumentException("class:{$class} not found"); } } $this->register(new $class(), (array) $options); } $container['dspec.command'] = new DSpecCommand($container); $this->bootProviders(); $this->add($container['dspec.command']); return parent::doRun($input, $output); }
/** * {@inheritDoc} */ public function doRun(InputInterface $input = null, OutputInterface $output = null) { $env = $input->getParameterOption('--env', null); if (null === $env) { $env = $input->getParameterOption('-e', 'dev'); } $this->app = new SilexApplication($env); $this->app->boot(); return parent::doRun($input, $output); }
/** * @param InputInterface $input * * @return array * @throws \Exception */ public static function findFiles(InputInterface $input) { if ($input->hasParameterOption('--config-file')) { $file = $input->getParameterOption('--config-file'); if (file_exists($file)) { return [$file]; } throw new ConfigurationFileNotFoundException(sprintf("Couldn't find the configuration file: %s", $file)); } $format = $input->hasParameterOption('--config-format') ? $input->getParameterOption('--config-format') : static::$DEFAULT_TYPE; return [sprintf("%s.%s", static::$NAME, $format), sprintf("%s.%s.dist", static::$NAME, $format)]; }
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { MinkContext::$allowed = array('servers' => $this->getContainer()->getParameter('behat.servers'), 'locales' => $this->getContainer()->getParameter('behat.locales')); MinkContext::$options = $this->getContainer()->getParameter('behat.options'); foreach (self::$options as $option) { if ($input->hasParameterOption('--' . $option)) { MinkContext::$options[$option] = $input->getParameterOption('--' . $option); } } $args = array(); if ($input->hasParameterOption('--suite')) { $args['--suite'] = $input->getParameterOption('--suite'); } $this->runBehatCommand($args); }
public function doRun(InputInterface $input, OutputInterface $output) { if ($input->hasParameterOption('--base-dir')) { $baseDir = realpath($input->getParameterOption('--base-dir')); if (!is_dir($baseDir)) { throw new \InvalidArgumentException(sprintf('Base directory does not exist or it is not a readable directory: "%s".', $input->getParameterOption('--base-dir'))); } // We have to load extension after the override of `base_dir` // configuration; because extension can rely on configuration inside the // `config.yml` file. $this->container['base_dir'] = $baseDir; } $this->loadExtensions(); return parent::doRun($input, $output); }
private function getNewWorkingDir(InputInterface $input) { $workingDir = $input->getParameterOption(array('--working-dir', '-w')); if (false !== $workingDir && !is_dir($workingDir)) { throw new \RuntimeException('Invalid working directory specified, ' . $workingDir . ' does not exist.'); } return $workingDir; }
private function getWikiDir(InputInterface $input) { $wikiDir = $input->getParameterOption(array('--wiki-dir', '-d')); if (false !== $wikiDir && !is_dir($wikiDir)) { throw new \RuntimeException('Invalid wiki directory specified.'); } return $wikiDir; }
private function getValue(InputInterface $input, $varName) { $envVarName = sprintf('INSIGHT_%s', str_replace(' ', '_', strtoupper($varName))); if ($value = getenv($envVarName)) { return $value; } $cliVarName = sprintf('--%s', str_replace(' ', '-', strtolower($varName))); return $input->getParameterOption($cliVarName); }
/** * @return KernelInterface */ private function getKernel(InputInterface $input) { $env = $input->getParameterOption(['--env', '-e'], $this->baseKernel->getEnvironment()); $debug = !$input->hasParameterOption(['--no-debug', '']); if ($env === $this->baseKernel->getEnvironment() && $debug === $this->baseKernel->isDebug()) { return $this->baseKernel; } $kernelClass = new ReflectionClass($this->baseKernel); return $kernelClass->newInstance([$env, $debug]); }
private function buildContainer(InputInterface $input, OutputInterface $output) { $factory = new ContainerFactory(); $resolver = new ExtensionNameResolver(); foreach ($input->getParameterOption(array('extensions', 'e'), array()) as $extension) { $factory->addExtension($resolver->resolve($extension)); } $factory->addExtension(new CliExtension($input, $output)); return $factory->createContainer(); }
public function doRun(InputInterface $input, OutputInterface $output) { $configFile = $input->getParameterOption(array('--config', '-c')); if (!is_readable($configFile)) { $configFile = 'config.yml'; } $container = $this->createContainer($configFile); $filterCommand = new FilterCommand($container); $this->add($filterCommand); return parent::doRun($input, $output); }
/** * {@inheritDoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $application = $this->getApplication(); DoctrineCommandHelper::setApplicationPHPCRSession($application, $input->getOption('session')); $helperSet = $application->getHelperSet(); $helperSet->set($this->getContainer()->get('doctrine_phpcr.console_dumper')); if (!$input->getParameterOption('max_line_length') && $this->getContainer()->hasParameter('doctrine_phpcr.dump_max_line_length')) { $input->setOption('max_line_length', $this->getContainer()->getParameter('doctrine_phpcr.dump_max_line_length')); } return parent::execute($input, $output); }
/** * @param InputInterface $input * @return string * @throws \RuntimeException */ protected function getWorkingDir(InputInterface $input) { $workingDir = $input->getParameterOption(array('--working-dir', '-d')); if (false !== $workingDir && !is_dir($workingDir)) { throw new \RuntimeException('Invalid working directory specified.'); } if (!$workingDir) { $workingDir = getcwd(); } return $workingDir; }
/** * @param InputInterface $input * * @return array * * @throws \RuntimeException */ protected function parseConfigurationFile(InputInterface $input) { $paths = array('stamp.yml', 'stamp.yml.dist'); if ($customPath = $input->getParameterOption(array('-c', '--config'))) { if (!file_exists($customPath)) { throw new RuntimeException('Custom configuration file not found at ' . $customPath); } $paths = array($customPath); } foreach ($paths as $path) { if ($path && file_exists($path) && ($parsedConfig = Yaml::parse(file_get_contents($path)))) { return $parsedConfig; } } return null; }
/** * Create a kernel. * * @param InputInterface $input Input * * @return \Symfony\Component\HttpKernel\Kernel */ public static function create(InputInterface $input) { $env = $input->getParameterOption(array('--env', '-e'), getenv('SCULPIN_DEBUG') ?: 'dev'); $debug = $env !== 'prod' && getenv('SCULPIN_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')); // do something here to locate and try to create // a custom kernel. // We are relying on our calling script to chdir as appropriate with any // --project-directory that was specified. $projectDir = getcwd(); if (file_exists($customKernel = $projectDir . '/app/SculpinKernel.php')) { require $customKernel; return new \SculpinKernel($env, $debug, $projectDir); } // Fallback to using the default kernel in case // user does not define their own kernel somehow. return new DefaultKernel($env, $debug, $projectDir); }
/** * @param InputInterface $input * @throws \RuntimeException */ private function getNewWorkingDir(InputInterface $input) { if ($input->getOption('global')) { return Env::get("homedir") . "/.altax"; } $workingDir = $input->getParameterOption(array('--working-dir', '-d')); if (false !== $workingDir && !is_dir($workingDir)) { throw new \RuntimeException('Invalid working directory specified.'); } if (false === $workingDir) { $workingDir = getcwd() . "/.altax"; } if (!is_dir($workingDir)) { throw new \RuntimeException('Invalid working directory.'); } return $workingDir; }
/** * @param InputInterface $input * @param OutputInterface $output * @return int */ public function doRun(InputInterface $input, OutputInterface $output) { if (true === $input->hasParameterOption(array('--configFile', '-c'))) { $configFile = $input->getParameterOption(array('--configFile', '-c')); //if(fs->exist(path/to/file)) $configValues = Yaml::parse(file_get_contents($configFile)); $processor = new Processor(); $configuration = new Configuration(); try { $processedConfiguration = $processor->processConfiguration($configuration, $configValues); // configuration validated } catch (Exception $e) { // validation error echo $e->getMessage() . PHP_EOL; } } return parent::doRun($input, $output); }
/** * @inheritdoc */ public function doRun(InputInterface $input, OutputInterface $output) { if (!$this->factory) { $config_file = $input->getParameterOption(['--config', '-c'], self::DEFAULT_CONFIG_FILE); switch (pathinfo($config_file, PATHINFO_EXTENSION)) { case 'php': $provider = new PHPConfigProvider($config_file); break; case 'yaml': case 'yml': $provider = new YAMLConfigProvider($config_file); break; default: $provider = new JSONConfigProvider($config_file); } $this->factory = new ConfigurableFactory($provider); } return parent::doRun($input, $output); }
protected function execute(InputInterface $input, OutputInterface $output) { if (!$this->isCommandSuccess('grunt --version') || !$this->isCommandSuccess('bower --version')) { $output->writeln('<error>For full functionality of this bundle, you should install grunt-cli, bower globally using npm.</error>'); return self::RETURN_CODE_NO_TOOLS; } if ($input->getParameterOption('--with-assets-dependencies')) { $output->write("Installing assets dependencies ..."); $this->executeProcess('bower install', $output); $output->write("Updating assets dependencies ..."); $this->executeProcess('bower update', $output); } $assetsDir = $this->bundleDir . 'Resources/assets'; $publicDir = $this->bundleDir . 'Resources/public'; $gruntFile = $this->bundleDir . 'Gruntfile.js'; $output->write("Building application ..."); $this->executeProcess([sprintf('%s --assets-dir=%s --public-dir=%s --base=%s --gruntfile=%s', 'grunt', $assetsDir, $publicDir, $this->bundleDir, $gruntFile)], $output); return 0; }
/** * @inheritdoc */ public function doRun(InputInterface $input, OutputInterface $output) { // Define the running environment and initialize the container. $env = $input->getParameterOption(array('-e', '--env'), 'dev'); $this->container->getApplicationBag()->setEnv($env); $this->container->getConsoleBag()->set('input', $input)->set('output', $output); $this->container->initialize(); // Add commands. foreach ($this->container->getCommandBag()->values() as $command) { $this->add($command); } // Dispatch pre run event. $dispatcher = $this->container->getServiceBag()->getDispatcher(); $dispatcher->dispatch(Events::PRE_RUN, new PreRunEvent($this->container)); // Run application. $result = parent::doRun($input, $output); // Dispatch post run event. $dispatcher->dispatch(Events::POST_RUN, new PostRunEvent($this->container, $result)); return $result; }
protected function configureIO(InputInterface $input, OutputInterface $output) { if ($input->hasParameterOption(['--config', '-c'])) { $configPath = realpath($input->getParameterOption(['--config', '-c'])); if (!$configPath) { throw new \InvalidArgumentException(sprintf('Config file does not exists! %s', $configPath)); } $cwd = getcwd(); chdir(dirname($configPath)); $yaml = new Parser(); $config = file_get_contents($configPath); $config = $yaml->parse($config); array_walk_recursive($config, function (&$item, $key) { $item = $this->processPlaceHolder($item); }); $params = isset($config['parameters']) ? $config['parameters'] : []; $pipeline = isset($config['pipeline']) ? $config['pipeline'] : []; $this->setConfig($params); $this->setPipeLine($pipeline); chdir($cwd); } return parent::configureIO($input, $output); }
/** * Runs the current application. * * @param InputInterface $input An Input instance * @param OutputInterface $output An Output instance * * @return integer 0 if everything went fine, or an error code */ public function doRun(InputInterface $input, OutputInterface $output) { //potentially override the environment if ($input->hasParameterOption(array('--env', '-e'))) { $this->neptune->setEnv($input->getParameterOption(array('--env', '-e'))); } if ($output->isVeryVerbose() && $this->neptune->getEnv()) { $output->writeln(sprintf('Using environment <info>%s</info>', $this->neptune->getEnv())); } //load the app configuration now to give a useful message if //it fails try { $this->neptune['config']; } catch (ConfigFileException $e) { $this->renderException($e, $output); $output->writeln('Run `<info>./vendor/bin/neptune-install .</info>` to set up a default configuration.'); return; } if (!$this->commands_registered) { $this->registerCommands($output); } return parent::doRun($input, $output); }
/** * Configures the input and output instances based on the user arguments and options. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance */ protected function configureIO(InputInterface $input, OutputInterface $output) { if (true === $input->hasParameterOption(array('--ansi'))) { $output->setDecorated(true); } elseif (true === $input->hasParameterOption(array('--no-ansi'))) { $output->setDecorated(false); } if (true === $input->hasParameterOption(array('--no-interaction', '-n'))) { $input->setInteractive(false); } elseif (function_exists('posix_isatty') && $this->getHelperSet()->has('dialog')) { $inputStream = $this->getHelperSet()->get('dialog')->getInputStream(); if (!@posix_isatty($inputStream)) { $input->setInteractive(false); } } if (true === $input->hasParameterOption(array('--quiet', '-q'))) { $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); } else { if ($input->hasParameterOption('-vvv') || $input->hasParameterOption('--verbose=3') || $input->getParameterOption('--verbose') === 3) { $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); } elseif ($input->hasParameterOption('-vv') || $input->hasParameterOption('--verbose=2') || $input->getParameterOption('--verbose') === 2) { $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); } elseif ($input->hasParameterOption('-v') || $input->hasParameterOption('--verbose=1') || $input->hasParameterOption('--verbose') || $input->getParameterOption('--verbose')) { $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); } } }
/** * @param InputInterface $input * * @return array * * @throws \RuntimeException */ protected function parseConfigurationFile(InputInterface $input) { $paths = array('phpspec.yml', 'phpspec.yml.dist'); if ($customPath = $input->getParameterOption(array('-c', '--config'))) { if (!file_exists($customPath)) { throw new RuntimeException('Custom configuration file not found at ' . $customPath); } $paths = array($customPath); } $config = array(); foreach ($paths as $path) { if ($path && file_exists($path) && ($parsedConfig = Yaml::parse($path))) { $config = $parsedConfig; break; } } if ($homeFolder = getenv('HOME')) { $localPath = $homeFolder . '/.phpspec.yml'; if (file_exists($localPath) && ($parsedConfig = Yaml::parse($localPath))) { $config = array_replace_recursive($parsedConfig, $config); } } return $config; }
/** * {@inheritdoc} */ public function doRun(InputInterface $input, OutputInterface $output) { $output = new DrupalStyle($input, $output); $root = null; $commandName = null; $recursive = false; $config = $this->getConfig(); $target = $input->getParameterOption(['--target'], null); if ($input && ($commandName = $this->getCommandName($input))) { $this->commandName = $commandName; } $targetConfig = []; if ($target && $config->loadTarget($target)) { $targetConfig = $config->getTarget($target); $root = $targetConfig['root']; } if ($targetConfig && $targetConfig['remote']) { $remoteResult = $this->getRemoteHelper()->executeCommand($commandName, $target, $targetConfig, $input->__toString(), $config->getUserHomeDir()); $output->writeln($remoteResult); return 0; } if (!$target && $input->hasParameterOption(['--root'])) { $root = $input->getParameterOption(['--root']); $root = strpos($root, '/') === 0 ? $root : sprintf('%s/%s', getcwd(), $root); } $uri = $input->getParameterOption(['--uri', '-l']); /*Checking if the URI has http of not in begenning*/ if ($uri && !preg_match('/^(http|https):\\/\\//', $uri)) { $uri = sprintf('http://%s', $uri); } $env = $input->getParameterOption(['--env', '-e'], getenv('DRUPAL_ENV') ?: 'prod'); if ($env) { $this->env = $env; } $debug = getenv('DRUPAL_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod'; if ($debug) { Debug::enable(); } $drupal = $this->getDrupalHelper(); $this->getCommandDiscoveryHelper()->setApplicationRoot($this->getDirectoryRoot()); if (!$root) { $root = getcwd(); $recursive = true; } /* validate drupal site */ $this->container->get('site')->isValidRoot($root, $recursive); if (!$drupal->isValidRoot($root, $recursive)) { $commands = $this->getCommandDiscoveryHelper()->getConsoleCommands(); if ($commandName == 'list') { $this->errorMessage = $this->trans('application.site.errors.directory'); } $this->registerCommands($commands); } else { $this->getKernelHelper()->setRequestUri($uri); $this->getKernelHelper()->setDebug($debug); $this->getKernelHelper()->setEnvironment($this->env); $this->prepare($drupal, $commandName); } if ($commandName && $this->has($commandName)) { $command = $this->get($commandName); $parameterOptions = $this->getDefinition()->getOptions(); foreach ($parameterOptions as $optionName => $parameterOption) { $parameterOption = [sprintf('--%s', $parameterOption->getName()), sprintf('-%s', $parameterOption->getShortcut())]; if (true === $input->hasParameterOption($parameterOption)) { $option = $this->getDefinition()->getOption($optionName); $command->getDefinition()->addOption($option); } } } $skipCheck = ['check', 'init']; if (!in_array($commandName, $skipCheck) && $config->get('application.checked') != 'true') { $requirementChecker = $this->getContainerHelper()->get('requirement_checker'); $phpCheckFile = $this->getConfig()->getUserHomeDir() . '/.console/phpcheck.yml'; if (!file_exists($phpCheckFile)) { $phpCheckFile = $this->getDirectoryRoot() . 'config/dist/phpcheck.yml'; } $requirementChecker->validate($phpCheckFile); if (!$requirementChecker->isValid()) { $command = $this->find('check'); return $this->doRunCommand($command, $input, $output); } if ($requirementChecker->isOverwritten()) { $this->getChain()->addCommand('check'); } else { $this->getChain()->addCommand('settings:set', ['setting-name' => 'checked', 'setting-value' => 'true', '--quiet']); } } return parent::doRun($input, $output); }
public function doRun(InputInterface $input, OutputInterface $output) { $this->siteAccessName = $input->getParameterOption('--siteaccess', null); return parent::doRun($input, $output); }
/** * @param InputInterface $input * * @return stdClass { * * @var string $packageHandle The package handle * @var string $packageDirectory The package directory * @var string|null $packageVersion The package version (if retrieved) * @var string|null $packageFormat The package format (if retrieved) - One of the PackPackageCommand::PACKAGEFORMAT_ constants * @var string $shortTags One of the PackPackageCommand::SHORTTAGS_ constants * @var string $compileIcons One of the PackPackageCommand::YNA_ constants * @var string $compileTranslations One of the PackPackageCommand::YNA_ constants * @var array $keep List of PackPackageCommand::KEEP_ constants * @var bool $updateSourceDirectory * @var string|null $zipFilename * } */ protected static function parseInput(InputInterface $input) { $result = new stdClass(); $vsh = Core::make('helper/validation/strings'); /* @var \Concrete\Core\Utility\Service\Validation\Strings $vsh */ $fh = Core::make('helper/file'); /* @var \Concrete\Core\File\Service\File $fh */ $result->packageHandle = null; $result->packageDirectory = null; $result->packageVersion = null; $result->packageFormat = null; $p = $input->getArgument('package'); if (is_dir($p) || !$vsh->handle($p)) { $result->packageDirectory = @realpath($p); if ($result->packageDirectory === false) { throw new Exception("Unable to find the directory '{$p}'"); } $controllerFile = $result->packageDirectory . '/' . FILENAME_CONTROLLER; if (!is_file($controllerFile)) { throw new Exception("The directory '{$result->packageDirectory}' does not seems to contain a valid concrete5 package"); } $controllerContents = $fh->getContents($controllerFile); if ($controllerContents) { $allTokens = @token_get_all($controllerContents); if ($allTokens) { $tokens = array_values(array_filter($allTokens, function ($token) { $keep = true; if (is_array($token)) { switch ($token[0]) { case T_DOC_COMMENT: case T_WHITESPACE: case T_COMMENT: $keep = false; break; } } return $keep; })); $packageAppVersionRequired = null; // Look for package info for ($i = 0; $i < count($tokens) - 2; ++$i) { if ($result->packageHandle === null && is_array($tokens[$i + 0]) && $tokens[$i + 0][0] === T_VARIABLE && $tokens[$i + 0][1] === '$pkgHandle' && is_string($tokens[$i + 1]) && $tokens[$i + 1] === '=' && is_array($tokens[$i + 2]) && $tokens[$i + 2][0] === T_CONSTANT_ENCAPSED_STRING) { $result->packageHandle = @eval('return ' . $tokens[$i + 2][1] . ';'); if (!is_string($result->packageHandle) || $result->packageHandle === '') { $result->packageHandle = null; } } if ($result->packageVersion === null && is_array($tokens[$i + 0]) && $tokens[$i + 0][0] === T_VARIABLE && $tokens[$i + 0][1] === '$pkgVersion' && is_string($tokens[$i + 1]) && $tokens[$i + 1] === '=' && is_array($tokens[$i + 2]) && $tokens[$i + 2][0] === T_CONSTANT_ENCAPSED_STRING) { $result->packageVersion = @eval('return ' . $tokens[$i + 2][1] . ';'); if (!is_string($result->packageVersion) || $result->packageVersion === '') { $result->packageVersion = null; } } if ($packageAppVersionRequired === null && is_array($tokens[$i + 0]) && $tokens[$i + 0][0] === T_VARIABLE && $tokens[$i + 0][1] === '$appVersionRequired' && is_string($tokens[$i + 1]) && $tokens[$i + 1] === '=' && is_array($tokens[$i + 2]) && $tokens[$i + 2][0] === T_CONSTANT_ENCAPSED_STRING) { $packageAppVersionRequired = @eval('return ' . $tokens[$i + 2][1] . ';'); if (!is_string($packageAppVersionRequired) || $packageAppVersionRequired === '') { $packageAppVersionRequired = null; } } } if ($packageAppVersionRequired !== null) { if (version_compare($packageAppVersionRequired, '5.7') < 0) { $result->packageFormat = self::PACKAGEFORMAT_LEGACY; } else { $result->packageFormat = self::PACKAGEFORMAT_CURRENT; } } } } if ($result->packageHandle === null) { $result->packageHandle = basename($result->packageDirectory); } } else { foreach (Package::getAvailablePackages(false) as $pkg) { if (strcasecmp($p, $pkg->getPackageHandle()) === 0) { $result->packageHandle = $pkg->getPackageHandle(); $result->packageDirectory = $pkg->getPackagePath(); $result->packageVersion = $pkg->getPackageVersion(); $result->packageFormat = self::PACKAGEFORMAT_CURRENT; break; } } if ($result->packageHandle === null) { throw new Exception("Unable to find a package with handle '{$p}'"); } } $v = $input->getOption('short-tags'); switch ($v) { case static::SHORTTAGS_ALL: case static::SHORTTAGS_KEEPECHO: case static::SHORTTAGS_NO: $result->shortTags = $v; break; default: throw new Exception('Invalid value of the --short-tags option: ' . $v); } $v = $input->getOption('compile-icons'); switch ($v) { case static::YNA_YES: case static::YNA_AUTO: case static::YNA_NO: $result->compileIcons = $v; break; default: throw new Exception('Invalid value of the --compile-icons option: ' . $v); } $v = $input->getOption('compile-translations'); switch ($v) { case static::YNA_YES: case static::YNA_AUTO: case static::YNA_NO: $result->compileTranslations = $v; break; default: throw new Exception('Invalid value of the --compile-translations option: ' . $v); } $result->keep = array(); foreach ($input->getOption('keep') as $keep) { if (!in_array($keep, $result->keep)) { switch ($keep) { case static::KEEP_DOT: case static::KEEP_SOURCES: $result->keep[] = $keep; break; default: throw new Exception('Invalid value of the --keep option: ' . $keep); } } } $result->updateSourceDirectory = (bool) $input->getOption('update-source-directory'); $result->zipFilename = null; $zipOption = $input->getOption('zip'); if ($zipOption === static::ZIPOUT_AUTO) { if ($input->getParameterOption(array('--zip', '-z')) === false) { $zipOption = null; } } if ($zipOption !== null) { if ($zipOption === static::ZIPOUT_AUTO) { $zipOption = dirname($result->packageDirectory); } if (is_dir($zipOption)) { $dir = @realpath($zipOption); if ($dir === false) { throw new Exception('Unable to normalize the directory ' . $zipOption); } $result->zipFilename = $dir . DIRECTORY_SEPARATOR . $result->packageHandle; if ($result->packageVersion !== null) { $result->zipFilename .= '-' . $result->packageVersion; } $result->zipFilename .= '.zip'; } else { $result->zipFilename = $zipOption; } } return $result; }