You are here

class Command in Composer Manager 8

Callbacks for Composer commands defined by Composer Manager.

Commands:

  • 'composer drupal-rebuild'
  • 'composer drupal-update'

Hierarchy

  • class \Drupal\composer_manager\Composer\Command

Expanded class hierarchy of Command

File

src/Composer/Command.php, line 17

Namespace

Drupal\composer_manager\Composer
View source
class Command {

  /**
   * Rebuilds the root package.
   */
  public static function rebuild(Event $event) {
    $package_manager = self::getPackageManager();
    $package_manager
      ->rebuildRootPackage();
    echo 'The composer.json has been successfuly rebuilt.' . PHP_EOL;
  }

  /**
   * Rebuilds the root package, then calls 'composer update'.
   */
  public static function update(Event $event) {
    $package_manager = self::getPackageManager();
    $package_manager
      ->rebuildRootPackage();

    // Change the requested command to 'update', and rerun composer.
    $command_index = array_search('drupal-update', $_SERVER['argv']);
    $_SERVER['argv'][$command_index] = 'update';
    $application = new Application();
    $application
      ->run();
  }

  /**
   * Returns a \Drupal\composer_manager\PackageManager instance.
   */
  public static function getPackageManager() {
    $root = getcwd();
    require $root . '/autoload.php';

    // The module classes aren't in the autoloader at this point.
    require __DIR__ . '/../ExtensionDiscovery.php';
    require __DIR__ . '/../JsonFile.php';
    require __DIR__ . '/../PackageManagerInterface.php';
    require __DIR__ . '/../PackageManager.php';

    // YAML discovery in core uses FileCache which is not available.
    FileCacheFactory::setConfiguration([
      'default' => [
        'class' => '\\Drupal\\Component\\FileCache\\NullFileCache',
      ],
    ]);
    return new PackageManager($root);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Command::getPackageManager public static function Returns a \Drupal\composer_manager\PackageManager instance.
Command::rebuild public static function Rebuilds the root package.
Command::update public static function Rebuilds the root package, then calls 'composer update'.