Skip to content

Commit

Permalink
feat: allow adding self aliases
Browse files Browse the repository at this point in the history
  • Loading branch information
Mohammad-Alavi committed Jan 3, 2025
1 parent 98861d0 commit 7aa4b55
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 15 deletions.
32 changes: 18 additions & 14 deletions src/Foundation/Providers/ApiatoServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Apiato\Commands\SeedDeploymentData;
use Apiato\Commands\SeedTestingData;
use Apiato\Foundation\Apiato;
use Apiato\Foundation\DatabaseSeeder;
use Apiato\Foundation\Loaders\HelperLoader;
use Apiato\Foundation\Loaders\Loader;
use Apiato\Foundation\Support\PathHelper;
Expand All @@ -17,6 +18,7 @@
use Apiato\Generator\GeneratorsServiceProvider;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Foundation\AliasLoader;
use Illuminate\Foundation\Console\AboutCommand;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\File;
Expand All @@ -34,6 +36,10 @@ class ApiatoServiceProvider extends AggregateServiceProvider
MigrationServiceProvider::class,
];

protected array $aliases = [
'DatabaseSeeder' => DatabaseSeeder::class,
];

public function register(): void
{
$this->providers = $this->mergeProviders($this->providers, $this->serviceProviders());
Expand Down Expand Up @@ -112,9 +118,12 @@ private function setUpTestProviders(Application $app): void

public function boot(): void
{
$this->addAliases();
$this->runBoot();

$this->runLoaders();
$this->load(
HelperLoader::create(),
);

$this->publishes([
__DIR__ . '/../../../config/apiato.php' => app_path('Ship/Configs/apiato.php'),
Expand All @@ -125,19 +134,6 @@ public function boot(): void
AboutCommand::add('Apiato', static fn () => ['Version' => '13.0.0']);
}

public function runLoaders(): void
{
$this->load(
HelperLoader::create(),
);

// $this->loadShipMigrations();

foreach (PathHelper::getContainerPaths() as $containerPath) {
// $this->loadContainerMigrations($containerPath);
}
}

private function load(Loader ...$loader): void
{
foreach ($loader as $load) {
Expand All @@ -159,4 +155,12 @@ static function (Request $request) {
);
}
}

private function addAliases(): void
{
$loader = AliasLoader::getInstance();
foreach ($this->aliases as $alias => $class) {
$loader->alias($alias, $class);
}
}
}
15 changes: 14 additions & 1 deletion tests/Functional/Providers/ApiatoServiceProviderTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use Apiato\Foundation\DatabaseSeeder;
use Apiato\Foundation\Providers\ApiatoServiceProvider;
use Apiato\Foundation\Providers\MacroServiceProvider;
use Apiato\Foundation\Support\Providers\LocalizationServiceProvider;
Expand Down Expand Up @@ -52,7 +53,19 @@
$availableAliases = AliasLoader::getInstance()->getAliases();

foreach ($aliases as $alias => $class) {
expect($availableAliases[$alias])->toBe($class);
expect($availableAliases)->toHaveKey($alias, $class);
}
});

it('can add its own aliases', function (): void {
$aliases = [
'DatabaseSeeder' => DatabaseSeeder::class,
];

$availableAliases = AliasLoader::getInstance()->getAliases();

foreach ($aliases as $alias => $class) {
expect($availableAliases)->toHaveKey($alias, $class);
}
});

Expand Down

0 comments on commit 7aa4b55

Please sign in to comment.