Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
iamgergo committed Mar 14, 2024
1 parent e5341ec commit e0430d8
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 39 deletions.
32 changes: 10 additions & 22 deletions src/BazarServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,9 @@

namespace Cone\Bazar;

use Cone\Bazar\Resources\CategoryResource;
use Cone\Bazar\Resources\OrderResource;
use Cone\Bazar\Resources\ProductResource;
use Cone\Bazar\Resources\PropertyResource;
use Cone\Root\Root;
use Cone\Root\Support\Filters;
use Illuminate\Auth\Events\Logout;
use Illuminate\Foundation\Console\AboutCommand;
use Illuminate\Foundation\Events\VendorTagPublished;
use Illuminate\Support\ServiceProvider;

class BazarServiceProvider extends ServiceProvider
Expand Down Expand Up @@ -71,7 +66,6 @@ public function boot(): void
$this->loadViewsFrom(__DIR__.'/../resources/views', 'bazar');

$this->registerEvents();
$this->registerResources();
}

/**
Expand Down Expand Up @@ -99,6 +93,14 @@ protected function registerPublishes(): void
$this->publishes([
__DIR__.'/../resources/views' => $this->app->resourcePath('views/vendor/bazar'),
], 'bazar-views');

$this->publishes([
__DIR__.'/../stubs/BazarServiceProvider.stub' => $this->app->basePath('app/Providers/BazarServiceProvider.php'),
__DIR__.'/../stubs/CategoryResource.stub' => $this->app->basePath('app/Root/Resources/CategoryResource.php'),
__DIR__.'/../stubs/ProductResource.stub' => $this->app->basePath('app/Root/Resources/ProductResource.php'),
__DIR__.'/../stubs/PropertyResource.stub' => $this->app->basePath('app/Root/Resources/PropertyResource.php'),
__DIR__.'/../stubs/OrderResource.stub' => $this->app->basePath('app/Root/Resources/OrderResource.php'),
], 'bazar-stubs');
}

/**
Expand All @@ -121,20 +123,6 @@ protected function registerEvents(): void
{
$this->app['events']->listen(Logout::class, Listeners\ClearCookies::class);
$this->app['events']->listen(Events\PaymentCaptured::class, Listeners\RefreshInventory::class);
}

/**
* Register the resources.
*/
protected function registerResources(): void
{
$resources = Filters::apply('bazar:resources', [
new CategoryResource(),
new ProductResource(),
new PropertyResource(),
new OrderResource(),
]);

$this->app->make(Root::class)->resources->register($resources);
$this->app['events']->listen(VendorTagPublished::class, Listeners\FormatBazarStubs::class);
}
}
6 changes: 6 additions & 0 deletions src/Console/Commands/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Cone\Bazar\Console\Commands;

use Cone\Bazar\BazarServiceProvider;
use Illuminate\Console\Command;

class Install extends Command
Expand All @@ -26,5 +27,10 @@ class Install extends Command
public function handle(): void
{
$this->call('migrate');

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

namespace Cone\Bazar\Listeners;

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

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

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

file_put_contents($to, $contents);
}
}
}
}
13 changes: 2 additions & 11 deletions src/Models/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Closure;
use Cone\Bazar\Database\Factories\AddressFactory;
use Cone\Bazar\Interfaces\Models\Address as Contract;
use Cone\Root\Support\Filters;
use Cone\Root\Traits\InteractsWithProxy;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Factories\Factory;
Expand Down Expand Up @@ -144,11 +143,7 @@ protected function alias(): Attribute
{
return new Attribute(
get: function (?string $value): ?string {
return Filters::apply(
'bazar:address.alias_attribute',
$this->exists ? ($value ?: "#{$this->getKey()}") : $value,
$this
);
return $this->exists ? ($value ?: "#{$this->getKey()}") : $value;
}
);
}
Expand All @@ -162,11 +157,7 @@ protected function name(): Attribute
{
return new Attribute(
get: function (mixed $value, array $attributes): string {
return Filters::apply(
'bazar:address.name_attribute',
trim(sprintf('%s %s', $attributes['first_name'], $attributes['last_name'])),
$this
);
return trim(sprintf('%s %s', $attributes['first_name'], $attributes['last_name']));
}
);
}
Expand Down
41 changes: 41 additions & 0 deletions stubs/BazarServiceProvider.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace {{ namespace }}Providers;

use {{ namespace }}Root\Resources\CategoryResource;
use {{ namespace }}Root\Resources\OrderResource;
use {{ namespace }}Root\Resources\ProductResource;
use {{ namespace }}Root\Resources\PropertyResource;
use Cone\Root\Root;
use Illuminate\Support\ServiceProvider;

class BazarServiceProvider extends ServiceProvider
{
/**
* All of the container bindings that should be registered.
*/
public array $bindings = [
//
];

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

/**
* Bootstrap any application services.
*/
public function boot(): void
{
Root::instance()->resources->register([
new CategoryResource(),
new ProductResource(),
new PropertyResource(),
new OrderResource(),
]);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

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

use Cone\Bazar\Models\Category;
use Cone\Root\Fields\Editor;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

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

use Cone\Bazar\Actions\SendOrderDetails;
use Cone\Bazar\Bazar;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

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

use Cone\Bazar\Bazar;
use Cone\Bazar\Fields\Inventory;
Expand Down Expand Up @@ -49,7 +49,7 @@ public function getModel(): string
*/
public function fields(Request $request): array
{
return array_merge(parent::fields($request), [
return [
ID::make(),

Text::make(__('Name'), 'name')
Expand All @@ -76,6 +76,6 @@ public function fields(Request $request): array
->groupOptionsBy('property.name'),

Variants::make(),
]);
];
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

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

use Cone\Bazar\Models\Property;
use Cone\Root\Fields\HasMany;
Expand Down

0 comments on commit e0430d8

Please sign in to comment.