You are here

class CakePHPInstaller in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/composer/installers/src/Composer/Installers/CakePHPInstaller.php \Composer\Installers\CakePHPInstaller

Hierarchy

Expanded class hierarchy of CakePHPInstaller

1 file declares its use of CakePHPInstaller
CakePHPInstallerTest.php in vendor/composer/installers/tests/Composer/Installers/Test/CakePHPInstallerTest.php

File

vendor/composer/installers/src/Composer/Installers/CakePHPInstaller.php, line 9

Namespace

Composer\Installers
View source
class CakePHPInstaller extends BaseInstaller {
  protected $locations = array(
    'plugin' => 'Plugin/{$name}/',
  );

  /**
   * Format package name to CamelCase
   */
  public function inflectPackageVars($vars) {
    if ($this
      ->matchesCakeVersion('>=', '3.0.0')) {
      return $vars;
    }
    $nameParts = explode('/', $vars['name']);
    foreach ($nameParts as &$value) {
      $value = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $value));
      $value = str_replace(array(
        '-',
        '_',
      ), ' ', $value);
      $value = str_replace(' ', '', ucwords($value));
    }
    $vars['name'] = implode('/', $nameParts);
    return $vars;
  }

  /**
   * Change the default plugin location when cakephp >= 3.0
   */
  public function getLocations() {
    if ($this
      ->matchesCakeVersion('>=', '3.0.0')) {
      $this->locations['plugin'] = $this->composer
        ->getConfig()
        ->get('vendor-dir') . '/{$vendor}/{$name}/';
    }
    return $this->locations;
  }

  /**
   * Check if CakePHP version matches against a version
   *
   * @param string $matcher
   * @param string $version
   * @return bool
   */
  protected function matchesCakeVersion($matcher, $version) {
    $repositoryManager = $this->composer
      ->getRepositoryManager();
    if ($repositoryManager) {
      $repos = $repositoryManager
        ->getLocalRepository();
      if (!$repos) {
        return false;
      }
      $cake3 = new MultiConstraint(array(
        new VersionConstraint($matcher, $version),
        new VersionConstraint('!=', '9999999-dev'),
      ));
      $pool = new Pool('dev');
      $pool
        ->addRepository($repos);
      $packages = $pool
        ->whatProvides('cakephp/cakephp');
      foreach ($packages as $package) {
        $installed = new VersionConstraint('=', $package
          ->getVersion());
        if ($cake3
          ->matches($installed)) {
          return true;
          break;
        }
      }
    }
    return false;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
BaseInstaller::$composer protected property
BaseInstaller::$package protected property
BaseInstaller::getInstallPath public function Return the install path based on package type. 1
BaseInstaller::mapCustomInstallPaths protected function Search through a passed paths array for a custom install path.
BaseInstaller::templatePath protected function Replace vars in a path
BaseInstaller::__construct public function Initializes base installer.
CakePHPInstaller::$locations protected property Overrides BaseInstaller::$locations
CakePHPInstaller::getLocations public function Change the default plugin location when cakephp >= 3.0 Overrides BaseInstaller::getLocations
CakePHPInstaller::inflectPackageVars public function Format package name to CamelCase Overrides BaseInstaller::inflectPackageVars
CakePHPInstaller::matchesCakeVersion protected function Check if CakePHP version matches against a version