1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* NOTICE OF LICENSE |
5
|
|
|
* |
6
|
|
|
* Part of the Rinvex Support Package. |
7
|
|
|
* |
8
|
|
|
* This source file is subject to The MIT License (MIT) |
9
|
|
|
* that is bundled with this package in the LICENSE file. |
10
|
|
|
* |
11
|
|
|
* Package: Rinvex Support Package |
12
|
|
|
* License: The MIT License (MIT) |
13
|
|
|
* Link: https://rinvex.com |
14
|
|
|
*/ |
15
|
|
|
|
16
|
|
|
namespace Rinvex\Support\Providers; |
17
|
|
|
|
18
|
|
|
use Illuminate\Support\ServiceProvider; |
19
|
|
|
|
20
|
|
|
abstract class BaseServiceProvider extends ServiceProvider |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* The alias pattern. |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $aliasPattern = '{{class}}Contract'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Register an IoC binding if it's not already been registered. |
31
|
|
|
* |
32
|
|
|
* @param string $abstract |
33
|
|
|
* @param \Closure|string|null $concrete |
34
|
|
|
* @param bool $shared |
35
|
|
|
* @param bool $force |
36
|
|
|
* |
37
|
|
|
* @return void |
38
|
|
|
*/ |
39
|
|
|
protected function bind($abstract, $concrete = null, $shared = true, $force = false) |
40
|
|
|
{ |
41
|
|
|
if (! $this->app->bound($abstract) || $force) { |
42
|
|
|
$concrete = $concrete ?: $abstract; |
43
|
|
|
$this->app->bind($abstract, $concrete, $shared); |
44
|
|
|
} |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Register an IoC binding whether it's already been registered or not. |
49
|
|
|
* |
50
|
|
|
* @param string $abstract |
51
|
|
|
* @param \Closure|string|null $concrete |
52
|
|
|
* @param bool $shared |
53
|
|
|
* @param string|null $alias |
54
|
|
|
* @param bool $force |
55
|
|
|
* |
56
|
|
|
* @return void |
57
|
|
|
*/ |
58
|
|
|
protected function bindAndAlias($abstract, $concrete = null, $shared = true, $alias = null, $force = false) |
59
|
|
|
{ |
60
|
|
|
if (! $this->app->bound($abstract) || $force) { |
61
|
|
|
$concrete = $concrete ?: $abstract; |
62
|
|
|
$this->app->bind($abstract, $concrete, $shared); |
63
|
|
|
$this->app->alias($abstract, $this->prepareAlias($alias, $concrete)); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Prepare the alias. |
69
|
|
|
* |
70
|
|
|
* @param string|null $alias |
71
|
|
|
* @param mixed $concrete |
72
|
|
|
* |
73
|
|
|
* @return string |
|
|
|
|
74
|
|
|
*/ |
75
|
|
|
protected function prepareAlias($alias, $concrete) |
76
|
|
|
{ |
77
|
|
|
if (! $alias && ! $concrete instanceof \Closure) { |
|
|
|
|
78
|
|
|
$concrete = str_replace('Repositories', 'Contracts', $concrete); |
79
|
|
|
$alias = str_replace('{{class}}', $concrete, $this->aliasPattern); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
return $alias; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.