Completed
Pull Request — master (#95)
by
unknown
01:29
created

PageSlugController::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * This file was created by the developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\SyliusCmsPlugin\Controller;
14
15
use Sylius\Component\Product\Generator\SlugGeneratorInterface;
16
use Symfony\Component\HttpFoundation\JsonResponse;
17
use Symfony\Component\HttpFoundation\Request;
18
19
/**
20
 * @author Mikołaj Król <[email protected]>
21
 */
22
final class PageSlugController
23
{
24
    /**
25
     * @var SlugGeneratorInterface
26
     */
27
    private $slugGenerator;
28
29
    /**
30
     * @param SlugGeneratorInterface $slugGenerator
31
     */
32
    public function __construct(SlugGeneratorInterface $slugGenerator)
33
    {
34
        $this->slugGenerator = $slugGenerator;
35
    }
36
37
    /**
38
     * @param Request $request
39
     *
40
     * @return JsonResponse
41
     */
42
    public function generateAction(Request $request): JsonResponse
43
    {
44
        $name = $request->query->get('name');
45
46
        return new JsonResponse([
47
            'slug' => $this->slugGenerator->generate($name),
48
        ]);
49
    }
50
}
51