Collections
2 weeks ago
Concerns
2 weeks ago
Console
2 weeks ago
Constants
2 weeks ago
Contracts
2 weeks ago
Database
2 weeks ago
Discovery
2 weeks ago
Exceptions
2 weeks ago
Filesystem
2 weeks ago
Http
2 weeks ago
Managers
2 weeks ago
Middlewares
2 weeks ago
Polyfill
2 weeks ago
Supports
2 weeks ago
Validation
2 weeks ago
Wordpress
2 weeks ago
ApiExceptionHandler.php
2 weeks ago
Application.php
2 weeks ago
Container.php
2 weeks ago
CoreServiceProvider.php
2 weeks ago
DTO.php
2 weeks ago
Facade.php
2 weeks ago
Listener.php
2 weeks ago
Resource.php
2 weeks ago
Route.php
2 weeks ago
Sanitizer.php
2 weeks ago
ServiceProvider.php
2 weeks ago
helpers.php
2 weeks ago
CoreServiceProvider.php
137 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Registers the framework's essential services during application bootstrap. |
| 5 | * Binds database, schema, migration, discovery, and manager components into the container. |
| 6 | * Boots listener and policy discovery caching. |
| 7 | * |
| 8 | * @package Framework |
| 9 | * @since 1.0.0 |
| 10 | */ |
| 11 | namespace Kirki\Framework; |
| 12 | |
| 13 | \defined('ABSPATH') || exit; |
| 14 | use Kirki\Framework\Console\CommandManager; |
| 15 | use Kirki\Framework\Database\Connection\Connection; |
| 16 | use Kirki\Framework\Database\Connection\DatabaseManager; |
| 17 | use Kirki\Framework\Database\Migrations\Migrator; |
| 18 | use Kirki\Framework\Database\Schema\SchemaManager; |
| 19 | use Kirki\Framework\Discovery\ListenerDiscovery; |
| 20 | use Kirki\Framework\Discovery\PolicyDiscovery; |
| 21 | use Kirki\Framework\Managers\EventManager; |
| 22 | use Kirki\Framework\Managers\LogManager; |
| 23 | use Kirki\Framework\Managers\PolicyManager; |
| 24 | use Kirki\Framework\ServiceProvider; |
| 25 | use Kirki\Framework\Managers\DateManager; |
| 26 | use Kirki\Framework\Http\Response; |
| 27 | use Kirki\Framework\Supports\MessagesBag; |
| 28 | class CoreServiceProvider extends ServiceProvider |
| 29 | { |
| 30 | /** |
| 31 | * Register the hooks to the application. |
| 32 | * |
| 33 | * @return void |
| 34 | * |
| 35 | * @since 1.0.0 |
| 36 | */ |
| 37 | public function register() |
| 38 | { |
| 39 | $this->register_database_services(); |
| 40 | $this->register_discoveries(); |
| 41 | $this->register_managers(); |
| 42 | $this->register_migrations(); |
| 43 | $this->register_messages(); |
| 44 | $this->app->singleton(Response::class); |
| 45 | if (\class_exists(\Faker\Factory::class)) { |
| 46 | $this->app->singleton(\Faker\Factory::class, function () { |
| 47 | return \Faker\Factory::create(); |
| 48 | }); |
| 49 | } |
| 50 | } |
| 51 | /** |
| 52 | * Boot the service provider. |
| 53 | * |
| 54 | * @return void |
| 55 | * |
| 56 | * @since 1.0.0 |
| 57 | */ |
| 58 | public function boot() |
| 59 | { |
| 60 | $this->app->make(PolicyDiscovery::class)->discover()->cache(); |
| 61 | $this->app->make(ListenerDiscovery::class)->discover()->cache(); |
| 62 | } |
| 63 | /** |
| 64 | * Register the messages. |
| 65 | * |
| 66 | * @return void |
| 67 | * |
| 68 | * @since 1.0.0 |
| 69 | */ |
| 70 | protected function register_messages() |
| 71 | { |
| 72 | $this->app->singleton(MessagesBag::class, function () { |
| 73 | return new MessagesBag(); |
| 74 | }); |
| 75 | } |
| 76 | /** |
| 77 | * Register the managers. |
| 78 | * |
| 79 | * @return void |
| 80 | * |
| 81 | * @since 1.0.0 |
| 82 | */ |
| 83 | protected function register_managers() |
| 84 | { |
| 85 | $this->app->singleton(DatabaseManager::class); |
| 86 | $this->app->singleton(SchemaManager::class); |
| 87 | $this->app->singleton(LogManager::class); |
| 88 | $this->app->singleton(EventManager::class); |
| 89 | $this->app->singleton(PolicyManager::class); |
| 90 | $this->app->singleton(DateManager::class); |
| 91 | $this->app->singleton(CommandManager::class); |
| 92 | } |
| 93 | /** |
| 94 | * Register the discoveries. |
| 95 | * |
| 96 | * @return void |
| 97 | * |
| 98 | * @since 1.0.0 |
| 99 | */ |
| 100 | protected function register_discoveries() |
| 101 | { |
| 102 | $this->app->singleton(ListenerDiscovery::class); |
| 103 | $this->app->singleton(PolicyDiscovery::class); |
| 104 | } |
| 105 | /** |
| 106 | * Register the database singletons. |
| 107 | * |
| 108 | * @return void |
| 109 | * |
| 110 | * @since 1.0.0 |
| 111 | */ |
| 112 | protected function register_database_services() |
| 113 | { |
| 114 | $this->app->singleton(Connection::class); |
| 115 | $this->app->singleton(Migrator::class); |
| 116 | } |
| 117 | /** |
| 118 | * Register the migrations tags. |
| 119 | * |
| 120 | * @return void |
| 121 | * |
| 122 | * @since 1.0.0 |
| 123 | */ |
| 124 | protected function register_migrations() |
| 125 | { |
| 126 | $migrations_path = $this->app->config_path('migrations.php'); |
| 127 | if (!\file_exists($migrations_path)) { |
| 128 | return; |
| 129 | } |
| 130 | $migrations = (include $migrations_path); |
| 131 | if (empty($migrations)) { |
| 132 | return; |
| 133 | } |
| 134 | $this->app->tag($migrations, 'app.migrations'); |
| 135 | } |
| 136 | } |
| 137 |