Skip to content
Snippets Groups Projects
BaseHandler.php 2.63 KiB
Newer Older
  • Learn to ignore specific revisions
  • <?php
    
    namespace LakeDrops\Component\Composer;
    
    use Composer\Composer;
    use Composer\IO\IOInterface;
    
    use Composer\Script\Event;
    use Symfony\Component\Console\Input\InputInterface;
    
    
    /**
     * Class BaseHandler.
     *
     * @package LakeDrops\Component\Composer
     */
    
    abstract class BaseHandler implements BaseHandlerInterface {
    
    
      /**
       * The composer object of this session.
       *
       * @var \Composer\Composer
       */
      protected $composer;
    
      /**
       * The input-output object of the composer session.
       *
       * @var \Composer\IO\IOInterface
       */
      protected $io;
    
    
      /**
       * @var \Symfony\Component\Console\Input\InputInterface
       */
      protected $input;
    
      /**
       * The event that triggered the action.
       *
       * @var \Composer\Script\Event
       */
      protected $event;
    
    
      /**
       * The Drupal core package.
       *
       * @var \Composer\Package\PackageInterface
       */
      protected $drupalCorePackage;
    
      /**
       * Handler constructor.
       *
       * @param \Composer\Composer $composer
       *   The composer object of this session.
       * @param \Composer\IO\IOInterface $io
       *   The input-output object of the composer session.
       */
      public function __construct(Composer $composer, IOInterface $io) {
        $this->composer = $composer;
        $this->io = $io;
      }
    
    
      /**
       * {@inheritdoc}
       */
      public function setEvent(Event $event) {
        $this->event = $event;
        return $this;
      }
    
      /**
       * {@inheritdoc}
       */
      public function setInput(InputInterface $input) {
        $this->input = $input;
        return $this;
      }
    
    
       * {@inheritdoc}
    
      public function getDrupalCorePackage() {
    
        if (!isset($this->drupalCorePackage)) {
          $this->drupalCorePackage = $this->getPackage('drupal/core');
        }
        return $this->drupalCorePackage;
      }
    
      /**
    
       * {@inheritdoc}
    
      public function getPackage($name) {
    
        return $this->composer->getRepositoryManager()->getLocalRepository()->findPackage($name, '*');
      }
    
    
      /**
       * {@inheritdoc}
       */
    
        if ($this->event !== NULL) {
          return $this->event->isDevMode();
        }
        if ($this->input !== NULL) {
          return !$this->input->hasOption('no-dev');
        }
        return FALSE;
      }
    
    
      /**
       * {@inheritdoc}
       */
    
      public function isLocalDevMode(): bool {
    
        $local_dev_mode = getenv('LAKEDROPS_DEV_ENV');
        return !empty($local_dev_mode);
      }
    
    
       * {@inheritdoc}
       */
    
      public function isCiContext(): bool {
    
        $ci_project_dir = getenv('CI_PROJECT_DIR');
    
        return !empty($ci_project_dir);
    
      }
    
      /**
       * {@inheritdoc}
    
      public function git($command) {
    
      /**
       * {@inheritdoc}
       */
      public function gitIgnore($pattern) {