Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class NewanceCMSValetDriver extends ValetDriver
- {
- public function configure($devtools, $url)
- {
- $sitePath = getcwd();
- $dirName = $devtools->mysql->getDirName();
- //Fix Newance CMS to work with domain .test
- info('Fix src/index.php to work .test domain');
- $find = 'if (substr($_SERVER[\'HTTP_HOST\'], 0, 6) == "local.") {';
- $replace = 'if (substr($_SERVER[\'HTTP_HOST\'], 0, 6) == "local." || substr($_SERVER[\'HTTP_HOST\'], -5) == ".test") {';
- $indexPhp = $sitePath.'/src/index.php';
- file_put_contents(
- $indexPhp,
- str_replace($find, $replace, file_get_contents($indexPhp))
- );
- //Set correct database credentials
- info('Fix src/config/config.xml to work database user');
- $configXml = $sitePath.'/src/config/config.xml';
- $xml = simplexml_load_file($configXml);
- $xml->databases->local->site->database = $dirName;
- $xml->databases->local->site->user = 'root';
- $xml->databases->local->site->pass = 'root';
- $xml->databases->local->cms->database = $dirName;
- $xml->databases->local->cms->user = 'root';
- $xml->databases->local->cms->pass = 'root';
- $xml->asXml($configXml);
- //Download database from online to database.sql file
- //Drop database, create database en import database from SQL folder
- info('Drop, create & import database from SQL folder');
- $devtools->mysql->reimportDatabase($sitePath.'/sql/database.sql', $dirName);
- //Install packages (composer)
- info('Composer install');
- $devtools->cli->quietlyAsUser('composer install -d '.$sitePath.'/src');
- //Open in browser when done
- $devtools->cli->quietlyAsUser('valet open');
- }
- /**
- * Determine if the driver serves the request.
- *
- * @param string $sitePath
- * @param string $siteName
- * @param string $uri
- * @return bool
- */
- public function serves($sitePath, $siteName, $uri)
- {
- if (file_exists($sitePath.'/fabricrc')) {
- return true;
- }
- return false;
- }
- /**
- * Determine if the incoming request is for a static file.
- *
- * @param string $sitePath
- * @param string $siteName
- * @param string $uri
- * @return string|false
- */
- public function isStaticFile($sitePath, $siteName, $uri)
- {
- if ($uri == '/cms') {
- return false;
- }
- if (file_exists($staticFilePath = $sitePath.'/src/'.$uri)) {
- return $staticFilePath;
- }
- return false;
- }
- /**
- * Get the fully resolved path to the application's front controller.
- *
- * @param string $sitePath
- * @param string $siteName
- * @param string $uri
- * @return string
- */
- public function frontControllerPath($sitePath, $siteName, $uri)
- {
- return $sitePath.'/src/index.php';
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement