Giter Site home page Giter Site logo

Comments (10)

mattstauffer avatar mattstauffer commented on August 15, 2024 1

Thanks for this @aerni!

@jasonvarga If we were to publish a Statamic v3 driver, is this the correct code to use? If so, do you want to make the PR so it's attributed to you? If not, I'll just create the PR and attribute you as co-author.

from valet.

aerni avatar aerni commented on August 15, 2024

@mattstauffer Some more thoughts I had.

The driver should probably just be called StatamicValetDriver as there isn't any difference between Statamic v3, Statamic v4, and any future releases. Statamic has been a Laravel package since v3.

You might also want the driver to override the serves() method so that Valet will only use this driver when Statamic is installed. Otherwise, the StatamicValetDriver will always be used in favor of the LaravelValetDriver.

A Statamic app will have a please file:

public function serves(string $sitePath, string $siteName, string $uri): bool
{
    return file_exists($sitePath.'/public/index.php') &&
           file_exists($sitePath.'/please');
}

from valet.

jasonvarga avatar jasonvarga commented on August 15, 2024

I'm happy to make the PR, but the problem I'm running into is that the Laravel Driver's serves method will return true before the Statamic specific driver gets a chance to run. Statamic 3+ sites are literally just Laravel sites, so the Laravel driver picks it up.

// Queue Valet-shipped drivers
$drivers[] = 'LaravelValetDriver';
$drivers = array_merge($drivers, $specificDrivers);
$drivers[] = 'BasicWithPublicValetDriver';
$drivers[] = 'BasicValetDriver';
foreach ($drivers as $driver) {

I understand that you probably have the Laravel driver in the array before the specific ones so that Laravel sites will get recognized quickly, without having to loop through all customer drivers first.

from valet.

mattstauffer avatar mattstauffer commented on August 15, 2024

@jasonvarga Apologies, I just saw this. This is interesting, and I'm not exactly sure how to address it. I'm trying to figure out if there's any other reason I put Laravel's driver up at the top, and I'm a bit tempted to just allow it to live in with the other drivers, or to put Statamic up above Laravel manually. If we did that, I assume it would solve the problem for Statamic?

from valet.

drbyte avatar drbyte commented on August 15, 2024

@mattstauffer I think moving anything above/before the Laravel driver is gonna cause it to fail to load if it extends the Laravel driver.

Instead I think the solution is to extract the call to if($driver->serves....) into a separate loop that first loops through Custom drivers, then Specific drivers, then Laravel driver, then basic driver, basically in a reverse cascade of the original loop. First loop identifies and instantiates available drivers, second loop goes semi-backwards through it, falling back to Laravel then Basic if no local/custom/specific (in that order) pass the serves() test.

EDIT: I was wrong. The require_drivers.php takes care of loading those essentials first.

from valet.

jasonvarga avatar jasonvarga commented on August 15, 2024

I think if you swap these two lines, you'll be sorted.

$drivers[] = 'LaravelValetDriver';
$drivers = array_merge($drivers, $specificDrivers);

The downside being that if you are hitting a Laravel site, you end up looping through the serves (and mutateUri) method on all the specific drivers first. Maybe that slows things down. 🤷 Maybe not a big deal though, since they are mostly just file_exists() checks.

or to put Statamic up above Laravel manually

That'll solve the issue for Statamic, but it'll remain for anyone with a Laravel site trying to use a custom driver. (Looks like there aren't any in Valet itself, but people could have custom ones in ~/.config/valet/Drivers.) Also I don't know if people will appreciate Statamic-specific code there. 😊

from valet.

mattstauffer avatar mattstauffer commented on August 15, 2024

Yah, I know I put Laravel first for a reason when I was re-writing, so I don't want to break that. I think custom putting Statamic above there is fine. I don't really care if anyone doesn't like it, there's a perfectly good explanation. :) If they want to build their CMSes on top of Laravel and then they need something custom, they can come talk to me then.

from valet.

jasonvarga avatar jasonvarga commented on August 15, 2024

Alrighty I'll put together the PR then. Thanks!

from valet.

drbyte avatar drbyte commented on August 15, 2024

After some further digging, and after correcting my simulation that I was testing with, I agree with the proposed change.

from valet.

mattstauffer avatar mattstauffer commented on August 15, 2024

Thanks both!

from valet.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.