protected function __construct(CommandEvent $event)
 {
     $this->composerEvent = $event;
     $this->io = $this->composerEvent->getIO();
     $this->extras = $this->composerEvent->getComposer()->getPackage()->getExtra();
     $this->fs = new Filesystem();
 }
Example #2
0
 protected static function getOptions(CommandEvent $event)
 {
     $options = array_merge(array('symfony-app-dir' => 'app', 'symfony-web-dir' => 'web', 'symfony-assets-install' => 'hard'), $event->getComposer()->getPackage()->getExtra());
     $options['symfony-assets-install'] = getenv('SYMFONY_ASSETS_INSTALL') ?: $options['symfony-assets-install'];
     $options['process-timeout'] = $event->getComposer()->getConfig()->get('process-timeout');
     return $options;
 }
 /**
  * Checks for the twitter/bootstrap package and copys all necessary files into the specified directory.
  *
  * Where the files are copied into must be specified in the extra section in the project's `composer.json`.
  *
  * 		"extra": {
  * 			"bootstrap-public-dir": "src/Acme/MyBundle/Resources/public",
  * 			...
  * 		}
  *
  * @param CommandEvent $event
  */
 public static function copyBootstrapFiles(CommandEvent $event)
 {
     /** @var RootPackage $package */
     $package = $event->getComposer()->getPackage();
     /** @var Link[] $requires */
     $requires = $package->getRequires();
     // Show error if package was not found
     if (!in_array(self::$bootstrapPackageKey, array_keys($requires))) {
         echo PHP_EOL . "\tError: Could not find the Twitter Bootstrap package \"twitter/bootstrap\"." . PHP_EOL . PHP_EOL;
         return;
     }
     $fs = new Filesystem();
     // Check for package path
     $packagePath = static::_getPackagePath($event->getComposer());
     if (is_null($packagePath) or !$fs->exists($packagePath)) {
         echo PHP_EOL . "\tError: The twitter bootstrap package doesn't seem to be installed." . PHP_EOL . PHP_EOL;
         return;
     }
     $bootstrapPath = $packagePath . '/dist/';
     // Check the public path where it should be copied to
     $extra = $package->getExtra();
     if (!isset($extra['bootstrap-public-dir']) or !$fs->exists($extra['bootstrap-public-dir'])) {
         echo PHP_EOL . "\tError: Given bootstrap public directory doesn't exist: " . $extra['bootstrap-public-dir'] . PHP_EOL . PHP_EOL;
         return;
     }
     $bootstrapPublicPath = $extra['bootstrap-public-dir'];
     echo sprintf('Installing twitter bootstrap files into %s%s', $bootstrapPublicPath, PHP_EOL);
     $files = array('js/bootstrap.js', 'js/bootstrap.min.js', 'fonts/glyphicons-halflings-regular.eot', 'fonts/glyphicons-halflings-regular.svg', 'fonts/glyphicons-halflings-regular.ttf', 'fonts/glyphicons-halflings-regular.woff');
     foreach ($files as $file) {
         $fs->copy($bootstrapPath . $file, $bootstrapPublicPath . '/' . $file, true);
     }
 }
Example #4
0
 public static function exec(CommandEvent $event)
 {
     $composer = $event->getComposer();
     $installManager = $composer->getInstallationManager();
     $repoManager = $composer->getRepositoryManager();
     $packages = $repoManager->getLocalRepository()->getPackages();
     foreach ($packages as $package) {
         $path = $installManager->getInstallPath($package);
         $extra = $package->getExtra();
         if (array_key_exists('clean', $extra)) {
             // we have things to remove, try to take them out
             foreach ($extra['clean'] as $remove) {
                 $resolvePath = realpath($path . '/' . $remove);
                 if ($resolvePath !== false) {
                     if (is_dir($resolvePath)) {
                         self::unlinkDirectory($resolvePath);
                         // rmdir($resolvePath);
                     } elseif (is_file($resolvePath)) {
                         // unlink($resolvePath);
                         self::unlinkFile($resolvePath);
                     }
                 }
             }
         }
     }
 }
 /**
  * Listener to the POST_INSTALL_CMD, POST_UPDATE_CMD and POST_CREATE_PROJECT_CMD events
  * It contains the code that launch the execution of the finalize precedures
  *
  * @param  \Composer\Script\CommandEvent $event Event to handle
  *
  */
 public function onPostInstallCMD(CommandEvent $event)
 {
     $packages = $event->getComposer()->getRepositoryManager()->getLocalRepository()->getPackages();
     foreach ($packages as $package) {
         $this->onEventHandler($package, "finalize");
     }
     $this->doRetry();
 }
