You are here

class PluginState in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/wikimedia/composer-merge-plugin/src/Merge/PluginState.php \Wikimedia\Composer\Merge\PluginState

Mutable plugin state

@author Bryan Davis <bd808@bd808.com>

Hierarchy

Expanded class hierarchy of PluginState

1 file declares its use of PluginState
MergePlugin.php in vendor/wikimedia/composer-merge-plugin/src/MergePlugin.php

File

vendor/wikimedia/composer-merge-plugin/src/Merge/PluginState.php, line 20

Namespace

Wikimedia\Composer\Merge
View source
class PluginState {

  /**
   * @var Composer $composer
   */
  protected $composer;

  /**
   * @var array $includes
   */
  protected $includes = array();

  /**
   * @var array $requires
   */
  protected $requires = array();

  /**
   * @var array $duplicateLinks
   */
  protected $duplicateLinks = array();

  /**
   * @var bool $devMode
   */
  protected $devMode = false;

  /**
   * @var bool $recurse
   */
  protected $recurse = true;

  /**
   * @var bool $replace
   */
  protected $replace = false;

  /**
   * Whether to merge the -dev sections.
   * @var bool $mergeDev
   */
  protected $mergeDev = true;

  /**
   * Whether to merge the extra section.
   *
   * By default, the extra section is not merged and there will be many
   * cases where the merge of the extra section is performed too late
   * to be of use to other plugins. When enabled, merging uses one of
   * two strategies - either 'first wins' or 'last wins'. When enabled,
   * 'first wins' is the default behaviour. If Replace mode is activated
   * then 'last wins' is used.
   *
   * @var bool $mergeExtra
   */
  protected $mergeExtra = false;

  /**
   * @var bool $firstInstall
   */
  protected $firstInstall = false;

  /**
   * @var bool $locked
   */
  protected $locked = false;

  /**
   * @var bool $dumpAutoloader
   */
  protected $dumpAutoloader = false;

  /**
   * @var bool $optimizeAutoloader
   */
  protected $optimizeAutoloader = false;

  /**
   * @param Composer $composer
   */
  public function __construct(Composer $composer) {
    $this->composer = $composer;
  }

  /**
   * Load plugin settings
   */
  public function loadSettings() {
    $extra = $this->composer
      ->getPackage()
      ->getExtra();
    $config = array_merge(array(
      'include' => array(),
      'require' => array(),
      'recurse' => true,
      'replace' => false,
      'merge-dev' => true,
      'merge-extra' => false,
    ), isset($extra['merge-plugin']) ? $extra['merge-plugin'] : array());
    $this->includes = is_array($config['include']) ? $config['include'] : array(
      $config['include'],
    );
    $this->requires = is_array($config['require']) ? $config['require'] : array(
      $config['require'],
    );
    $this->recurse = (bool) $config['recurse'];
    $this->replace = (bool) $config['replace'];
    $this->mergeDev = (bool) $config['merge-dev'];
    $this->mergeExtra = (bool) $config['merge-extra'];
  }

  /**
   * Get list of filenames and/or glob patterns to include
   *
   * @return array
   */
  public function getIncludes() {
    return $this->includes;
  }

  /**
   * Get list of filenames and/or glob patterns to require
   *
   * @return array
   */
  public function getRequires() {
    return $this->requires;
  }

  /**
   * Set the first install flag
   *
   * @param bool $flag
   */
  public function setFirstInstall($flag) {
    $this->firstInstall = (bool) $flag;
  }

  /**
   * Is this the first time that the plugin has been installed?
   *
   * @return bool
   */
  public function isFirstInstall() {
    return $this->firstInstall;
  }

  /**
   * Set the locked flag
   *
   * @param bool $flag
   */
  public function setLocked($flag) {
    $this->locked = (bool) $flag;
  }

  /**
   * Was a lockfile present when the plugin was installed?
   *
   * @return bool
   */
  public function isLocked() {
    return $this->locked;
  }

  /**
   * Should an update be forced?
   *
   * @return true If packages are not locked
   */
  public function forceUpdate() {
    return !$this->locked;
  }

  /**
   * Set the devMode flag
   *
   * @param bool $flag
   */
  public function setDevMode($flag) {
    $this->devMode = (bool) $flag;
  }

