Completed
Push — 3.x ( fe4009...05c76d )
by Grégoire
03:50
created

CollectionPostArchiveAction::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 3
1
<?php
2
3
/*
4
 * This file is part of the Sonata Project package.
5
 *
6
 * (c) Thomas Rabaix <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sonata\NewsBundle\Action;
13
14
use Sonata\ClassificationBundle\Model\CollectionManagerInterface;
15
use Sonata\NewsBundle\Model\BlogInterface;
16
use Sonata\NewsBundle\Model\PostManagerInterface;
17
use Symfony\Component\HttpFoundation\Request;
18
use Symfony\Component\HttpFoundation\Response;
19
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
20
21
final class CollectionPostArchiveAction extends AbstractPostArchiveAction
22
{
23
    /**
24
     * @var CollectionManagerInterface
25
     */
26
    private $collectionManager;
27
28
    public function __construct(
29
        BlogInterface $blog,
30
        PostManagerInterface $postManager,
31
        CollectionManagerInterface $collectionManager
32
    ) {
33
        parent::__construct($blog, $postManager);
34
35
        $this->collectionManager = $collectionManager;
36
    }
37
38
    /**
39
     * @param string $tag
40
     *
41
     * @return Response
42
     */
43
    public function __invoke(Request $request, $tag)
44
    {
45
        $collection = $this->collectionManager->findOneBy([
46
            'slug' => $tag,
47
            'enabled' => true,
48
        ]);
49
50
        if (!$collection || !$collection->getEnabled()) {
51
            throw new NotFoundHttpException('Unable to find the collection');
52
        }
53
54
        return $this->renderArchive($request, ['collection' => $collection], ['collection' => $collection]);
55
    }
56
}
57