|
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\Component\Metadata\Provider; |
|
13
|
|
|
|
|
14
|
|
|
use Doctrine\Common\Persistence\ObjectRepository; |
|
15
|
|
|
use Sylius\Component\Metadata\Compiler\MetadataCompilerInterface; |
|
16
|
|
|
use Sylius\Component\Metadata\Model\MetadataSubjectInterface; |
|
17
|
|
|
use Sylius\Component\Metadata\HierarchyProvider\MetadataHierarchyProviderInterface; |
|
18
|
|
|
use Sylius\Component\Metadata\Model\MetadataContainerInterface; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @author Kamil Kokot <[email protected]> |
|
22
|
|
|
*/ |
|
23
|
|
|
final class MetadataProvider implements MetadataProviderInterface |
|
24
|
|
|
{ |
|
25
|
|
|
/** |
|
26
|
|
|
* @var ObjectRepository |
|
27
|
|
|
*/ |
|
28
|
|
|
private $metadataContainerRepository; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @var MetadataCompilerInterface |
|
32
|
|
|
*/ |
|
33
|
|
|
private $metadataCompiler; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @var MetadataHierarchyProviderInterface |
|
37
|
|
|
*/ |
|
38
|
|
|
private $metadataHierarchyProvider; |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @param ObjectRepository $metadataContainerRepository |
|
42
|
|
|
* @param MetadataCompilerInterface $metadataCompiler |
|
43
|
|
|
* @param MetadataHierarchyProviderInterface $metadataHierarchyProvider |
|
44
|
|
|
*/ |
|
45
|
|
|
public function __construct( |
|
46
|
|
|
ObjectRepository $metadataContainerRepository, |
|
47
|
|
|
MetadataCompilerInterface $metadataCompiler, |
|
48
|
|
|
MetadataHierarchyProviderInterface $metadataHierarchyProvider |
|
49
|
|
|
) { |
|
50
|
|
|
$this->metadataContainerRepository = $metadataContainerRepository; |
|
51
|
|
|
$this->metadataCompiler = $metadataCompiler; |
|
52
|
|
|
$this->metadataHierarchyProvider = $metadataHierarchyProvider; |
|
53
|
|
|
} |
|
54
|
|
|
|
|
55
|
|
|
/** |
|
56
|
|
|
* {@inheritdoc} |
|
57
|
|
|
*/ |
|
58
|
|
|
public function findMetadataBySubject(MetadataSubjectInterface $metadataSubject) |
|
59
|
|
|
{ |
|
60
|
|
|
$identifiers = $this->metadataHierarchyProvider->getHierarchyByMetadataSubject($metadataSubject); |
|
61
|
|
|
|
|
62
|
|
|
$parents = []; |
|
63
|
|
|
$baseMetadata = null; |
|
64
|
|
|
foreach ($identifiers as $identifier) { |
|
65
|
|
|
/** @var MetadataContainerInterface $metadataContainer */ |
|
66
|
|
|
// TODO: Use find($identifier) after Resource refactoring (PR #2255) |
|
|
|
|
|
|
67
|
|
|
$metadataContainer = $this->metadataContainerRepository->findOneBy(['id' => $identifier]); |
|
68
|
|
|
|
|
69
|
|
|
if (null === $metadataContainer) { |
|
70
|
|
|
continue; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
if (null === $baseMetadata) { |
|
74
|
|
|
$baseMetadata = $metadataContainer->getMetadata(); |
|
75
|
|
|
|
|
76
|
|
|
continue; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
$parents[] = $metadataContainer->getMetadata(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
if (null === $baseMetadata) { |
|
83
|
|
|
return null; |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return $this->metadataCompiler->compile($baseMetadata, $parents); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.