Constraint.php 1.68 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\Framework\Setup\Declaration\Schema\Dto;

/**
 * Constraint structural element.
 * Used for creating additional rules on db tables.
 */
class Constraint extends GenericElement implements
    ElementInterface,
    TableElementInterface
{
    /**
     * In case if we will need to change this object: add, modify or drop, we will need
     * to define it by its type.
     */
    const TYPE = 'constraint';

    /**
     * Means PRIMARY KEY
     */
    const PRIMARY_TYPE = 'primary';

    /**
     * Means UNIQUE KEY
     */
    const UNIQUE_TYPE = 'unique';

    /**
     * @var Table
     */
    private $table;

    /**
     * @var string
     */
    private $nameWithoutPrefix;

    /**
     * Constructor.
     *
     * @param string $name
     * @param string $type
     * @param Table $table
     * @param string $nameWithoutPrefix
     */
    public function __construct(
        string $name,
        string $type,
        Table $table,
        string $nameWithoutPrefix
    ) {
        parent::__construct($name, $type);
        $this->table = $table;
        $this->nameWithoutPrefix = $nameWithoutPrefix;
    }

    /**
     * Retrieve table object.
     *
     * @return Table
     */
    public function getTable()
    {
        return $this->table;
    }

    /**
     * @inheritdoc
     */
    public function getElementType()
    {
        return self::TYPE;
    }

    /**
     * Retrieve the constraint name which is calculated without table prefix.
     *
     * @return string
     */
    public function getNameWithoutPrefix()
    {
        return $this->nameWithoutPrefix;
    }
}