Completed
Push — 4.0 ( 268f2c...88f012 )
by Hideki
05:48 queued 10s
created

DependencyInjection/Compiler/PurchaseFlowPass.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.ec-cube.co.jp/
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Eccube\DependencyInjection\Compiler;
15
16
use Doctrine\Common\Annotations\AnnotationReader;
17
use Doctrine\Common\Annotations\AnnotationRegistry;
18
use Eccube\Annotation\CartFlow;
19
use Eccube\Annotation\OrderFlow;
20
use Eccube\Annotation\ShoppingFlow;
21
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
22
use Symfony\Component\DependencyInjection\ContainerBuilder;
23
use Symfony\Component\DependencyInjection\Reference;
24
25
class PurchaseFlowPass implements CompilerPassInterface
26
{
27
    const ITEM_PREPROCESSOR_TAG = 'eccube.item.preprocessor';
28
    const ITEM_VALIDATOR_TAG = 'eccube.item.validator';
29
    const ITEM_HOLDER_PREPROCESSOR_TAG = 'eccube.item.holder.preprocessor';
30
    const ITEM_HOLDER_VALIDATOR_TAG = 'eccube.item.holder.validator';
31
    const ITEM_HOLDER_POST_VALIDATOR_TAG = 'eccube.item.holder.post.validator';
32
    const DISCOUNT_PROCESSOR_TAG = 'eccube.discount.processor';
33 9
    const PURCHASE_PROCESSOR_TAG = 'eccube.purchase.processor';
34
35
    public function process(ContainerBuilder $container)
36 9
    {
37 9
        $flowDefs = [
38 9
            CartFlow::class => $container->getDefinition('eccube.purchase.flow.cart'),
39
            ShoppingFlow::class => $container->getDefinition('eccube.purchase.flow.shopping'),
40
            OrderFlow::class => $container->getDefinition('eccube.purchase.flow.order'),
41
        ];
42 9
43 9
        $processorTags = [
44 9
            self::ITEM_PREPROCESSOR_TAG => 'addItemPreprocessor',
45 9
            self::ITEM_VALIDATOR_TAG => 'addItemValidator',
46 9
            self::ITEM_HOLDER_PREPROCESSOR_TAG => 'addItemHolderPreprocessor',
47
            self::ITEM_HOLDER_VALIDATOR_TAG => 'addItemHolderValidator',
48
            self::ITEM_HOLDER_POST_VALIDATOR_TAG => 'addItemHolderPostValidator',
49 9
            self::DISCOUNT_PROCESSOR_TAG => 'addDiscountProcessor',
50 9
            self::PURCHASE_PROCESSOR_TAG => 'addPurchaseProcessor',
51
        ];
52 9
53 9
        AnnotationRegistry::registerAutoloadNamespace('Eccube\Annotation', __DIR__.'/../../../../src');
0 ignored issues
show
Deprecated Code introduced by
The method Doctrine\Common\Annotati...sterAutoloadNamespace() has been deprecated with message: this method is deprecated and will be removed in doctrine/annotations 2.0 autoloading should be deferred to the globally registered autoloader by then. For now, use @example AnnotationRegistry::registerLoader('class_exists')

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
54 9
        $reader = new AnnotationReader();
55 9
56 9
        foreach ($processorTags as $tag => $methodName) {
57 9
            $ids = $container->findTaggedServiceIds($tag);
58 9
            foreach ($ids as $id => $tags) {
59 9
                $def = $container->getDefinition($id);
60
                foreach ($flowDefs as $annotationName => $purchaseFlowDef) {
61
                    $anno = $reader->getClassAnnotation(new \ReflectionClass($def->getClass()), $annotationName);
62
                    if ($anno) {
63
                        $purchaseFlowDef->addMethodCall($methodName, [new Reference($id)]);
64
                    }
65
                }
66
            }
67
        }
68
    }
69
}
70