1 <?php
  2 
  3 /**
  4  * Class to represent sql indexes.
  5  *
  6  * @author gharlan
  7  *
  8  * @package redaxo\core\sql
  9  */
 10 class rex_sql_index
 11 {
 12     const INDEX = 'INDEX';
 13     const UNIQUE = 'UNIQUE';
 14     const FULLTEXT = 'FULLTEXT';
 15 
 16     private $name;
 17     private $type;
 18     private $columns;
 19 
 20     private $modified = false;
 21 
 22     /**
 23      * @param string   $name
 24      * @param string[] $columns
 25      * @param string   $type    One of `rex_sql_index::INDEX`, `rex_sql_index::UNIQUE`, `rex_sql_index::FULLTEXT`
 26      */
 27     public function __construct($name, array $columns, $type = self::INDEX)
 28     {
 29         $this->name = $name;
 30         $this->columns = $columns;
 31         $this->type = $type;
 32     }
 33 
 34     /**
 35      * @param bool $modified
 36      *
 37      * @return $this
 38      */
 39     public function setModified($modified)
 40     {
 41         $this->modified = $modified;
 42 
 43         return $this;
 44     }
 45 
 46     /**
 47      * @return bool
 48      */
 49     public function isModified()
 50     {
 51         return $this->modified;
 52     }
 53 
 54     /**
 55      * @param string $name
 56      *
 57      * @return $this
 58      */
 59     public function setName($name)
 60     {
 61         $this->name = $name;
 62 
 63         return $this->setModified(true);
 64     }
 65 
 66     /**
 67      * @return string
 68      */
 69     public function getName()
 70     {
 71         return $this->name;
 72     }
 73 
 74     /**
 75      * @param string $type
 76      *
 77      * @return $this
 78      */
 79     public function setType($type)
 80     {
 81         $this->type = $type;
 82 
 83         return $this->setModified(true);
 84     }
 85 
 86     /**
 87      * @return string
 88      */
 89     public function getType()
 90     {
 91         return $this->type;
 92     }
 93 
 94     /**
 95      * @param string[] $columns
 96      *
 97      * @return $this
 98      */
 99     public function setColumns(array $columns)
100     {
101         $this->columns = $columns;
102 
103         return $this->setModified(true);
104     }
105 
106     /**
107      * @return string[]
108      */
109     public function getColumns()
110     {
111         return $this->columns;
112     }
113 
114     /**
115      * @return bool
116      */
117     public function equals(self $index)
118     {
119         return
120             $this->name === $index->name &&
121             $this->type === $index->type &&
122             $this->columns == $index->columns;
123     }
124 }
125