Skip to content

Commit

Permalink
Version 2 rewrite: Valet 4 compat, add install script
Browse files Browse the repository at this point in the history
  • Loading branch information
aj-adl committed Jun 9, 2023
1 parent 0fce5d1 commit f714be0
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
.DS_Store
12 changes: 8 additions & 4 deletions FrameWordpressValetDriver.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

class FrameWordPressValetDriver extends BasicValetDriver
namespace Valet\Drivers\Custom;

use Valet\Drivers\ValetDriver;

class FrameWordPressValetDriver extends ValetDriver
{

public $wp_root = 'wordpress';
Expand All @@ -15,7 +19,7 @@ class FrameWordPressValetDriver extends BasicValetDriver
* @param string $uri
* @return bool
*/
public function serves($sitePath, $siteName, $uri)
public function serves(string $sitePath, string $siteName, string $uri): bool
{
if (file_exists($sitePath.'/site/wp-config.php') || file_exists($sitePath.'/site/wp-config-sample.php'))
{
Expand Down Expand Up @@ -46,7 +50,7 @@ public function serves($sitePath, $siteName, $uri)
* @param string $uri
* @return string
*/
public function frontControllerPath($sitePath, $siteName, $uri)
public function frontControllerPath(string $sitePath, string $siteName, string $uri): string
{

if ( $this->debug ){
Expand Down Expand Up @@ -176,7 +180,7 @@ private function forceTrailingSlash($uri)
}


public function isStaticFile($sitePath, $siteName, $uri)
public function isStaticFile(string $sitePath, string $siteName, string $uri)/*: string|false */
{
$sitePath = $sitePath . $this->public_dir;
// If the URI contains one of the main WordPress directories and it doesn't end with a slash,
Expand Down
36 changes: 35 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,38 @@ A custom upgraded Valet driver that handles the unique structure of Frame's proj

This driver allows you to run `valet link` in the project root folder, rather than having to link from the `site` or `dist` folder - this makes valet work better overall, and commands such as `valet isolate`, `valet php` and `valet composer` will work with less complications whe the Valet site root is set as the root folder of the project.

To enable, copy or symlink into the `~/.config/valet/Drivers/` folder.
## Installation ##

Clone this repo to your local machine - this will allow for easy updates to be published in the future;

```shell
git clone https://github.com/framecreative/frame-valet-drivers.git
```

Run the installation script on the cli, this will remove any old version of this specific driver, and create a symlink from valet's config to the driver in this repo.

```shell
php install.php
```

## Updates ##

By utilising the symlink method above, updating is as simple as pulling changes from github.

```shell
git pull origin master
```

## Changelog ##

### Version 1.0.0 ###
- Initial release
- Move to github vs sharing the file in team slack
- Compatible with Valet 2.x, works with Valet 3.x with minor issues

### Version 2.0.0 ###
- Updates to support valet 4.x releases
- Added installation script for easier setup
- Requires PHP 7+ (standard)
- Supports 3.x and 4.x versions of Valet - Valet 1.x and 2.x support is deprecated

27 changes: 27 additions & 0 deletions install.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#!/usr/local/bin/php
<?php

$home = getenv('HOME');
$path = dirname(__FILE__);
$driverFile = 'FrameWordPressValetDriver.php';
$valetDriverPath = $home . DIRECTORY_SEPARATOR . '.config' . DIRECTORY_SEPARATOR . 'valet' .DIRECTORY_SEPARATOR . 'Drivers';
$targetDriverFullPath = $path . DIRECTORY_SEPARATOR . $driverFile;
$valetDriverFullPath = $valetDriverPath . DIRECTORY_SEPARATOR . $driverFile;

if ( file_exists( $valetDriverFullPath ) or is_link( $valetDriverFullPath ) ){
echo 'Driver already exists, removing' . PHP_EOL;
unlink( $valetDriverFullPath );
}

echo 'Creating symlink to driver...' . PHP_EOL;
symlink( $targetDriverFullPath, $valetDriverFullPath );
$link = readlink( $valetDriverFullPath ) . PHP_EOL;
if ( !$link ){
echo "Error creating link: readlink() returned " . $link . PHP_EOL;
return 1;
}

echo "Success! Symbolic link created" . PHP_EOL;
echo $targetDriverFullPath . ' -> ' . $valetDriverFullPath . PHP_EOL;

echo PHP_EOL . 'Install completed. To update the driver just run "git pull origin master" in this repo';

0 comments on commit f714be0

Please sign in to comment.