Example #6
0
 protected static function getConfigs(CommandEvent $event)
 {
     $extras = array_merge(array('app-version-key' => 'version_number'), $event->getComposer()->getPackage()->getExtra());
     if (!isset($extras['incenteev-parameters'])) {
         throw new \InvalidArgumentException('The parameter handler needs to be configured through the extra.incenteev-parameters setting.');
     }
     $configs = $extras['incenteev-parameters'];
     return $configs;
 }
 /**
  * Build a directory path starting on the project base
  *
  * @param CommandEvent $event
  * @param string       $directory
  */
 private static function buildPathFromBase(CommandEvent $event, $directory)
 {
     /** @var Package $package */
     $package = $event->getComposer()->getPackage();
     $extra = $package->getExtra();
     // Generate the complete path.
     $basePath = getcwd();
     $path = array_key_exists($directory, $extra) ? $extra[$directory] : self::$options[$directory];
     $completePath = sprintf('%s/%s', $basePath, $path);
     // Set values.
     self::$options[self::CONSOLE_APPLICATION_BASE_DIR] = $basePath;
     self::$options[$directory] = $completePath;
 }
Example #8
0
 protected static function executeCommand(CommandEvent $event, $cmd, $timeout = 300)
 {
     $extra = $event->getComposer()->getPackage()->getExtra();
     $binDir = $extra['sb-bin-dir'];
     if (!is_dir($binDir)) {
         echo 'The sb-bin-dir (' . $binDir . ') specified in composer.json was not found in ' . getcwd() . ', can not clear the cache.' . PHP_EOL;
         return;
     }
     $php = escapeshellarg(self::getPhp());
     $console = escapeshellarg($binDir . '/sb');
     if ($event->getIO()->isDecorated()) {
         $console .= ' --ansi';
     }
     $process = new Process($php . ' ' . $console . ' ' . $cmd, null, null, null, $timeout);
     $process->run(function ($type, $buffer) {
         echo $buffer;
     });
     if (!$process->isSuccessful()) {
         throw new \RuntimeException(sprintf('An error occurred when executing the "%s" command.', escapeshellarg($cmd)));
     }
 }
Example #9
0
 /**
  * Sets the correct skeleton for the unit tests.
  * @param CommandEvent $event
  */
 public static function initTestsSkeleton($event)
 {
     $options = $event->getComposer()->getPackage()->getExtra();
     if (!isset($options[self::EXTRA_SKELETON], $options[self::EXTRA_SKELETON]['path'])) {
         $path = 'tests/js';
     } else {
         $path = $options[self::EXTRA_SKELETON]['path'];
     }
     $path = getcwd() . DIRECTORY_SEPARATOR . $path;
     echo "Setting init tests skeleton: {$path} ...\n";
     if (!file_exists($path)) {
         if (FileHelper::createDirectory($path)) {
             FileHelper::copyDirectory(self::getSourceSkeletonPath(), $path);
             echo "done\n";
         } else {
             echo "The directory was not found: " . $path . "\n";
         }
     } else {
         echo "{$path} directory is exists\n";
         return;
     }
 }
 /**
  * Deploy a proper settings/override/site.ini using settings/override/site.ini.dist as a template
  * Only main DB parameters (Host,Port,User,Password,Database) are replaced using the Symfony parameters
  *
  * @param $event CommandEvent A instance
  */
 public static function siteIniUpdate(CommandEvent $event)
 {
     $extras = $event->getComposer()->getPackage()->getExtra();
     if (!isset($extras['ezpublish-legacy-utility'])) {
         throw new \InvalidArgumentException('The eZ Publish Utility handler needs to be configured through the extra.ezpublish-legacy-utility setting.');
     }
     $configs = $extras['ezpublish-legacy-utility'];
     $yamlParser = new Parser();
     $parameters = $yamlParser->parse(file_get_contents($configs['parameters-file']));
     file_put_contents($configs['legacy-site_ini'], file_get_contents($configs['legacy-site_ini-dist']));
     $siteIniArray = file($configs['legacy-site_ini']);
     $dbSection = false;
     $siteIniUpdated = array();
     foreach ($siteIniArray as $siteIniRow) {
         $siteIniRow = trim($siteIniRow);
         if (substr($siteIniRow, 0, 1) === '[') {
             if ($siteIniRow === "[DatabaseSettings]") {
                 $dbSection = true;
             } else {
                 $dbSection = false;
             }
         }
         if ($dbSection) {
             if (strstr($siteIniRow, '=', true) != false) {
                 $key = strstr($siteIniRow, '=', true);
                 if (array_key_exists($key, $configs['parameters-map'])) {
                     $siteIniRow = $key . "=" . $parameters['parameters'][$configs['parameters-map'][$key]];
                 }
             }
         }
         $siteIniUpdated[] = $siteIniRow;
     }
     file_put_contents($configs['legacy-site_ini'], "");
     foreach ($siteIniUpdated as $siteIniUpdatedRow) {
         file_put_contents($configs['legacy-site_ini'], $siteIniUpdatedRow . "\n", FILE_APPEND);
     }
 }
