26 lines
745 B
PHP
26 lines
745 B
PHP
<?php
|
|
|
|
namespace Icefox\Data\Providers;
|
|
|
|
use Icefox\Data\Factories\DataObjectFactory;
|
|
use Icefox\Data\IData;
|
|
use Illuminate\Support\ServiceProvider;
|
|
|
|
class DataObjectServiceProvider extends ServiceProvider
|
|
{
|
|
public function register(): void
|
|
{
|
|
$this->publishes([
|
|
__DIR__ . '../../workbench/config/dto.php' => config_path('dto.php'),
|
|
]);
|
|
|
|
$this->app->beforeResolving(function ($abstract, $parameters, $app) {
|
|
if ($app->has($abstract)) {
|
|
return;
|
|
}
|
|
if (is_subclass_of($abstract, IData::class)) {
|
|
$app->bind($abstract, fn($container) => DataObjectFactory::fromRequest($abstract, $container['request']));
|
|
}
|
|
});
|
|
}
|
|
}
|