Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Doctrine\DBAL\Platforms\Keywords;
4
 
5
use Doctrine\DBAL\Schema\Column;
6
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
7
use Doctrine\DBAL\Schema\Index;
8
use Doctrine\DBAL\Schema\Schema;
9
use Doctrine\DBAL\Schema\Sequence;
10
use Doctrine\DBAL\Schema\Table;
11
use Doctrine\DBAL\Schema\Visitor\Visitor;
12
use Doctrine\Deprecations\Deprecation;
13
 
14
use function count;
15
use function implode;
16
use function str_replace;
17
 
18
/** @deprecated Use database documentation instead. */
19
class ReservedKeywordsValidator implements Visitor
20
{
21
    /** @var KeywordList[] */
22
    private array $keywordLists;
23
 
24
    /** @var string[] */
25
    private array $violations = [];
26
 
27
    /** @param KeywordList[] $keywordLists */
28
    public function __construct(array $keywordLists)
29
    {
30
        Deprecation::triggerIfCalledFromOutside(
31
            'doctrine/dbal',
32
            'https://github.com/doctrine/dbal/pull/5431',
33
            'ReservedKeywordsValidator is deprecated. Use database documentation instead.',
34
        );
35
 
36
        $this->keywordLists = $keywordLists;
37
    }
38
 
39
    /** @return string[] */
40
    public function getViolations()
41
    {
42
        return $this->violations;
43
    }
44
 
45
    /**
46
     * @param string $word
47
     *
48
     * @return string[]
49
     */
50
    private function isReservedWord($word): array
51
    {
52
        if ($word[0] === '`') {
53
            $word = str_replace('`', '', $word);
54
        }
55
 
56
        $keywordLists = [];
57
        foreach ($this->keywordLists as $keywordList) {
58
            if (! $keywordList->isKeyword($word)) {
59
                continue;
60
            }
61
 
62
            $keywordLists[] = $keywordList->getName();
63
        }
64
 
65
        return $keywordLists;
66
    }
67
 
68
    /**
69
     * @param string   $asset
70
     * @param string[] $violatedPlatforms
71
     */
72
    private function addViolation($asset, $violatedPlatforms): void
73
    {
74
        if (count($violatedPlatforms) === 0) {
75
            return;
76
        }
77
 
78
        $this->violations[] = $asset . ' keyword violations: ' . implode(', ', $violatedPlatforms);
79
    }
80
 
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function acceptColumn(Table $table, Column $column)
85
    {
86
        $this->addViolation(
87
            'Table ' . $table->getName() . ' column ' . $column->getName(),
88
            $this->isReservedWord($column->getName()),
89
        );
90
    }
91
 
92
    /**
93
     * {@inheritdoc}
94
     */
95
    public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
96
    {
97
    }
98
 
99
    /**
100
     * {@inheritdoc}
101
     */
102
    public function acceptIndex(Table $table, Index $index)
103
    {
104
    }
105
 
106
    /**
107
     * {@inheritdoc}
108
     */
109
    public function acceptSchema(Schema $schema)
110
    {
111
    }
112
 
113
    /**
114
     * {@inheritdoc}
115
     */
116
    public function acceptSequence(Sequence $sequence)
117
    {
118
    }
119
 
120
    /**
121
     * {@inheritdoc}
122
     */
123
    public function acceptTable(Table $table)
124
    {
125
        $this->addViolation(
126
            'Table ' . $table->getName(),
127
            $this->isReservedWord($table->getName()),
128
        );
129
    }
130
}