Example #11
0
 /**
  * Sets the correct permission for the files and directories listed in the extra section.
  * @param CommandEvent $event
  */
 public static function setPermission($event)
 {
     $options = array_merge([self::EXTRA_WRITABLE => [], self::EXTRA_EXECUTABLE => []], $event->getComposer()->getPackage()->getExtra());
     foreach ((array) $options[self::EXTRA_WRITABLE] as $path) {
         echo "Setting writable: {$path} ...";
         if (is_dir($path)) {
             chmod($path, 0777);
             echo "done\n";
         } else {
             echo "The directory was not found: " . getcwd() . DIRECTORY_SEPARATOR . $path;
             return;
         }
     }
     foreach ((array) $options[self::EXTRA_EXECUTABLE] as $path) {
         echo "Setting executable: {$path} ...";
         if (is_file($path)) {
             chmod($path, 0755);
             echo "done\n";
         } else {
             echo "\n\tThe file was not found: " . getcwd() . DIRECTORY_SEPARATOR . $path . "\n";
             return;
         }
     }
 }
Example #12
0
 /**
  * Updates the Puli repository after Composer installations/updates.
  *
  * @param CommandEvent $event The Composer event.
  */
 public function postInstall(CommandEvent $event)
 {
     // Plugin has been uninstalled
     if (!file_exists(__FILE__)) {
         return;
     }
     if (!$this->initialized) {
         $this->initialize($event->getComposer(), $event->getIO());
     }
     // This method is called twice. Run it only once.
     if (!$this->runPostInstall) {
         return;
     }
     $this->runPostInstall = false;
     $io = $event->getIO();
     $io->write('<info>Looking for updated Puli packages</info>');
     $rootPackage = $event->getComposer()->getPackage();
     $composerPackages = $this->loadComposerPackages($event->getComposer());
     $prodPackageNames = $this->filterProdPackageNames($composerPackages, $rootPackage);
     $env = $event->isDevMode() ? PuliPackage::ENV_DEV : PuliPackage::ENV_PROD;
     try {
         $puliPackages = $this->loadPuliPackages();
     } catch (PuliRunnerException $e) {
         $this->printWarning($io, 'Could not load Puli packages', $e);
         return;
     }
     // Don't remove non-existing packages in production environment
     // Removed packages could be dev dependencies (i.e. "require-dev"
     // of the root package or "require" of another dev dependency), and
     // we can't find out whether they are since Composer doesn't load them
     if (PuliPackage::ENV_PROD !== $env) {
         $this->removeRemovedPackages($composerPackages, $puliPackages, $io);
     }
     $this->installNewPackages($composerPackages, $prodPackageNames, $puliPackages, $io, $event->getComposer());
     // Don't print warnings for non-existing packages in production
     if (PuliPackage::ENV_PROD !== $env) {
         $this->checkForNotFoundErrors($puliPackages, $io);
     }
     $this->checkForNotLoadableErrors($puliPackages, $io);
     $this->adoptComposerName($puliPackages, $io, $event->getComposer());
     $this->buildPuli($io);
 }
