Guest User

Untitled

a guest
Apr 24th, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.89 KB | None | 0 0
  1. <?php
  2. /*
  3. * Magento 1 Valet Driver
  4. * @author spinsch
  5. * @path ~/.valet/Drivers/Magento1ValetDriver.php
  6. */
  7. class Magento1ValetDriver extends ValetDriver
  8. {
  9. private $siteSubFolder = 'htdocs';
  10.  
  11. /**
  12. * Determine if the driver serves the request.
  13. *
  14. * @param string $sitePath
  15. * @param string $siteName
  16. * @param string $uri
  17. * @return bool
  18. */
  19. public function serves($sitePath, $siteName, $uri)
  20. {
  21. return file_exists($this->getFullSitePath($sitePath, '/js/mage/translate.js'));
  22. }
  23. /**
  24. * Determine if the incoming request is for a static file.
  25. *
  26. * @param string $sitePath
  27. * @param string $siteName
  28. * @param string $uri
  29. * @return string|false
  30. */
  31. public function isStaticFile($sitePath, $siteName, $uri)
  32. {
  33. $sitePath = $this->getFullSitePath($sitePath);
  34.  
  35. if ($this->isActualFile($staticFilePath = $sitePath.$uri)) {
  36. return $staticFilePath;
  37. }
  38.  
  39. return false;
  40. }
  41.  
  42. /**
  43. * Get the fully resolved path to the application's front controller.
  44. *
  45. * @param string $sitePath
  46. * @param string $siteName
  47. * @param string $uri
  48. * @return string
  49. */
  50. public function frontControllerPath($sitePath, $siteName, $uri)
  51. {
  52. $sitePath = $this->getFullSitePath($sitePath);
  53.  
  54. // api request
  55. if (substr($uri, 1, 8) == 'api/rest') {
  56. $_GET['type'] = 'rest';
  57. return $sitePath.'/api.php';
  58. }
  59. // default request
  60. $dynamicCandidates = [
  61. $this->asActualFile($sitePath, $uri),
  62. $this->asPhpIndexFileInDirectory($sitePath, $uri),
  63. $this->asHtmlIndexFileInDirectory($sitePath, $uri),
  64. ];
  65. foreach ($dynamicCandidates as $candidate) {
  66. if ($this->isActualFile($candidate)) {
  67. $_SERVER['SCRIPT_FILENAME'] = $candidate;
  68. $_SERVER['SCRIPT_NAME'] = str_replace($sitePath, '', $candidate);
  69. $_SERVER['DOCUMENT_ROOT'] = $sitePath;
  70. return $candidate;
  71. }
  72. }
  73.  
  74. $candidate = $this->asRootPhpIndexFile($sitePath);
  75.  
  76. if ($this->isActualFile($candidate)) {
  77. $_SERVER['SCRIPT_FILENAME'] = $candidate;
  78. $_SERVER['SCRIPT_NAME'] = '/index.php';
  79. $_SERVER['DOCUMENT_ROOT'] = $sitePath;
  80. return $candidate;
  81. }
  82.  
  83. }
  84.  
  85. /**
  86. * Concatenate the site path and URI as a single file name.
  87. *
  88. * @param string $sitePath
  89. * @param string $uri
  90. * @return string
  91. */
  92. protected function asActualFile($sitePath, $uri)
  93. {
  94. return $sitePath.$uri;
  95. }
  96.  
  97. /**
  98. * Format the site path and URI with a trailing "index.php".
  99. *
  100. * @param string $sitePath
  101. * @param string $uri
  102. * @return string
  103. */
  104. protected function asPhpIndexFileInDirectory($sitePath, $uri)
  105. {
  106. return $sitePath.rtrim($uri, '/').'/index.php';
  107. }
  108.  
  109. /**
  110. * Format the site path and URI with a trailing "index.html".
  111. *
  112. * @param string $sitePath
  113. * @param string $uri
  114. * @return string
  115. */
  116. protected function asHtmlIndexFileInDirectory($sitePath, $uri)
  117. {
  118. return $sitePath.rtrim($uri, '/').'/index.html';
  119. }
  120.  
  121. /**
  122. * Format the incoming site path as root "index.php" file path.
  123. *
  124. * @param string $sitePath
  125. * @return string
  126. */
  127. protected function asRootPhpIndexFile($sitePath)
  128. {
  129. return $sitePath.'/index.php';
  130. }
  131.  
  132. /**
  133. * Get the full site path including sub folder.
  134. *
  135. * @param string $sitePath
  136. * @param string $uri
  137. * @return string
  138. */
  139. protected function getFullSitePath($sitePath, $path = null)
  140. {
  141. $fullPath = rtrim($sitePath, '/').'/'.$this->siteSubFolder;
  142.  
  143. if ($path !== null) {
  144. $fullPath .= '/'.rtrim($path, '/');
  145. }
  146.  
  147. return $fullPath;
  148. }
  149. }
Add Comment
Please, Sign In to add comment