ComposerInstallersBaseInstaller

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