mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 12:44:02 +00:00
[3.x] Add Vite helper for tenancy (#956)
* Add Vite helper for tenancy * Move Vite bundler to an Optional Feature * Rename to foundation vite * Add ViteBundlerTest * Add missing end of file * Update tests * remove unnecessary end() call Co-authored-by: Samuel Štancl <samuel@archte.ch>
This commit is contained in:
parent
38fc706c97
commit
d093c1387d
5 changed files with 75 additions and 0 deletions
|
|
@ -168,6 +168,7 @@ return [
|
|||
// Stancl\Tenancy\Features\UniversalRoutes::class,
|
||||
// Stancl\Tenancy\Features\TenantConfig::class, // https://tenancyforlaravel.com/docs/v3/features/tenant-config
|
||||
// Stancl\Tenancy\Features\CrossDomainRedirect::class, // https://tenancyforlaravel.com/docs/v3/features/cross-domain-redirect
|
||||
// Stancl\Tenancy\Features\ViteBundler::class,
|
||||
],
|
||||
|
||||
/**
|
||||
|
|
|
|||
21
src/Features/ViteBundler.php
Normal file
21
src/Features/ViteBundler.php
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Features;
|
||||
|
||||
use Illuminate\Foundation\Application;
|
||||
use Illuminate\Foundation\Vite as FoundationVite;
|
||||
use Stancl\Tenancy\Contracts\Feature;
|
||||
use Stancl\Tenancy\Tenancy;
|
||||
use Stancl\Tenancy\Vite as StanclVite;
|
||||
|
||||
class ViteBundler implements Feature
|
||||
{
|
||||
public function __construct(protected Application $app) { }
|
||||
|
||||
public function bootstrap(Tenancy $tenancy): void
|
||||
{
|
||||
$this->app->singleton(FoundationVite::class, StanclVite::class);
|
||||
}
|
||||
}
|
||||
|
|
@ -65,6 +65,7 @@ class TenancyServiceProvider extends ServiceProvider
|
|||
$this->app->singleton(Commands\Rollback::class, function ($app) {
|
||||
return new Commands\Rollback($app['migrator']);
|
||||
});
|
||||
|
||||
$this->app->singleton(Commands\Seed::class, function ($app) {
|
||||
return new Commands\Seed($app['db']);
|
||||
});
|
||||
|
|
|
|||
20
src/Vite.php
Normal file
20
src/Vite.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy;
|
||||
|
||||
use Illuminate\Foundation\Vite as BaseVite;
|
||||
|
||||
class Vite extends BaseVite
|
||||
{
|
||||
/**
|
||||
* Generate an asset path for the application.
|
||||
*
|
||||
* @param string $path
|
||||
* @param bool|null $secure
|
||||
* @return string
|
||||
*/
|
||||
protected function assetPath($path, $secure = null)
|
||||
{
|
||||
return global_asset($path);
|
||||
}
|
||||
}
|
||||
32
tests/Features/ViteBundlerTest.php
Normal file
32
tests/Features/ViteBundlerTest.php
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
use Illuminate\Foundation\Vite as FoundationVite;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Stancl\Tenancy\Features\ViteBundler;
|
||||
use Stancl\Tenancy\Tests\Etc\Tenant;
|
||||
use Stancl\Tenancy\Vite as StanclVite;
|
||||
|
||||
|
||||
test('replaces the vite helper instance with custom class', function () {
|
||||
$vite = app(\Illuminate\Foundation\Vite::class);
|
||||
|
||||
expect($vite)->toBeInstanceOf(FoundationVite::class);
|
||||
|
||||
expect($vite)->not->toBeInstanceOf(StanclVite::class);
|
||||
|
||||
config([
|
||||
'tenancy.features' => [ViteBundler::class],
|
||||
]);
|
||||
|
||||
$tenant = Tenant::create();
|
||||
|
||||
tenancy()->initialize($tenant);
|
||||
|
||||
app()->forgetInstance(\Illuminate\Foundation\Vite::class);
|
||||
|
||||
$vite = app(\Illuminate\Foundation\Vite::class);
|
||||
|
||||
expect($vite)->toBeInstanceOf(StanclVite::class);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue