|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Albert221\Blog\ServiceProvider; |
|
4
|
|
|
|
|
5
|
|
|
use Albert221\Blog\Controller\AbstractController; |
|
6
|
|
|
use Albert221\Blog\Controller\AbstractWidgetController; |
|
7
|
|
|
use Albert221\Blog\Controller\PostController; |
|
8
|
|
|
use Albert221\Blog\Repository\PostRepositoryInterface; |
|
9
|
|
|
use Albert221\Blog\Repository\SettingRepositoryInterface; |
|
10
|
|
|
use Albert221\Blog\Route\RouteCollection; |
|
11
|
|
|
use League\Container\ServiceProvider\AbstractServiceProvider; |
|
12
|
|
|
use League\Container\ServiceProvider\BootableServiceProviderInterface; |
|
13
|
|
|
use Psr\Http\Message\ResponseInterface; |
|
14
|
|
|
use Psr\Http\Message\ServerRequestInterface; |
|
15
|
|
|
use Zend\Diactoros\Response; |
|
16
|
|
|
use Zend\Diactoros\Response\EmitterInterface; |
|
17
|
|
|
use Zend\Diactoros\Response\SapiEmitter; |
|
18
|
|
|
use Zend\Diactoros\ServerRequestFactory; |
|
19
|
|
|
|
|
20
|
|
|
class HttpServiceProvider extends AbstractServiceProvider implements BootableServiceProviderInterface |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritdoc} |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $provides = [ |
|
26
|
|
|
ServerRequestInterface::class, |
|
27
|
|
|
ResponseInterface::class, |
|
28
|
|
|
EmitterInterface::class, |
|
29
|
|
|
RouteCollection::class, |
|
30
|
|
|
PostController::class |
|
31
|
|
|
]; |
|
32
|
|
|
|
|
33
|
|
|
public function boot() |
|
34
|
|
|
{ |
|
35
|
|
|
$this->getContainer()->inflector(AbstractController::class) |
|
36
|
|
|
->invokeMethod('setTwig', ['twig']) |
|
37
|
|
|
->invokeMethod('setSettings', [SettingRepositoryInterface::class]); |
|
38
|
|
|
|
|
39
|
|
|
$this->getContainer()->inflector(AbstractWidgetController::class) |
|
40
|
|
|
->invokeMethod('setWidgetExtension', ['twigWidgetExtension']); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* {@inheritdoc} |
|
45
|
|
|
*/ |
|
46
|
|
|
public function register() |
|
47
|
|
|
{ |
|
48
|
|
|
$this->getContainer()->share(ServerRequestInterface::class, function () { |
|
49
|
|
|
return ServerRequestFactory::fromGlobals(); |
|
50
|
|
|
}); |
|
51
|
|
|
|
|
52
|
|
|
$this->getContainer()->share(ResponseInterface::class, Response::class); |
|
53
|
|
|
|
|
54
|
|
|
$this->getContainer()->share(EmitterInterface::class, SapiEmitter::class); |
|
55
|
|
|
|
|
56
|
|
|
$this->getContainer()->share(RouteCollection::class, function () { |
|
57
|
|
|
return require sprintf( |
|
58
|
|
|
'%s/config/routes.php', |
|
59
|
|
|
$this->getContainer()->get('baseDir') |
|
60
|
|
|
); |
|
61
|
|
|
}); |
|
62
|
|
|
|
|
63
|
|
|
$this->getContainer()->add(PostController::class) |
|
64
|
|
|
->withArgument(PostRepositoryInterface::class) |
|
65
|
|
|
->withArgument('paginatorBuilder'); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|