  /**
   * Should devMode settings be processed?
   *
   * @return bool
   */
  public function isDevMode() {
    return $this->mergeDev && $this->devMode;
  }

  /**
   * Set the dumpAutoloader flag
   *
   * @param bool $flag
   */
  public function setDumpAutoloader($flag) {
    $this->dumpAutoloader = (bool) $flag;
  }

  /**
   * Is the autoloader file supposed to be written out?
   *
   * @return bool
   */
  public function shouldDumpAutoloader() {
    return $this->dumpAutoloader;
  }

  /**
   * Set the optimizeAutoloader flag
   *
   * @param bool $flag
   */
  public function setOptimizeAutoloader($flag) {
    $this->optimizeAutoloader = (bool) $flag;
  }

  /**
   * Should the autoloader be optimized?
   *
   * @return bool
   */
  public function shouldOptimizeAutoloader() {
    return $this->optimizeAutoloader;
  }

  /**
   * Add duplicate packages
   *
   * @param string $type Package type
   * @param array $packages
   */
  public function addDuplicateLinks($type, array $packages) {
    if (!isset($this->duplicateLinks[$type])) {
      $this->duplicateLinks[$type] = array();
    }
    $this->duplicateLinks[$type] = array_merge($this->duplicateLinks[$type], $packages);
  }

  /**
   * Get duplicate packages
   *
   * @param string $type Package type
   * @return array
   */
  public function getDuplicateLinks($type) {
    return isset($this->duplicateLinks[$type]) ? $this->duplicateLinks[$type] : array();
  }

  /**
   * Should includes be recursively processed?
   *
   * @return bool
   */
  public function recurseIncludes() {
    return $this->recurse;
  }

  /**
   * Should duplicate links be replaced in a 'last definition wins' order?
   *
   * @return bool
   */
  public function replaceDuplicateLinks() {
    return $this->replace;
  }

  /**
   * Should the extra section be merged?
   *
   * By default, the extra section is not merged and there will be many
   * cases where the merge of the extra section is performed too late
   * to be of use to other plugins. When enabled, merging uses one of
   * two strategies - either 'first wins' or 'last wins'. When enabled,
   * 'first wins' is the default behaviour. If Replace mode is activated
   * then 'last wins' is used.
   *
   * @return bool
   */
  public function shouldMergeExtra() {
    return $this->mergeExtra;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
PluginState::$composer protected property
PluginState::$devMode protected property
PluginState::$dumpAutoloader protected property
PluginState::$duplicateLinks protected property
PluginState::$firstInstall protected property
PluginState::$includes protected property
PluginState::$locked protected property
PluginState::$mergeDev protected property Whether to merge the -dev sections.
PluginState::$mergeExtra protected property Whether to merge the extra section.
PluginState::$optimizeAutoloader protected property
PluginState::$recurse protected property
PluginState::$replace protected property
PluginState::$requires protected property
PluginState::addDuplicateLinks public function Add duplicate packages
PluginState::forceUpdate public function Should an update be forced?
PluginState::getDuplicateLinks public function Get duplicate packages
PluginState::getIncludes public function Get list of filenames and/or glob patterns to include
PluginState::getRequires public function Get list of filenames and/or glob patterns to require
PluginState::isDevMode public function Should devMode settings be processed?
PluginState::isFirstInstall public function Is this the first time that the plugin has been installed?
PluginState::isLocked public function Was a lockfile present when the plugin was installed?
PluginState::loadSettings public function Load plugin settings
PluginState::recurseIncludes public function Should includes be recursively processed?
PluginState::replaceDuplicateLinks public function Should duplicate links be replaced in a 'last definition wins' order?
PluginState::setDevMode public function Set the devMode flag
PluginState::setDumpAutoloader public function Set the dumpAutoloader flag
PluginState::setFirstInstall public function Set the first install flag
PluginState::setLocked public function Set the locked flag
PluginState::setOptimizeAutoloader public function Set the optimizeAutoloader flag
PluginState::shouldDumpAutoloader public function Is the autoloader file supposed to be written out?
PluginState::shouldMergeExtra public function Should the extra section be merged?
PluginState::shouldOptimizeAutoloader public function Should the autoloader be optimized?
PluginState::__construct public function