Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.01 KB | None | 0 0
  1. <?php
  2.  
  3. class NewanceCMSValetDriver extends ValetDriver
  4. {
  5. public function configure($devtools, $url)
  6. {
  7. $sitePath = getcwd();
  8. $dirName = $devtools->mysql->getDirName();
  9.  
  10. //Fix Newance CMS to work with domain .test
  11. info('Fix src/index.php to work .test domain');
  12. $find = 'if (substr($_SERVER[\'HTTP_HOST\'], 0, 6) == "local.") {';
  13. $replace = 'if (substr($_SERVER[\'HTTP_HOST\'], 0, 6) == "local." || substr($_SERVER[\'HTTP_HOST\'], -5) == ".test") {';
  14. $indexPhp = $sitePath.'/src/index.php';
  15. file_put_contents(
  16. $indexPhp,
  17. str_replace($find, $replace, file_get_contents($indexPhp))
  18. );
  19.  
  20. //Set correct database credentials
  21. info('Fix src/config/config.xml to work database user');
  22. $configXml = $sitePath.'/src/config/config.xml';
  23. $xml = simplexml_load_file($configXml);
  24. $xml->databases->local->site->database = $dirName;
  25. $xml->databases->local->site->user = 'root';
  26. $xml->databases->local->site->pass = 'root';
  27. $xml->databases->local->cms->database = $dirName;
  28. $xml->databases->local->cms->user = 'root';
  29. $xml->databases->local->cms->pass = 'root';
  30. $xml->asXml($configXml);
  31.  
  32. //Download database from online to database.sql file
  33.  
  34. //Drop database, create database en import database from SQL folder
  35. info('Drop, create & import database from SQL folder');
  36. $devtools->mysql->reimportDatabase($sitePath.'/sql/database.sql', $dirName);
  37.  
  38. //Install packages (composer)
  39. info('Composer install');
  40. $devtools->cli->quietlyAsUser('composer install -d '.$sitePath.'/src');
  41.  
  42. //Open in browser when done
  43. $devtools->cli->quietlyAsUser('valet open');
  44. }
  45.  
  46. /**
  47. * Determine if the driver serves the request.
  48. *
  49. * @param string $sitePath
  50. * @param string $siteName
  51. * @param string $uri
  52. * @return bool
  53. */
  54. public function serves($sitePath, $siteName, $uri)
  55. {
  56. if (file_exists($sitePath.'/fabricrc')) {
  57. return true;
  58. }
  59.  
  60. return false;
  61. }
  62.  
  63. /**
  64. * Determine if the incoming request is for a static file.
  65. *
  66. * @param string $sitePath
  67. * @param string $siteName
  68. * @param string $uri
  69. * @return string|false
  70. */
  71. public function isStaticFile($sitePath, $siteName, $uri)
  72. {
  73. if ($uri == '/cms') {
  74. return false;
  75. }
  76.  
  77. if (file_exists($staticFilePath = $sitePath.'/src/'.$uri)) {
  78. return $staticFilePath;
  79. }
  80.  
  81. return false;
  82. }
  83.  
  84. /**
  85. * Get the fully resolved path to the application's front controller.
  86. *
  87. * @param string $sitePath
  88. * @param string $siteName
  89. * @param string $uri
  90. * @return string
  91. */
  92. public function frontControllerPath($sitePath, $siteName, $uri)
  93. {
  94. return $sitePath.'/src/index.php';
  95. }
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement