55namespace WayOfDev \Cycle \Bridge \Laravel \Providers ;
66
77use Cycle \Database \Config \DatabaseConfig ;
8+ use Cycle \Database \DatabaseManager ;
9+ use Cycle \Database \DatabaseProviderInterface ;
810use Illuminate \Support \ServiceProvider ;
11+ use WayOfDev \Cycle \Config ;
12+ use WayOfDev \Cycle \Contracts \Config \Repository as ConfigRepository ;
13+ use WayOfDev \Cycle \Contracts \EntityManager ;
14+ use WayOfDev \Cycle \Entity \Manager ;
915
1016final class CycleServiceProvider extends ServiceProvider
1117{
12- public function register (): void
13- {
14- $ this ->mergeConfigFrom (
15- __DIR__ . '/../../../../config/cycle.php ' ,
16- 'cycle '
17- );
18- }
19-
2018 public function boot (): void
2119 {
2220 if ($ this ->app ->runningInConsole ()) {
@@ -28,18 +26,59 @@ public function boot(): void
2826 }
2927 }
3028
29+ public function register (): void
30+ {
31+ $ this ->mergeConfigFrom (
32+ __DIR__ . '/../../../../config/cycle.php ' ,
33+ 'cycle '
34+ );
35+
36+ $ this ->registerAdapterConfig ();
37+ $ this ->registerDatabaseConfig ();
38+ $ this ->registerDatabaseManager ();
39+ $ this ->registerEntityManager ();
40+ }
41+
3142 private function registerConsoleCommands (): void
3243 {
3344 $ this ->commands ([
45+ // ...
3446 ]);
3547 }
3648
49+ private function registerAdapterConfig (): void
50+ {
51+ $ this ->app ->singleton (ConfigRepository::class, static function (): ConfigRepository {
52+ return Config::fromArray (
53+ config ('cycle ' )
54+ );
55+ });
56+ }
57+
3758 private function registerDatabaseConfig (): void
3859 {
3960 $ this ->app ->singleton (DatabaseConfig::class, static function (): DatabaseConfig {
4061 return new DatabaseConfig (
41- // sjuda podatj nastrojki iz konfiga !!!
62+ config ('cycle.database ' )
63+ );
64+ });
65+ }
66+
67+ private function registerDatabaseManager (): void
68+ {
69+ $ this ->app ->singleton (DatabaseProviderInterface::class, function ($ app ): DatabaseProviderInterface {
70+ return new DatabaseManager (
71+ $ app [DatabaseConfig::class]
4272 );
4373 });
74+
75+ $ this ->app ->alias (DatabaseProviderInterface::class, DatabaseManager::class);
76+ }
77+
78+ private function registerEntityManager (): void
79+ {
80+ $ this ->app ->singleton (EntityManager::class, function ($ app ): EntityManager {
81+ return $ app [Manager::class];
82+ });
4483 }
4584}
0 commit comments