Example #13
0
 public static function hookRootPackageInstall(CommandEvent $event)
 {
     $event->getComposer()->getEventDispatcher()->addSubscriber(new InstallationHelper());
 }
 protected static function loadConfiguration(CommandEvent $event)
 {
     $composerConfiguration = $event->getComposer()->getPackage()->getExtra();
     return static::getOptions(isset($composerConfiguration['cqt-parameters']) ? $composerConfiguration['cqt-parameters'] : []);
 }
 /**
  * Get a default set of options.
  *
  * @param CommandEvent $event
  *
  * @return array
  */
 protected static function getOptions(CommandEvent $event)
 {
     $options = array_merge(array('bolt-separate-web-dir' => true, 'bolt-web-dir' => 'public', 'bolt-app-dir' => 'app', 'bolt-dir-mode' => 0777), $event->getComposer()->getPackage()->getExtra());
     return $options;
 }
Example #16
0
 public static function deleteCache(CommandEvent $event)
 {
     $options = array_merge(array('symfony-app-dir' => 'app'), $event->getComposer()->getPackage()->getExtra());
     $cacheDir = $options['symfony-app-dir'] . '/cache';
     $event->getIO()->write('Clearing the cache...');
     static::removeContentFrom($cacheDir);
 }
Example #17
0
 protected static function getOptions(CommandEvent $event)
 {
     return array_merge(self::$options, $event->getComposer()->getPackage()->getExtra());
 }
Example #18
0
 /**
  * Get a default set of options.
  *
  * @param CommandEvent $event
  *
  * @return array
  */
 protected static function getOptions(CommandEvent $event)
 {
     $options = array_merge(['bolt-web-dir' => 'web', 'bolt-app-dir' => 'app', 'bolt-dir-mode' => 0777], $event->getComposer()->getPackage()->getExtra());
     return $options;
 }
Example #19
0
 protected static function getOptions(CommandEvent $event)
 {
     $options = array_merge(array('schema-update-force' => true), $event->getComposer()->getPackage()->getExtra());
     return $options;
 }
Example #20
0
 /**
  * @param CommandEvent $event
  * @return Config
  */
 protected static function getConfig(CommandEvent $event)
 {
     return Config::load($event->getComposer());
 }
Example #21
0
 protected static function getOptions(CommandEvent $event)
 {
     $options = array_merge(self::$options, $event->getComposer()->getPackage()->getExtra());
     $options['process-timeout'] = $event->getComposer()->getConfig()->get('process-timeout');
     return $options;
 }
Example #22
0
 /**
  * event listener is named this way, as it listens for events leading to changed code files
  *
  * @param \Composer\Script\CommandEvent $event
  */
 public function onNewCodeEvent(\Composer\Script\CommandEvent $event)
 {
     if ($this->io->isDebug()) {
         $this->io->write('start magento deploy via deployManager');
     }
     $this->deployManager->doDeploy();
     $this->deployLibraries();
     $this->saveVendorDirPath($event->getComposer());
 }
 protected static function getOptions(CommandEvent $event)
 {
     $options = array_merge(array('symfony-app-dir' => 'app'), $event->getComposer()->getPackage()->getExtra());
     return $options;
 }
 public function __construct(CommandEvent $event)
 {
     $this->configuration = $event->getComposer()->getPackage()->getExtra();
 }
 protected static function getConfigOptions(CommandEvent $event)
 {
     $allConfig = $event->getComposer()->getConfig()->all();
     $options = array_merge(array('vendor-dir' => './li/bs'), $allConfig['config']);
     return $options;
 }
