Skip to content

Libs not automatically loaded in sprout commands #328

Description

@patrickvuarnoz

I'm re-issuing this issue as it was not picked up (maybe not seen) in the leafsphp/sprout repository. It's about the following issue: leafsphp/sprout#4

In Aloe /libs were automatically loaded. Now in Sprout they aren't. The loadConsole() in the MVC Core does call static::loadApplicationConfig() but there it excludes the libs from being loaded when called via CLI:

    public static function loadApplicationConfig()
    {
        static::loadConfig();

        \Leaf\Database::initDb();

        if (php_sapi_name() !== 'cli') {
            if (class_exists('Leaf\Vite')) {
                \Leaf\Vite::config('assets', PublicPath('build'));
                \Leaf\Vite::config('build', 'public/build');
                \Leaf\Vite::config('hotFile', 'public/hot');
            }

            if (storage()->exists(LibPath())) {
                static::loadLibs();
            }

            if (storage()->exists('app/index.php')) {
                require 'app/index.php';
            }
        }
    }

In Aloe, /lib was automatically loaded in Command::execute(). Maybe the easiest way would be to always load libs in loadApplicationConfig():

    public static function loadApplicationConfig()
    {
        static::loadConfig();

        \Leaf\Database::initDb();

        if (storage()->exists(LibPath())) {
            static::loadLibs();
        }

        if (php_sapi_name() !== 'cli') {
            if (class_exists('Leaf\Vite')) {
                \Leaf\Vite::config('assets', PublicPath('build'));
                \Leaf\Vite::config('build', 'public/build');
                \Leaf\Vite::config('hotFile', 'public/hot');
            }

            if (storage()->exists('app/index.php')) {
                require 'app/index.php';
            }
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions