Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Mar 14, 2024
1 parent 9fa2e00 commit cdc436f
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 26 deletions.
6 changes: 6 additions & 0 deletions src/Console/Commands/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Cone\Root\Console\Commands;

use Cone\Root\Database\Seeders\RootTestDataSeeder;
use Cone\Root\RootServiceProvider;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\File;
Expand Down Expand Up @@ -35,5 +36,10 @@ public function handle(): void
if ($this->option('seed')) {
$this->call('db:seed', ['--class' => RootTestDataSeeder::class]);
}

$this->call('vendor:publish', [
'--provider' => RootServiceProvider::class,
'--tag' => 'root-stubs',
]);
}
}
25 changes: 25 additions & 0 deletions src/Listeners/FormatRootStubs.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Cone\Root\Listeners;

use Illuminate\Foundation\Events\VendorTagPublished;
use Illuminate\Support\Facades\App;

class FormatRootStubs
{
/**
* Handle the event.
*/
public function handle(VendorTagPublished $event): void
{
if ($event->tag === 'root-stubs') {
foreach ($event->paths as $from => $to) {
$contents = file_get_contents($to);

$contents = str_replace('{{ namespace }}', App::getNamespace(), $contents);

file_put_contents($to, $contents);
}
}
}
}
2 changes: 1 addition & 1 deletion src/Root.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public static function instance(): static
}

/**
* Boot the Root application.
* Boot the Root instance.
*/
public function boot(): void
{
Expand Down
34 changes: 10 additions & 24 deletions src/RootServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,15 @@
use Cone\Root\Exceptions\SaveFormDataException;
use Cone\Root\Models\User;
use Cone\Root\Resources\Resource;
use Cone\Root\Resources\UserResource;
use Cone\Root\Support\Alert;
use Cone\Root\Support\Filters;
use Cone\Root\Widgets\Welcome;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Contracts\Debug\ExceptionHandler;
use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\View\View;
use Illuminate\Cookie\Middleware\EncryptCookies;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Console\AboutCommand;
use Illuminate\Foundation\Events\VendorTagPublished;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Routing\Route;
Expand Down Expand Up @@ -84,12 +82,11 @@ public function boot(): void
$this->registerPublishes();
}

$this->registerResources();
$this->registerWidgets();
$this->registerViews();
$this->registerRoutes();
$this->registerExceptions();
$this->registerAuth();
$this->registerEvents();
}

/**
Expand All @@ -113,6 +110,11 @@ protected function registerPublishes(): void
$this->publishes([
__DIR__.'/../resources/views' => $this->app->resourcePath('views/vendor/root'),
], 'root-views');

$this->publishes([
__DIR__.'/../stubs/RootServiceProvider.stub' => $this->app->basePath('app/Providers/RootServiceProvider.php'),
__DIR__.'/../stubs/UserResource.stub' => $this->app->basePath('app/Root/Resources/UserResource.php'),
], 'root-stubs');
}

/**
Expand Down Expand Up @@ -224,26 +226,10 @@ protected function registerAuth(): void
}

/**
* Register the resources.
* Register the events.
*/
protected function registerResources(): void
protected function registerEvents(): void
{
$resources = Filters::apply('root:resources', [
new UserResource(),
]);

Root::instance()->resources->register($resources);
}

/**
* Register the widgets.
*/
protected function registerWidgets(): void
{
$widgets = Filters::apply('root:widgets', [
new Welcome(),
]);

Root::instance()->widgets->register($widgets);
$this->app['events']->listen(VendorTagPublished::class, Listeners\FormatRootStubs::class);
}
}
42 changes: 42 additions & 0 deletions stubs/RootServiceProvider.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

namespace {{ namespace }}Providers;

use {{ namespace }}Models\User;
use {{ namespace }}Root\Resources\UserResource;
use Cone\Root\Interfaces\Models\User as UserInterface;
use Cone\Root\Root;
use Cone\Root\Widgets\Welcome;
use Illuminate\Support\ServiceProvider;

class RootServiceProvider extends ServiceProvider
{
/**
* All of the container bindings that should be registered.
*/
public array $bindings = [
UserInterface::class => User::class,
];

/**
* Register any application services.
*/
public function register(): void
{
//
}

/**
* Bootstrap any application services.
*/
public function boot(): void
{
Root::instance()->resources->register([
new UserResource(),
]);

Root::instance()->widgets->register([
new Welcome(),
]);
}
}
3 changes: 2 additions & 1 deletion src/Resources/UserResource.php → stubs/UserResource.stub
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Cone\Root\Resources;
namespace {{ namespace }}Root\Resources;

use Cone\Root\Actions\SendPasswordResetNotification;
use Cone\Root\Actions\SendVerificationNotification;
Expand All @@ -9,6 +9,7 @@
use Cone\Root\Fields\ID;
use Cone\Root\Fields\Text;
use Cone\Root\Models\User;
use Cone\Root\Resources\Resource;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
Expand Down

0 comments on commit cdc436f

Please sign in to comment.