Example #26
0
 public static function postInstall(CommandEvent $event)
 {
     $composer = $event->getComposer();
     echo "Creating directory structure...\n";
     $dirs = array();
     $dirs[] = 'bin';
     $dirs[] = 'cache' . DIRECTORY_SEPARATOR . 'view';
     $dirs[] = 'cache' . DIRECTORY_SEPARATOR . 'config';
     $dirs[] = 'applications';
     $dirs[] = 'config';
     foreach ($dirs as $dir) {
         futil_mkdir_if_not_exists($dir, 0755, true);
     }
     echo "Installing main.php\n";
     if (!file_exists('main.php')) {
         copy('vendor/corneltek/phifty-core/main_app.php', 'main.php');
     }
     if (!file_exists('config/framework.yml')) {
         echo "Installing default framework config...\n";
         $appId = basename(getcwd());
         $appName = ucfirst(basename(getcwd()));
         $uuid = UUID::v4();
         $domain = $appId . '.dev';
         echo "ApplicationId: {$appId}, Domain: {$domain}, UUID: {$uuid}\n";
         $content = self::createConfigFromTemplate($appId, $appName, $uuid, $domain);
         file_put_contents("config/framework.yml", $content);
     }
     if (!file_exists('config/database.yml')) {
         echo "Installing default database config...\n";
         copy('vendor/corneltek/phifty-core/config/database.yml', 'config/database.yml');
         echo "Rewriting database config...\n";
         $config = ConfigCompiler::load('config/database.yml');
         $config['data_sources']['default'] = array('database' => basename(getcwd()), 'driver' => 'mysql', 'host' => 'localhost', 'user' => 'user', 'pass' => 'pass');
         file_put_contents("config/database.yml", yaml_emit($config));
     }
     if (!file_exists('locale')) {
         echo "Installing locale...\n";
         passthru('rsync -r vendor/corneltek/phifty-core/locale/ locale/');
     }
     if (!file_exists('webroot')) {
         passthru('rsync -r vendor/corneltek/phifty-core/webroot/ webroot/');
     }
     echo "Changing permissions...\n";
     $chmods = array();
     $chmods[] = array("og+rw", "cache");
     $chmods[] = array("og+rw", "webroot" . DIRECTORY_SEPARATOR . 'static' . DIRECTORY_SEPARATOR . 'upload');
     foreach ($chmods as $mod) {
         list($mod, $path) = $mod;
         if (!file_exists($path)) {
             mkdir($path, 0755, true);
         }
         system("chmod -R {$mod} {$path}");
     }
     if (!file_exists('.gitignore')) {
         copy('vendor/corneltek/phifty-core/.gitignore', '.gitignore');
     }
     echo "Done";
 }
 /**
  * Get the default options.
  *
  * @param CommandEvent $event
  *
  * @return array
  */
 protected static function getOptions(CommandEvent $event)
 {
     $options = array_merge(array('symfony-app-dir' => 'app', 'symfony-bin-dir' => 'bin'), $event->getComposer()->getPackage()->getExtra());
     $options['process-timeout'] = $event->getComposer()->getConfig()->get('process-timeout');
     return $options;
 }
 /**
  * Updates the Puli repository after Composer installations/updates.
  *
  * @param CommandEvent $event The Composer event.
  */
 public function postInstall(CommandEvent $event)
 {
     // This method is called twice. Run it only once.
     if (!$this->runPostInstall) {
         return;
     }
     $this->runPostInstall = false;
     $io = $event->getIO();
     $io->write('<info>Looking for updated Puli packages</info>');
     $composerPackages = $this->loadComposerPackages($event->getComposer());
     try {
         $puliPackages = $this->loadPuliPackages();
     } catch (PuliRunnerException $e) {
         $this->printWarning($io, 'Could not load Puli packages', $e);
         return;
     }
     $this->removeRemovedPackages($composerPackages, $puliPackages, $io);
     $this->installNewPackages($composerPackages, $puliPackages, $io, $event->getComposer());
     $this->checkForLoadErrors($puliPackages, $io);
     $this->adoptComposerName($puliPackages, $io, $event->getComposer());
     $this->buildPuli($io);
 }
 /**
  * Returns the available options defined in the composer file.
  *
  * @param CommandEvent $event Command event object
  * @return array Associative list of option keys and values
  */
 protected static function getOptions(CommandEvent $event)
 {
     return $event->getComposer()->getPackage()->getExtra();
 }
Example #30
0
 /**
  * Installer process for project based on post install event hook on composer.
  *
  * @param CommandEvent $event The event passed in by Composer.
  *
  * @author Benjamin Carl <*****@*****.**>
  * @return boolean|null TRUE on success, otherwise FALSE (signal for Composer to resolve with error)
  * @access public
  * @static
  */
 public static function postInstall(CommandEvent $event)
 {
     // Detect path to composer.json
     self::setInstallPath(self::retrieveInstallPath());
     // We must include autoloader - funny.
     require_once self::getInstallPath() . DIRECTORY_SEPARATOR . 'vendor/autoload.php';
     // Store extra from composer
     self::setExtra($event->getComposer()->getPackage()->getExtra());
     // Force colors
     \cli\Colors::enable();
     // Process event
     return self::handleEvent($event);
 }