Created
May 14, 2016 10:09
-
-
Save dblencowe/07187b8ce6da775528ca7b855906be31 to your computer and use it in GitHub Desktop.
Anchor CMS driver for Valet from Laravel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class AnchorCmsValetDriver extends ValetDriver | |
{ | |
/** | |
* Determine if the driver serves the request. | |
* | |
* @param string $sitePath | |
* @param string $siteName | |
* @param string $uri | |
* @return void | |
*/ | |
public function serves($sitePath, $siteName, $uri) | |
{ | |
return is_dir($sitePath . '/anchor'); | |
} | |
/** | |
* 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 (self::isInstalling($sitePath)) { | |
if (file_exists($sitePath . '/install' . $uri)) { | |
return $sitePath . '/install' . $uri; | |
} | |
} | |
if (file_exists($staticFilePath = $sitePath . $uri)) { | |
return $staticFilePath; | |
} | |
if (file_exists($sitePath . '/anchor' . $uri)) { | |
return $sitePath . '/anchor' . $uri; | |
} | |
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) | |
{ | |
if (self::isInstalling($sitePath)) { | |
return $sitePath . '/install/index.php'; | |
} | |
if (file_exists($sitePath . $uri)) { | |
return $sitePath . $uri; | |
} | |
return $sitePath . '/index.php'; | |
} | |
/** | |
* Check if anchor has been installed or not | |
* @param string $sitePath | |
* @return boolean | |
*/ | |
private function isInstalling($sitePath) | |
{ | |
if (!file_exists($sitePath . '/anchor/config/db.php')) { | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment