ComposerInstallersBaseInstaller

The Simple Calendar Composer Installers BaseInstaller class.

Defined (1)

The class is defined in the following location(s).

/vendor/composer/installers/src/Composer/Installers/BaseInstaller.php  
  1. abstract class BaseInstaller 
  2. protected $locations = array(); 
  3. protected $composer; 
  4. protected $package; 
  5. protected $io; 
  6.  
  7. /** 
  8. * Initializes base installer. 
  9. * @param PackageInterface $package 
  10. * @param Composer $composer 
  11. * @param IOInterface $io 
  12. */ 
  13. public function __construct(PackageInterface $package = null, Composer $composer = null, IOInterface $io = null) 
  14. $this->composer = $composer; 
  15. $this->package = $package; 
  16. $this->io = $io; 
  17.  
  18. /** 
  19. * Return the install path based on package type. 
  20. * @param PackageInterface $package 
  21. * @param string $frameworkType 
  22. * @return string 
  23. */ 
  24. public function getInstallPath(PackageInterface $package, $frameworkType = '') 
  25. $type = $this->package->getType(); 
  26.  
  27. $prettyName = $this->package->getPrettyName(); 
  28. if (strpos($prettyName, '/') !== false) { 
  29. list($vendor, $name) = explode('/', $prettyName); 
  30. } else { 
  31. $vendor = ''; 
  32. $name = $prettyName; 
  33.  
  34. $availableVars = $this->inflectPackageVars(compact('name', 'vendor', 'type')); 
  35.  
  36. $extra = $package->getExtra(); 
  37. if (!empty($extra['installer-name'])) { 
  38. $availableVars['name'] = $extra['installer-name']; 
  39.  
  40. if ($this->composer->getPackage()) { 
  41. $extra = $this->composer->getPackage()->getExtra(); 
  42. if (!empty($extra['installer-paths'])) { 
  43. $customPath = $this->mapCustomInstallPaths($extra['installer-paths'], $prettyName, $type, $vendor); 
  44. if ($customPath !== false) { 
  45. return $this->templatePath($customPath, $availableVars); 
  46.  
  47. $packageType = substr($type, strlen($frameworkType) + 1); 
  48. $locations = $this->getLocations(); 
  49. if (!isset($locations[$packageType])) { 
  50. throw new \InvalidArgumentException(sprintf('Package type "%s" is not supported', $type)); 
  51.  
  52. return $this->templatePath($locations[$packageType], $availableVars); 
  53.  
  54. /** 
  55. * For an installer to override to modify the vars per installer. 
  56. * @param array $vars 
  57. * @return array 
  58. */ 
  59. public function inflectPackageVars($vars) 
  60. return $vars; 
  61.  
  62. /** 
  63. * Gets the installer's locations 
  64. * @return array 
  65. */ 
  66. public function getLocations() 
  67. return $this->locations; 
  68.  
  69. /** 
  70. * Replace vars in a path 
  71. * @param string $path 
  72. * @param array $vars 
  73. * @return string 
  74. */ 
  75. protected function templatePath($path, array $vars = array()) 
  76. if (strpos($path, '{') !== false) { 
  77. extract($vars); 
  78. preg_match_all('@\{\$([A-Za-z0-9_]*)\}@i', $path, $matches); 
  79. if (!empty($matches[1])) { 
  80. foreach ($matches[1] as $var) { 
  81. $path = str_replace('{$' . $var . '}', $$var, $path); 
  82.  
  83. return $path; 
  84.  
  85. /** 
  86. * Search through a passed paths array for a custom install path. 
  87. * @param array $paths 
  88. * @param string $name 
  89. * @param string $type 
  90. * @param string $vendor = NULL 
  91. * @return string 
  92. */ 
  93. protected function mapCustomInstallPaths(array $paths, $name, $type, $vendor = NULL) 
  94. foreach ($paths as $path => $names) { 
  95. if (in_array($name, $names) || in_array('type:' . $type, $names) || in_array('vendor:' . $vendor, $names)) { 
  96. return $path; 
  97.  
  98. return false;