laradumps / laradumps-core

🛻 LaraDumps Core is a friendly app designed to boost you PHP coding and debugging experience.

Home Page:https://laradumps.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

rewrite appBasePath function

emanuellopes opened this issue · comments

Hi, I'm trying create a new package to support wordpress functionalities, but I've some issues with the laradumps/laradumps-core package.

On Wordpress the function appBasepath, can have the following values:

  • /var/www/html
  • /var/www/html/wp-admin

With this issue I need to update the code manually and change the .env config directory to avoid duplicate file for both folders.

I started a package but I'm unable to override this function on my package.

if (!function_exists('appBasePath')) {
    function appBasePath(): string
    {
        $basePath = rtrim(strval(getcwd()), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;

        if (str_contains($basePath, 'public')) {
            $basePath = str_replace('public' . DIRECTORY_SEPARATOR, '', $basePath);
        }

        return $basePath;
    }
}

My idea is replacing that function by this:

function appBasePath(): string
    {
       // this will allow developers, choose where the .env will stay.
        return apply_filters('wordpressdumps/appBasePath', get_stylesheet_directory());
    }

I've a solution, but is not perfect...

for example in your function, you can use something like

function appBasePath(): string
{
    $basePath = rtrim(strval(getcwd()), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;

    if(file_exists($basePath . '/.env')) {
        return $basePath;
    }

    // upp one level
    $basePath = rtrim(dirname(getcwd()), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;

    if(file_exists($basePath . '/.env')) {
        return $basePath;
    }

    // upp two level
    return rtrim(dirname(getcwd(), 2), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
}

or moving the function appBasePath to Laradump class and in there place I will be able to override that function extending your base class.

Hello @emanuellopes. Could you send a pull request to update the function? The core idea is exactly to create forks for other types of frameworks and take advantage of some existing resources. thank you

My modifications to update our function I guess will not support everything.

I guess we need a third package, like laradumps-core, but without any global function, and the appConfigFile should be refactored to support change the directory, maybe here we can use an env var and the developer can set the variable in docker-composer.yml or in other place.

But the best solution is removing the global functions, this will allow developers use your payloads and some feature from base package.

I don't want to submit a big PR because my issue on wordpress, but If you can create a new package with everything from laradumps-core, but without having global functions related with appConfigFile, will be great.

Sorry for the delay here. LaraDumps Core was recently refactored in version 2.0, if you're still willing to submit a PR, I'd be grateful.

Thanks