Skip to content

Commit b046309

Browse files
committed
Add DatabaseServiceProvider
1 parent c33b2b1 commit b046309

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed
File renamed without changes.

DatabaseRepositoryServiceProvider.php

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
4+
namespace Changiz\DatabaseRepository;
5+
6+
7+
use Changiz\DatabaseRepository\Commands\MakeAllRepository;
8+
use Changiz\DatabaseRepository\Commands\MakeEntity;
9+
use Changiz\DatabaseRepository\Commands\MakeFactory;
10+
use Changiz\DatabaseRepository\Commands\MakeInterfaceRepository;
11+
use Changiz\DatabaseRepository\Commands\MakeMySqlRepository;
12+
use Changiz\DatabaseRepository\Commands\MakeRedisRepository;
13+
use Changiz\DatabaseRepository\Commands\MakeRepository;
14+
use Illuminate\Support\ServiceProvider;
15+
16+
/**
17+
* Laravel service provider for DatabaseRepositor.
18+
*
19+
*/
20+
class DatabaseRepositoryServiceProvider extends ServiceProvider
21+
{
22+
/**
23+
* The package configuration file.
24+
*/
25+
const CONFIG_FILE = 'repository.php';
26+
27+
/**
28+
* Bootstrap the application events.
29+
*/
30+
public function boot()
31+
{
32+
$this->publishes([
33+
__DIR__ . '/Config/' . self::CONFIG_FILE => config_path(self::CONFIG_FILE),
34+
], 'config');
35+
}
36+
37+
/**
38+
* Register the service provider.
39+
*/
40+
public function register()
41+
{
42+
$this->registerCommand();
43+
}
44+
45+
/**
46+
* Register custom commands.
47+
*/
48+
private function registerCommand()
49+
{
50+
$this->app->singleton('command.make-all-repository', function () {
51+
return new MakeAllRepository();
52+
});
53+
54+
$this->app->singleton('command.make-entity', function () {
55+
return new MakeEntity();
56+
});
57+
58+
$this->app->singleton('command.make-factory', function () {
59+
return new MakeFactory();
60+
});
61+
62+
$this->app->singleton('command.make-interface-repository', function () {
63+
return new MakeInterfaceRepository();
64+
});
65+
66+
$this->app->singleton('command.make-mysql-repository', function () {
67+
return new MakeMySqlRepository();
68+
});
69+
70+
$this->app->singleton('command.make-redis-repository', function () {
71+
return new MakeRedisRepository();
72+
});
73+
74+
$this->app->singleton('command.make-repository', function () {
75+
return new MakeRepository();
76+
});
77+
78+
$this->app->singleton('command.make-resource', function () {
79+
return new MakeResource();
80+
});
81+
82+
$this->commands([
83+
'command:make-all-repository',
84+
'command:make-entity',
85+
'command:make-factory',
86+
'command:make-interface-repository',
87+
'command:make-mysql-repository',
88+
'command:make-redis-repository',
89+
'command:make-repository',
90+
'command:make-resource'
91+
]);
92+
}
93+
94+
}

composer.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,12 @@
1717
"psr-4": {
1818
"Changiz\\DatabaseRepository\\": "src/"
1919
}
20+
},
21+
"extra": {
22+
"laravel": {
23+
"providers": [
24+
"DatabaseRepositoryServiceProvider"
25+
]
2026
}
2127
}
28+
}

0 commit comments

Comments
 (0)