Skip to content

Commit

Permalink
Making laravel commands available
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelfolaron committed Jul 25, 2024
1 parent 422e19f commit c84d0ff
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 6 deletions.
31 changes: 31 additions & 0 deletions app/Core/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,20 @@ class Application extends Container
*/
protected $booted = false;

/**
* The array of booting callbacks.
*
* @var callable[]
*/
protected $bootingCallbacks = [];

/**
* The array of booted callbacks.
*
* @var callable[]
*/
protected $bootedCallbacks = [];

/**
* Constructor method for the class.
*
Expand All @@ -81,6 +95,8 @@ public function __construct()
Facade::setFacadeApplication($this);

Events::discover_listeners();

$this->boot();
}
/**
* Check if application has been bootstrapped
Expand Down Expand Up @@ -191,6 +207,8 @@ private function registerCoreAliases(): void
$this->alias(HttpKernel::class, HttpKernelContract::class);

$this->alias(\Illuminate\Encryption\Encrypter::class, "encrypter");

$this->alias(\Leantime\Core\Events::class, 'events');
}

/**
Expand Down Expand Up @@ -654,6 +672,10 @@ protected function fireAppCallbacks(array &$callbacks)
}
}

public function runningUnitTests() {
return false;
}

/**
* Flush the container of all bindings and resolved instances.
*
Expand All @@ -678,4 +700,13 @@ public function flush()
$this->globalResolvingCallbacks = [];
$this->globalAfterResolvingCallbacks = [];
}

public function storagePath($path) {

if($path == "framework/cache") {
$path = "cache";
}

return APP_ROOT."/".$path;
}
}
13 changes: 12 additions & 1 deletion app/Core/ConsoleKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public function getArtisan(): ConsoleApplicationContract|ConsoleApplication
{
app()->alias(\Illuminate\Console\Application::class, ConsoleApplicationContract::class);
app()->alias(\Illuminate\Console\Application::class, ConsoleApplication::class);

return $this->artisan ??= app()->instance(\Illuminate\Console\Application::class, new class extends ConsoleApplication implements ConsoleApplicationContract
{
/**
Expand Down Expand Up @@ -124,6 +125,7 @@ protected function commands()

$customCommands = $customPluginCommands = null;


session(["commands.core" => collect(glob(APP_ROOT . '/app/Command/*.php') ?? [])
->filter(function ($command) use (&$customCommands) {
return ! Arr::has(
Expand Down Expand Up @@ -155,16 +157,25 @@ protected function commands()
*
* @var LaravelCommand[]|SymfonyCommand[] $additionalCommands
**/
$glob = glob(APP_ROOT . '/vendor/illuminate/*/Console/*.php');
$laravelCommands = collect($glob)->map(function ($command) {
$path = Str::replace(APP_ROOT."/vendor/illuminate/", "", $command);
$cleanPath = ucfirst(Str::replace(['/', '.php'], ['\\', ''], $path));
return "Illuminate\\".$cleanPath;
});
session(["commands.laravel" => $laravelCommands]);

$additionalCommands = self::dispatch_filter('additional_commands', [
\Illuminate\Console\Scheduling\ScheduleRunCommand::class,
\Illuminate\Console\Scheduling\ScheduleFinishCommand::class,
\Illuminate\Console\Scheduling\ScheduleListCommand::class,
\Illuminate\Console\Scheduling\ScheduleTestCommand::class,
\Illuminate\Console\Scheduling\ScheduleWorkCommand::class,
\Illuminate\Console\Scheduling\ScheduleClearCacheCommand::class,
\Illuminate\Cache\Console\ClearCommand::class,
]);

$commands = collect($commands)->concat($laravelCommands);

collect($commands)->concat($additionalCommands)
->each(function ($command) {
if (
Expand Down
8 changes: 8 additions & 0 deletions app/Core/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,14 @@ public static function dispatch_event(
self::executeHandlers($matchedEvents, "events", $eventName, $payload);
}

public function dispatch(
string $eventName,
mixed $payload = [],
string $context = ''
) {
$this->dispatch_event($eventName, $payload, $context);
}


/**
* Finds event listeners by event names,
Expand Down
6 changes: 3 additions & 3 deletions app/Core/Providers/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,20 @@ function () use ($instanceStore) {

return $cacheManager;
});


$this->app->singleton('cache.store', fn ($app) => $app['cache']->driver());
$this->app->singleton('cache.psr6', fn ($app) => new \Symfony\Component\Cache\Adapter\Psr16Adapter($app['cache.store']));
$this->app->singleton('memcached.connector', fn () => new MemcachedConnector());


$this->app->alias(\Illuminate\Cache\CacheManager::class, 'cache');
$this->app->alias(\Illuminate\Cache\CacheManager::class, \Illuminate\Contracts\Cache\Factory::class);


}

public function boot() {



$currentVersion = $this->app->make(AppSettings::class)->appVersion;
$cachedVersion = \Illuminate\Support\Facades\Cache::store('installation')->rememberForever('version', fn () => $currentVersion);

Expand Down
4 changes: 2 additions & 2 deletions app/Core/Providers/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ public function register()

$this->app->alias(\Leantime\Core\Environment::class, 'config');
$this->app->alias(\Leantime\Core\Environment::class, \Illuminate\Contracts\Config\Repository::class);

}

public function boot() {


$this->app->make(\Leantime\Core\AppSettings::class)->loadSettings();

$config = $this->app->make(\Leantime\Core\AppSettings::class);


$this->setErrorHandler($config->debug ?? 0);

self::dispatch_event('config_initialized');
Expand Down
1 change: 1 addition & 0 deletions app/Domain/Cron/Controllers/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public function run(): Response
/** @return never **/
(new \Leantime\Core\ConsoleKernel())->call('schedule:run', [], $output);


});

return tap(new Response(), function ($response) {
Expand Down
8 changes: 8 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -333,3 +333,11 @@ function session($key = null, $default = null)
}

}

if (! function_exists('storage_path')) {
function storage_path($path = '')
{
return app()->storagePath($path);
}

}

0 comments on commit c84d0ff

Please sign in to comment.