1 <?php
  2 
  3 /**
  4  * Class to represent sql columns.
  5  *
  6  * @author gharlan
  7  *
  8  * @package redaxo\core\sql
  9  */
 10 class rex_sql_column
 11 {
 12     private $name;
 13     private $type;
 14     private $nullable;
 15     private $default;
 16     private $extra;
 17 
 18     private $modified = false;
 19 
 20     /**
 21      * @param string      $name
 22      * @param string      $type
 23      * @param bool        $nullable
 24      * @param null|string $default
 25      * @param null|string $extra
 26      */
 27     public function __construct($name, $type, $nullable = false, $default = null, $extra = null)
 28     {
 29         $this->name = $name;
 30         $this->type = $type;
 31         $this->nullable = $nullable;
 32         $this->default = $default;
 33         $this->extra = $extra;
 34     }
 35 
 36     /**
 37      * @param bool $modified
 38      *
 39      * @return $this
 40      */
 41     public function setModified($modified)
 42     {
 43         $this->modified = $modified;
 44 
 45         return $this;
 46     }
 47 
 48     /**
 49      * @return bool
 50      */
 51     public function isModified()
 52     {
 53         return $this->modified;
 54     }
 55 
 56     /**
 57      * @param string $name
 58      *
 59      * @return $this
 60      */
 61     public function setName($name)
 62     {
 63         $this->name = $name;
 64 
 65         return $this->setModified(true);
 66     }
 67 
 68     /**
 69      * @return string
 70      */
 71     public function getName()
 72     {
 73         return $this->name;
 74     }
 75 
 76     /**
 77      * @param string $type
 78      *
 79      * @return $this
 80      */
 81     public function setType($type)
 82     {
 83         $this->type = $type;
 84 
 85         return $this->setModified(true);
 86     }
 87 
 88     /**
 89      * @return string
 90      */
 91     public function getType()
 92     {
 93         return $this->type;
 94     }
 95 
 96     /**
 97      * @param bool $nullable
 98      *
 99      * @return $this
100      */
101     public function setNullable($nullable)
102     {
103         $this->nullable = $nullable;
104 
105         return $this->setModified(true);
106     }
107 
108     /**
109      * @return bool
110      */
111     public function isNullable()
112     {
113         return $this->nullable;
114     }
115 
116     /**
117      * @param null|string $default
118      *
119      * @return $this
120      */
121     public function setDefault($default)
122     {
123         $this->default = $default;
124 
125         return $this->setModified(true);
126     }
127 
128     /**
129      * @return null|string
130      */
131     public function getDefault()
132     {
133         return $this->default;
134     }
135 
136     /**
137      * @param null|string $extra
138      *
139      * @return $this
140      */
141     public function setExtra($extra)
142     {
143         $this->extra = $extra;
144 
145         return $this->setModified(true);
146     }
147 
148     /**
149      * @return null|string
150      */
151     public function getExtra()
152     {
153         return $this->extra;
154     }
155 
156     /**
157      * @return bool
158      */
159     public function equals(self $column)
160     {
161         return
162             $this->name === $column->name &&
163             $this->type === $column->type &&
164             $this->nullable === $column->nullable &&
165             $this->default === $column->default &&
166             $this->extra === $column->extra;
167     }
168 }
169