ColumnDiff.php 2.31 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
<?php
/*
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * This software consists of voluntary contributions made by many individuals
Benjamin Eberlei's avatar
Benjamin Eberlei committed
16
 * and is licensed under the MIT license. For more information, see
17 18 19 20 21
 * <http://www.doctrine-project.org>.
 */

namespace Doctrine\DBAL\Schema;

22 23
use function in_array;

24
/**
Benjamin Morel's avatar
Benjamin Morel committed
25
 * Represents the change of a column.
26
 *
Benjamin Morel's avatar
Benjamin Morel committed
27 28
 * @link   www.doctrine-project.org
 * @since  2.0
29 30 31 32
 * @author Benjamin Eberlei <kontakt@beberlei.de>
 */
class ColumnDiff
{
Benjamin Morel's avatar
Benjamin Morel committed
33 34 35
    /**
     * @var string
     */
36 37
    public $oldColumnName;

38
    /**
39
     * @var Column
40 41 42 43 44 45
     */
    public $column;

    /**
     * @var array
     */
46
    public $changedProperties = [];
47

48
    /**
49
     * @var Column
50 51 52
     */
    public $fromColumn;

Benjamin Morel's avatar
Benjamin Morel committed
53
    /**
54 55 56 57
     * @param string   $oldColumnName
     * @param Column   $column
     * @param string[] $changedProperties
     * @param Column   $fromColumn
Benjamin Morel's avatar
Benjamin Morel committed
58
     */
59
    public function __construct($oldColumnName, Column $column, array $changedProperties = [], Column $fromColumn = null)
60
    {
61
        $this->oldColumnName = $oldColumnName;
62 63
        $this->column = $column;
        $this->changedProperties = $changedProperties;
64
        $this->fromColumn = $fromColumn;
65 66
    }

Benjamin Morel's avatar
Benjamin Morel committed
67 68 69
    /**
     * @param string $propertyName
     *
70
     * @return bool
Benjamin Morel's avatar
Benjamin Morel committed
71
     */
72 73 74 75
    public function hasChanged($propertyName)
    {
        return in_array($propertyName, $this->changedProperties);
    }
76 77

    /**
78
     * @return Identifier
79 80 81
     */
    public function getOldColumnName()
    {
82 83 84
        $quote = $this->fromColumn && $this->fromColumn->isQuoted();

        return new Identifier($this->oldColumnName, $quote);
85
    }
Benjamin Eberlei's avatar
Benjamin Eberlei committed
86
}