/** * @return string */ protected static function getCoreHooksPath() { foreach (static::$event->getArguments() as $arg) { if (strpos($arg, '--') !== 0) { return $arg; } } /** @var \Composer\Package\Package $root_package */ $root_package = static::$event->getComposer()->getPackage(); $extra = $root_package->getExtra(); if (!empty($extra[static::$selfPackage['name']]['core.hooksPath'])) { return $extra[static::$selfPackage['name']]['core.hooksPath']; } if (is_dir(static::$defaultCoreHooksPath)) { return static::$defaultCoreHooksPath; } /** @var \Composer\Config $config */ $config = static::$event->getComposer()->getConfig(); $chg_path_abs = $config->get('vendor-dir') . '/' . static::$selfPackage['name']; $cwd = getcwd(); $cgh_path_rel = preg_replace('@^' . preg_quote("{$cwd}/", '@') . '@', '', "{$chg_path_abs}/"); $cgh_path_rel = rtrim($cgh_path_rel, '/'); if (!$cgh_path_rel) { $cgh_path_rel = '.'; } if (is_dir("{$cgh_path_rel}/" . static::$defaultCoreHooksPath)) { return "{$cgh_path_rel}/" . static::$defaultCoreHooksPath; } if ($root_package->getName() === static::$selfPackage['name']) { return static::$defaultCoreHooksPath; } return realpath(__DIR__ . '/..') . '/' . static::$defaultCoreHooksPath; }
public static function postCreateProject(Event $event) { $args = $event->getArguments(); /** @var \Composer\IO\IOInterface $io */ $io = $event->getIO(); $projectIdentifier = isset($args['directory']) ? $args['directory'] : 'my-project'; $projectIdentifier = $io->ask('Enter the project identifier [<comment>' . $projectIdentifier . '</comment>]: ', $projectIdentifier); $projectName = ucwords(str_replace('-', ' ', $projectIdentifier)); $projectName = $io->ask('Enter the project name [<comment>' . $projectName . '</comment>]: ', $projectName); self::replace(__DIR__ . '/.gitignore', $projectName, $projectIdentifier); self::replace(__DIR__ . '/composer.json.template', $projectName, $projectIdentifier); self::replace(__DIR__ . '/Gruntfile.js', $projectName, $projectIdentifier); self::replace(__DIR__ . '/package.json', $projectName, $projectIdentifier); self::replace(__DIR__ . '/webpack.config.js', $projectName, $projectIdentifier); self::replace(__DIR__ . '/README.md.template', $projectName, $projectIdentifier); self::replaceDir(__DIR__ . '/web/wp-content/themes/wordpress-boilerplate', $projectName, $projectIdentifier); rename(__DIR__ . '/web/wp-content/themes/wordpress-boilerplate', __DIR__ . '/web/wp-content/themes/' . $projectIdentifier); unlink(__DIR__ . '/README.md'); rename(__DIR__ . '/README.md.template', __DIR__ . '/README.md'); unlink(__DIR__ . '/composer.json'); rename(__DIR__ . '/composer.json.template', __DIR__ . '/composer.json'); unlink(__DIR__ . '/composer.lock'); self::removeDir(__DIR__ . '/vendor'); unlink(__DIR__ . '/ComposerScripts.php'); }
public static function migrateDatabase(Event $event = null, $testing = false) { if ($event) { // Use the event's IO $io = $event->getIO(); $arguments = $event->getArguments(); $testingArguments = array('testing', '--testing', '-t'); $testing = count(array_intersect($arguments, $testingArguments)) > 0; } else { // Create our own IO $input = new ArrayInput(array()); $output = new ConsoleOutput(); $helperSet = new HelperSet(array(new QuestionHelper())); $io = new ConsoleIO($input, $output, $helperSet); } try { $config = self::getDatabaseConfig($testing); } catch (\Exception $e) { $io->write("<bg=red>\n\n [WARNING] " . $e->getMessage() . ", the database won't be updated\n</>"); return; } // If the database doesn't exist, ask the user to create it and perform // the necessary migrations (unless the user didn't agree to // create the database) if (self::createDatabase($io, $config['host'], $config['username'], $config['password'], $config['database'])) { $io->write(''); // newline $arguments = array('migrate', '-e' => $testing ? 'test' : 'main'); $app = new PhinxApplication(); $app->doRun(new ArrayInput($arguments), new ConsoleOutput()); } }
/** * Run with composer validate-masonry * @param Event $event * * @SuppressWarnings(PHPMD.StaticAccess) */ public static function validate(Event $event) { $configFile = ''; $localYaml = getcwd() . '/masonry.yaml'; if (is_file($localYaml)) { $configFile = $localYaml; } if (array_key_exists(0, $event->getArguments())) { $configFile = $event->getArguments()[0]; if (!is_file($configFile)) { throw new \InvalidArgumentException("'{$configFile}' is not a Module configuration file"); } } // Validate YamlWorkerModuleDefinition::load($configFile); $event->getIO()->write("Module file '{$configFile}' is valid"); }
public static function buildResource(Event $event) { $io = $event->getIO(); $args = ScriptToolkit::processArguments($event->getArguments()); $target = isset($args['target']) ? ' -target ' . $args['target'] : ''; $target = isset($args['all']) ? ' -target all' : $target; $process = ScriptToolkit::createProcess('bin/cli honeybee.core.trellis.generate_code -quiet' . $target, ScriptToolkit::getProjectPath($event)); $process->run(function ($type, $buffer) use($io) { $io->write($buffer, false); }); }
public static function importFixture(Event $event) { $args = ScriptToolkit::processArguments($event->getArguments()); $target = isset($args['target']) ? ' -target ' . $args['target'] : ''; $fixture = isset($args['fixture']) ? ' -fixture ' . $args['fixture'] : ''; $io = $event->getIO(); $process = ScriptToolkit::createProcess('bin/cli honeybee.core.fixture.import' . $target . $fixture, ScriptToolkit::getProjectPath($event)); $process->run(function ($type, $buffer) use($io) { $io->write($buffer, false); }); }
public static function run(Event $event) { $args = $event->getArguments(); define('BASEPATH', 'foobar'); /* for old school file protector */ define('ROOTPATH', realpath('.')); define('ENVIRONMENT', $_SERVER['SERVER_ENVIRONMENT']); define('DEBUG', $_SERVER['SERVER_DEBUG']); require __DIR__ . '/includes/compat.php'; require __DIR__ . '/includes/functions.php'; require __DIR__ . '/includes/output.php'; $output = new \output(true); $func = new \func(); $methods = get_class_methods($func); if (!isset($args[0])) { $methods[] = 'cli +{any codeigniter cli command}'; sort($methods); $actions = ''; foreach ($methods as $m) { if ($m[0] != '_') { $actions .= str_replace('_', ' ', $m) . chr(10); } } $output->e('<blue>Please provide action:<off>' . chr(10) . trim($actions), true); } if ($args[0] == 'cli') { /* shift off cli */ array_shift($args); /* call codeigniter cli script passthru */ passthru('cd ' . ROOTPATH . '/public;php index.php ' . implode(' ', $args)); exit(0); } /* is the command there? */ $command = implode('_', $args); if (!in_array($command, $methods)) { $output->e('<red>Unknown Command: ' . $command, true); } /* load setup json */ $setup_file = __DIR__ . '/setup.json'; $output->e('<yellow>Setup File ' . $setup_file); if (!file_exists($setup_file)) { $output->e('<red>Setup File Missing?', true); } $setup = json_decode(file_get_contents($setup_file), true); /* start the party */ $output->e('<green>Start ' . $args[0]); $func->_process($command, $setup, $output); $output->e('<green>Finished'); }
protected static function _getApiKey(Event $event) { //Check if api key got passed as argument $arguments = $event->getArguments(); if (isset($arguments[0])) { return $arguments[0]; } //Check for `.apikey` file in the working directory $composer = $event->getComposer(); $apiKeyFile = realpath(implode(DIRECTORY_SEPARATOR, [__DIR__, '..', '..', '..', '.apikey'])); if (is_readable($apiKeyFile)) { return trim(file_get_contents($apiKeyFile)); } //No api key found, throw Exception throw new \Exception('Please provide a valid api key. Pass it as argument or put it in the `.apikey` file.'); }
public static function call(Event $event) { $io = $event->getIO(); $args = ScriptToolkit::processArguments($event->getArguments()); if (!isset($args['route'])) { throw new Exception('"route" argument is required'); } $cmd_line = ['bin/cli', $args['route']]; unset($args['route']); foreach ($args as $arg => $val) { $cmd_line[] = '-' . $arg; $cmd_line[] = $val; } $process = ScriptToolkit::createProcess(implode(' ', $cmd_line), ScriptToolkit::getProjectPath($event)); $process->run(function ($type, $buffer) use($io) { $io->write($buffer, false); }); }
/** * This method will be invoked by composer after a successful installation and creates * the application server configuration file under etc/appserver/appserver.xml. * * @param \Composer\Script\Event $event The event that invokes this method * * @return void */ public static function postInstall(Event $event) { // initialize the installation directory $override = false; $installDir = getcwd(); // check the arguments for an installation directory foreach ($event->getArguments() as $arg) { // extract arguments list($key, ) = explode('=', $arg); // query we want to override files if ($key === SetupKeys::ARG_OVERRIDE) { $override = true; } // query for a custom installation directory if ($key === SetupKeys::ARG_INSTALL_DIR) { $installDir = str_replace("{$key}=", '', $arg); } } Setup::prepareContext($installDir, $event); // process and move the configuration files their target directory Setup::processTemplate('etc/appserver/appserver.xml', $override); // write a message to the console $event->getIo()->write(sprintf('%s<info>Successfully invoked appserver.io Composer post-install-cmd script ...</info>', Setup::$logo)); }
/** * Instantiate an AbstractTask object. * * @since 0.1.0 * * @param ConfigInterface $config Configuration settings. * @param Event $event The Composer Event that is being handled. * * @throws FailedToProcessConfigException If the configuration could not be processed. */ public function __construct(ConfigInterface $config, Event $event) { $this->processConfig($config); $this->event = $event; $this->name = $event->getName(); $this->arguments = $event->getArguments(); $this->flags = $event->getFlags(); $this->composer = $event->getComposer(); $this->io = $event->getIO(); }
/** * event listener is named this way, as it listens for events leading to changed code files * * @param Event $event */ public function onNewCodeEvent(Event $event) { $packageTypeToMatch = static::PACKAGE_TYPE; $magentoModules = array_filter($this->composer->getRepositoryManager()->getLocalRepository()->getPackages(), function (PackageInterface $package) use($packageTypeToMatch) { if ($package instanceof AliasPackage) { return false; } return $package->getType() === $packageTypeToMatch; }); $vendorDir = rtrim($this->composer->getConfig()->get(self::VENDOR_DIR_KEY), '/'); Helper::initMagentoRootDir($this->config, $this->io, $this->filesystem, $vendorDir); $this->applyEvents($this->getEventManager()); if (in_array('--redeploy', $event->getArguments())) { $this->writeDebug('remove all deployed modules'); $this->getModuleManager()->updateInstalledPackages(array()); } $this->writeDebug('start magento module deploy via moduleManager'); $this->getModuleManager()->updateInstalledPackages($magentoModules); $this->deployLibraries(); $patcher = Bootstrap::fromConfig($this->config); $patcher->setIo($this->io); try { $patcher->patch(); } catch (\DomainException $e) { $this->io->write('<comment>' . $e->getMessage() . '</comment>'); } }