1 | <?php |
||
19 | class Retrofit |
||
20 | { |
||
21 | /** |
||
22 | * Registered services |
||
23 | * |
||
24 | * @var array $services |
||
25 | */ |
||
26 | private $services = []; |
||
27 | |||
28 | /** |
||
29 | * Finds all services in a given source directory |
||
30 | * |
||
31 | * @var ServiceResolver $serviceResolver |
||
32 | */ |
||
33 | private $serviceResolver; |
||
34 | |||
35 | /** |
||
36 | * An array of proxy factories |
||
37 | * |
||
38 | * @var ProxyFactory[] |
||
39 | */ |
||
40 | private $proxyFactories; |
||
41 | |||
42 | /** |
||
43 | * Constructor |
||
44 | * |
||
45 | * @param ServiceResolver $serviceResolver Finds service classes |
||
46 | * @param ProxyFactory[] $proxyFactories |
||
47 | */ |
||
48 | 19 | public function __construct(ServiceResolver $serviceResolver, array $proxyFactories) |
|
53 | |||
54 | /** |
||
55 | * Create a new builder |
||
56 | * |
||
57 | * @return RetrofitBuilder |
||
58 | */ |
||
59 | 22 | public static function builder(): RetrofitBuilder |
|
63 | |||
64 | /** |
||
65 | * Register an array of classes |
||
66 | * |
||
67 | * @param array $services |
||
68 | * @return void |
||
69 | */ |
||
70 | 1 | public function registerServices(array $services): void |
|
76 | |||
77 | /** |
||
78 | * Register a single class |
||
79 | * |
||
80 | * @param string $service |
||
81 | * @return void |
||
82 | */ |
||
83 | 1 | public function registerService(string $service): void |
|
87 | |||
88 | /** |
||
89 | * Use the service resolver to find all the services dynamically |
||
90 | * |
||
91 | * @param string $srcDir |
||
92 | * @return int Number of services cached |
||
93 | * @throws \RuntimeException |
||
94 | * @throws \BadMethodCallException |
||
95 | */ |
||
96 | 1 | public function createAll(string $srcDir): int |
|
102 | |||
103 | /** |
||
104 | * Creates cache files based on registered services |
||
105 | * |
||
106 | * @return int Number of services cached |
||
107 | * @throws \RuntimeException |
||
108 | * @throws \BadMethodCallException |
||
109 | */ |
||
110 | 2 | public function createServices(): int |
|
118 | |||
119 | /** |
||
120 | * Create a new service proxy given an interface name |
||
121 | * |
||
122 | * The returned proxy object should be used as if it's an |
||
123 | * instance of the service provided. |
||
124 | * |
||
125 | * @param string $service |
||
126 | * @return Proxy |
||
127 | */ |
||
128 | 19 | public function create(string $service): Proxy |
|
140 | } |
||
141 |