Completed
Push — checkout-optimisation ( 4a6bfb...756f29 )
by Kamil
18:24
created

ResourceUpdateHandler::__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
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
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 Sylius\Bundle\CoreBundle\Doctrine\ORM\Updater;
13
14
use Doctrine\Common\Persistence\ObjectManager;
15
use Doctrine\ORM\OptimisticLockException;
16
use Sylius\Bundle\ResourceBundle\Controller\RequestConfiguration;
17
use Sylius\Bundle\ResourceBundle\Controller\ResourceUpdateHandlerInterface;
18
use Sylius\Component\Resource\Exception\RaceConditionException;
19
use Sylius\Component\Resource\Model\ResourceInterface;
20
21
/**
22
 * @author Grzegorz Sadowski <[email protected]>
23
 */
24
final class ResourceUpdateHandler implements ResourceUpdateHandlerInterface
25
{
26
    /**
27
     * @var ResourceUpdateHandlerInterface
28
     */
29
    private $decoratedHandler;
30
31
    /**
32
     * @param ResourceUpdateHandlerInterface $decoratedHandler
33
     */
34
    public function __construct(ResourceUpdateHandlerInterface $decoratedHandler)
35
    {
36
        $this->decoratedHandler = $decoratedHandler;
37
    }
38
39
    /**
40
     * {@inheritdoc}
41
     *
42
     * @throws RaceConditionException
43
     */
44
    public function handle(
45
        ResourceInterface $resource,
46
        RequestConfiguration $configuration,
47
        ObjectManager $manager
48
    ) {
49
        try {
50
            $this->decoratedHandler->handle($resource, $configuration, $manager);
51
        } catch (OptimisticLockException $exception) {
52
            throw new RaceConditionException($exception);
53
        }
54
    }
55
}
56