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\Schema;
4
 
5
use Doctrine\DBAL\Schema\Visitor\Visitor;
6
use Doctrine\Deprecations\Deprecation;
7
 
8
use function count;
9
use function sprintf;
10
 
11
/**
12
 * Sequence structure.
13
 */
14
class Sequence extends AbstractAsset
15
{
16
    /** @var int */
17
    protected $allocationSize = 1;
18
 
19
    /** @var int */
20
    protected $initialValue = 1;
21
 
22
    /** @var int|null */
23
    protected $cache;
24
 
25
    /**
26
     * @param string   $name
27
     * @param int      $allocationSize
28
     * @param int      $initialValue
29
     * @param int|null $cache
30
     */
31
    public function __construct($name, $allocationSize = 1, $initialValue = 1, $cache = null)
32
    {
33
        $this->_setName($name);
34
        $this->setAllocationSize($allocationSize);
35
        $this->setInitialValue($initialValue);
36
        $this->cache = $cache;
37
    }
38
 
39
    /** @return int */
40
    public function getAllocationSize()
41
    {
42
        return $this->allocationSize;
43
    }
44
 
45
    /** @return int */
46
    public function getInitialValue()
47
    {
48
        return $this->initialValue;
49
    }
50
 
51
    /** @return int|null */
52
    public function getCache()
53
    {
54
        return $this->cache;
55
    }
56
 
57
    /**
58
     * @param int $allocationSize
59
     *
60
     * @return Sequence
61
     */
62
    public function setAllocationSize($allocationSize)
63
    {
64
        if ($allocationSize > 0) {
65
            $this->allocationSize = $allocationSize;
66
        } else {
67
            $this->allocationSize = 1;
68
        }
69
 
70
        return $this;
71
    }
72
 
73
    /**
74
     * @param int $initialValue
75
     *
76
     * @return Sequence
77
     */
78
    public function setInitialValue($initialValue)
79
    {
80
        if ($initialValue > 0) {
81
            $this->initialValue = $initialValue;
82
        } else {
83
            $this->initialValue = 1;
84
        }
85
 
86
        return $this;
87
    }
88
 
89
    /**
90
     * @param int $cache
91
     *
92
     * @return Sequence
93
     */
94
    public function setCache($cache)
95
    {
96
        $this->cache = $cache;
97
 
98
        return $this;
99
    }
100
 
101
    /**
102
     * Checks if this sequence is an autoincrement sequence for a given table.
103
     *
104
     * This is used inside the comparator to not report sequences as missing,
105
     * when the "from" schema implicitly creates the sequences.
106
     *
107
     * @return bool
108
     */
109
    public function isAutoIncrementsFor(Table $table)
110
    {
111
        $primaryKey = $table->getPrimaryKey();
112
 
113
        if ($primaryKey === null) {
114
            return false;
115
        }
116
 
117
        $pkColumns = $primaryKey->getColumns();
118
 
119
        if (count($pkColumns) !== 1) {
120
            return false;
121
        }
122
 
123
        $column = $table->getColumn($pkColumns[0]);
124
 
125
        if (! $column->getAutoincrement()) {
126
            return false;
127
        }
128
 
129
        $sequenceName      = $this->getShortestName($table->getNamespaceName());
130
        $tableName         = $table->getShortestName($table->getNamespaceName());
131
        $tableSequenceName = sprintf('%s_%s_seq', $tableName, $column->getShortestName($table->getNamespaceName()));
132
 
133
        return $tableSequenceName === $sequenceName;
134
    }
135
 
136
    /**
137
     * @deprecated
138
     *
139
     * @return void
140
     */
141
    public function visit(Visitor $visitor)
142
    {
143
        Deprecation::triggerIfCalledFromOutside(
144
            'doctrine/dbal',
145
            'https://github.com/doctrine/dbal/pull/5435',
146
            'Sequence::visit() is deprecated.',
147
        );
148
 
149
        $visitor->acceptSequence($this);
150
    }
151
}