d||ell

Laravel Valet Driver For AbanteCart

November 25, 2016 · ☕️ 2 min read

So today I’ve stumbled myself working with AbanteCart on my dev machine running El Capitan OS X. I’ve been using Laravel Valet since it was initially released due to how it made things so easy on my end. If you’re working on a WordPress site and other PHP-based apps, I encourage you to check it out and spend a good 20 minutes to get it up and running. I promise, it’ll make your lives easier as a developer.

But hey, let’s go back. I got halted by the fact that I need to run AbanteCart – an opensource eCommerce platform that’s really promising as well. Anyhow, let’s cut the chase, valet doesn’t support AbanteCart out of the box and I was left with no choice but to make things work.

Fast forward minutes later, I have finally created a custom driver for AbanteCart and if you’re on the same boat like me, you can use my work below to save time and don’t bother yourself tinkering and tinkering and end up worst wasting your time.

Here’s a link to the gist that you can grab at GitHub.

Alternatively, without going to link above, just copy and paste code below:

<?php

class AbanteCartValetDriver 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)
    {
        if (file_exists($sitePath.'/public_html/index.php')) {
            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 (file_exists($staticFilePath = $sitePath.'/public_html/'.$uri)) {
            return $staticFilePath;
        }
        if (file_exists($staticFilePath = $sitePath.'/public_html/install/'.$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)
    {
        $_SERVER['PHP_SELF'] = $uri;
        if ($uri == '/')
            return $sitePath.'/public_html/index.php';

        return strpos($uri, '.php') ? $sitePath.'/public_html/'.$uri : $sitePath.'/public_html/'.$uri.'.php';
    }
}

And oh before I forgot, just save this file to ~/.valet/Drivers in your machine.

Enjoy, hope that helps!


@dorelljames

Personal blog by @dorelljames
I love you and coding!

Let me know your thoughts... 😊

What's next?

Continue reading articles using the links below...

Copyright © 2023,d||ell. Built with Gatsby. Source on GitHub.