@@ -7,17 +7,17 @@ |
||
7 | 7 | |
8 | 8 | class StringColumn extends ColumnRule implements ColumnInterface |
9 | 9 | { |
10 | - const DEFAULT_LENGTH = 30; |
|
10 | + const DEFAULT_LENGTH = 30; |
|
11 | 11 | |
12 | - public function __construct($title, $length = self::DEFAULT_LENGTH) |
|
13 | - { |
|
14 | - $this->setTitle($title); |
|
15 | - $this->setType(self::TYPE_STRING); |
|
16 | - $this->setLength($length); |
|
17 | - } |
|
12 | + public function __construct($title, $length = self::DEFAULT_LENGTH) |
|
13 | + { |
|
14 | + $this->setTitle($title); |
|
15 | + $this->setType(self::TYPE_STRING); |
|
16 | + $this->setLength($length); |
|
17 | + } |
|
18 | 18 | |
19 | - public static function cast($content) |
|
20 | - { |
|
21 | - return ''.trim(Str::toUtf8(Bin::toStr($content))); |
|
22 | - } |
|
19 | + public static function cast($content) |
|
20 | + { |
|
21 | + return ''.trim(Str::toUtf8(Bin::toStr($content))); |
|
22 | + } |
|
23 | 23 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | class DebugPool extends Pool |
6 | 6 | { |
7 | - public function cast($element) |
|
8 | - { |
|
9 | - return $element; |
|
10 | - } |
|
7 | + public function cast($element) |
|
8 | + { |
|
9 | + return $element; |
|
10 | + } |
|
11 | 11 | } |
@@ -4,29 +4,29 @@ |
||
4 | 4 | |
5 | 5 | class BtrieveRecord extends ActiveRecord |
6 | 6 | { |
7 | - protected $length; |
|
7 | + protected $length; |
|
8 | 8 | |
9 | - /** |
|
10 | - * Sets the element's length in bytes. |
|
11 | - * |
|
12 | - * @param int $n |
|
13 | - * |
|
14 | - * @return BtrieveRecord |
|
15 | - */ |
|
16 | - public function setLength($n) |
|
17 | - { |
|
18 | - $this->length = $n; |
|
9 | + /** |
|
10 | + * Sets the element's length in bytes. |
|
11 | + * |
|
12 | + * @param int $n |
|
13 | + * |
|
14 | + * @return BtrieveRecord |
|
15 | + */ |
|
16 | + public function setLength($n) |
|
17 | + { |
|
18 | + $this->length = $n; |
|
19 | 19 | |
20 | - return $this; |
|
21 | - } |
|
20 | + return $this; |
|
21 | + } |
|
22 | 22 | |
23 | - /** |
|
24 | - * Returns the element's length in bytes. |
|
25 | - * |
|
26 | - * @return int |
|
27 | - */ |
|
28 | - public function getLength() |
|
29 | - { |
|
30 | - return $this->length; |
|
31 | - } |
|
23 | + /** |
|
24 | + * Returns the element's length in bytes. |
|
25 | + * |
|
26 | + * @return int |
|
27 | + */ |
|
28 | + public function getLength() |
|
29 | + { |
|
30 | + return $this->length; |
|
31 | + } |
|
32 | 32 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | class RecordsPool extends Pool |
6 | 6 | { |
7 | - public function cast($element) |
|
8 | - { |
|
9 | - return BtrieveRecord::attributes($element); |
|
10 | - } |
|
7 | + public function cast($element) |
|
8 | + { |
|
9 | + return BtrieveRecord::attributes($element); |
|
10 | + } |
|
11 | 11 | } |
@@ -6,200 +6,200 @@ |
||
6 | 6 | |
7 | 7 | class ActiveRecord |
8 | 8 | { |
9 | - private $columns; |
|
10 | - private $data; |
|
11 | - private $attributes; |
|
12 | - |
|
13 | - /** |
|
14 | - * Shorter way to create an ActiveRecord using an array of attributes. |
|
15 | - * |
|
16 | - * @param array $attributes |
|
17 | - * |
|
18 | - * @return ActiveRecord |
|
19 | - */ |
|
20 | - public static function attributes($attributes = []) |
|
21 | - { |
|
22 | - return (new static())->setAttributes($attributes); |
|
23 | - } |
|
24 | - |
|
25 | - /** |
|
26 | - * Constructor. |
|
27 | - * |
|
28 | - * @param array $columns |
|
29 | - * @param array $data |
|
30 | - */ |
|
31 | - public function __construct($columns = [], $data = []) |
|
32 | - { |
|
33 | - if (count($columns) !== count($data)) { |
|
34 | - throw new InvalidArgumentException('Columns are required to have the same # of elements from data.'); |
|
35 | - } |
|
36 | - $this->setColumns($columns); |
|
37 | - $this->setData($data); |
|
38 | - if (!empty($columns)) { |
|
39 | - $this->setAttributes(array_combine($this->getColumns(), $this->getData())); |
|
40 | - } |
|
41 | - } |
|
42 | - |
|
43 | - /** |
|
44 | - * Set columns. |
|
45 | - * |
|
46 | - * @param array $columns |
|
47 | - * |
|
48 | - * @return ActiveRecord |
|
49 | - */ |
|
50 | - public function setColumns($columns) |
|
51 | - { |
|
52 | - $this->columns = $columns; |
|
53 | - |
|
54 | - return $this; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Get columns. |
|
59 | - * |
|
60 | - * @return array |
|
61 | - */ |
|
62 | - public function getColumns() |
|
63 | - { |
|
64 | - return $this->columns; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Set correspondent data from columns order. |
|
69 | - * |
|
70 | - * @param array $data |
|
71 | - * |
|
72 | - * @return ActiveRecord |
|
73 | - */ |
|
74 | - public function setData($data) |
|
75 | - { |
|
76 | - $this->data = $data; |
|
77 | - |
|
78 | - return $this; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Get correspondent data from columns order. |
|
83 | - * |
|
84 | - * @return array |
|
85 | - */ |
|
86 | - public function getData() |
|
87 | - { |
|
88 | - return $this->data; |
|
89 | - } |
|
90 | - |
|
91 | - /** |
|
92 | - * Returns combination array of attributes. |
|
93 | - * |
|
94 | - * @return array |
|
95 | - */ |
|
96 | - public function toArray() |
|
97 | - { |
|
98 | - return $this->getAttributes(); |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * Defines columns and data from an array of attributes. |
|
103 | - * |
|
104 | - * @param array $attributes |
|
105 | - * |
|
106 | - * @return ActiveRecord |
|
107 | - */ |
|
108 | - public function setAttributes($attributes) |
|
109 | - { |
|
110 | - $this->attributes = $attributes; |
|
111 | - $this->setColumns(array_keys($attributes)); |
|
112 | - $this->setData(array_values($attributes)); |
|
113 | - |
|
114 | - return $this; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Get an array of attributes. |
|
119 | - * |
|
120 | - * @return array |
|
121 | - */ |
|
122 | - public function getAttributes() |
|
123 | - { |
|
124 | - return $this->attributes; |
|
125 | - } |
|
126 | - |
|
127 | - /** |
|
128 | - * Verify if columns exists. |
|
129 | - * |
|
130 | - * @param string $key |
|
131 | - * |
|
132 | - * @return bool |
|
133 | - */ |
|
134 | - public function has($key) |
|
135 | - { |
|
136 | - if (isset($this->attributes[$key])) { |
|
137 | - return true; |
|
138 | - } |
|
139 | - |
|
140 | - return false; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Returns attribute of the element. |
|
145 | - * |
|
146 | - * @param string $key |
|
147 | - * |
|
148 | - * @return mixed |
|
149 | - */ |
|
150 | - public function attribute($key) |
|
151 | - { |
|
152 | - if (!$this->has($key)) { |
|
153 | - throw new InvalidArgumentException('Attribute \''.$key.'\' doesnt exists.'); |
|
154 | - } |
|
155 | - |
|
156 | - return $this->attributes[$key]; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @aliasof attribute |
|
161 | - * |
|
162 | - * @param string $key |
|
163 | - * |
|
164 | - * @return mixed |
|
165 | - */ |
|
166 | - public function attr($key) |
|
167 | - { |
|
168 | - return $this->attribute($key); |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * Update attribute value. |
|
173 | - * |
|
174 | - * @param string $key |
|
175 | - * @param mixed $value |
|
176 | - */ |
|
177 | - public function update($key, $value) |
|
178 | - { |
|
179 | - if (!$this->has($key)) { |
|
180 | - throw new InvalidArgumentException('Attribute \''.$key.'\' doesnt exists.'); |
|
181 | - } |
|
182 | - $this->attributes[$key] = $value; |
|
183 | - $this->data[array_search($key, $this->getColumns())] = $value; |
|
184 | - |
|
185 | - return $this; |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * Set new attribute value. |
|
190 | - * |
|
191 | - * @param string $key |
|
192 | - * @param mixed $value |
|
193 | - */ |
|
194 | - public function set($key, $value) |
|
195 | - { |
|
196 | - if ($this->has($key)) { |
|
197 | - return $this->update($key, $value); |
|
198 | - } |
|
199 | - $this->attributes[$key] = $value; |
|
200 | - $this->columns[] = $key; |
|
201 | - $this->data[] = $value; |
|
202 | - |
|
203 | - return $this; |
|
204 | - } |
|
9 | + private $columns; |
|
10 | + private $data; |
|
11 | + private $attributes; |
|
12 | + |
|
13 | + /** |
|
14 | + * Shorter way to create an ActiveRecord using an array of attributes. |
|
15 | + * |
|
16 | + * @param array $attributes |
|
17 | + * |
|
18 | + * @return ActiveRecord |
|
19 | + */ |
|
20 | + public static function attributes($attributes = []) |
|
21 | + { |
|
22 | + return (new static())->setAttributes($attributes); |
|
23 | + } |
|
24 | + |
|
25 | + /** |
|
26 | + * Constructor. |
|
27 | + * |
|
28 | + * @param array $columns |
|
29 | + * @param array $data |
|
30 | + */ |
|
31 | + public function __construct($columns = [], $data = []) |
|
32 | + { |
|
33 | + if (count($columns) !== count($data)) { |
|
34 | + throw new InvalidArgumentException('Columns are required to have the same # of elements from data.'); |
|
35 | + } |
|
36 | + $this->setColumns($columns); |
|
37 | + $this->setData($data); |
|
38 | + if (!empty($columns)) { |
|
39 | + $this->setAttributes(array_combine($this->getColumns(), $this->getData())); |
|
40 | + } |
|
41 | + } |
|
42 | + |
|
43 | + /** |
|
44 | + * Set columns. |
|
45 | + * |
|
46 | + * @param array $columns |
|
47 | + * |
|
48 | + * @return ActiveRecord |
|
49 | + */ |
|
50 | + public function setColumns($columns) |
|
51 | + { |
|
52 | + $this->columns = $columns; |
|
53 | + |
|
54 | + return $this; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Get columns. |
|
59 | + * |
|
60 | + * @return array |
|
61 | + */ |
|
62 | + public function getColumns() |
|
63 | + { |
|
64 | + return $this->columns; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Set correspondent data from columns order. |
|
69 | + * |
|
70 | + * @param array $data |
|
71 | + * |
|
72 | + * @return ActiveRecord |
|
73 | + */ |
|
74 | + public function setData($data) |
|
75 | + { |
|
76 | + $this->data = $data; |
|
77 | + |
|
78 | + return $this; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Get correspondent data from columns order. |
|
83 | + * |
|
84 | + * @return array |
|
85 | + */ |
|
86 | + public function getData() |
|
87 | + { |
|
88 | + return $this->data; |
|
89 | + } |
|
90 | + |
|
91 | + /** |
|
92 | + * Returns combination array of attributes. |
|
93 | + * |
|
94 | + * @return array |
|
95 | + */ |
|
96 | + public function toArray() |
|
97 | + { |
|
98 | + return $this->getAttributes(); |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * Defines columns and data from an array of attributes. |
|
103 | + * |
|
104 | + * @param array $attributes |
|
105 | + * |
|
106 | + * @return ActiveRecord |
|
107 | + */ |
|
108 | + public function setAttributes($attributes) |
|
109 | + { |
|
110 | + $this->attributes = $attributes; |
|
111 | + $this->setColumns(array_keys($attributes)); |
|
112 | + $this->setData(array_values($attributes)); |
|
113 | + |
|
114 | + return $this; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Get an array of attributes. |
|
119 | + * |
|
120 | + * @return array |
|
121 | + */ |
|
122 | + public function getAttributes() |
|
123 | + { |
|
124 | + return $this->attributes; |
|
125 | + } |
|
126 | + |
|
127 | + /** |
|
128 | + * Verify if columns exists. |
|
129 | + * |
|
130 | + * @param string $key |
|
131 | + * |
|
132 | + * @return bool |
|
133 | + */ |
|
134 | + public function has($key) |
|
135 | + { |
|
136 | + if (isset($this->attributes[$key])) { |
|
137 | + return true; |
|
138 | + } |
|
139 | + |
|
140 | + return false; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Returns attribute of the element. |
|
145 | + * |
|
146 | + * @param string $key |
|
147 | + * |
|
148 | + * @return mixed |
|
149 | + */ |
|
150 | + public function attribute($key) |
|
151 | + { |
|
152 | + if (!$this->has($key)) { |
|
153 | + throw new InvalidArgumentException('Attribute \''.$key.'\' doesnt exists.'); |
|
154 | + } |
|
155 | + |
|
156 | + return $this->attributes[$key]; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @aliasof attribute |
|
161 | + * |
|
162 | + * @param string $key |
|
163 | + * |
|
164 | + * @return mixed |
|
165 | + */ |
|
166 | + public function attr($key) |
|
167 | + { |
|
168 | + return $this->attribute($key); |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * Update attribute value. |
|
173 | + * |
|
174 | + * @param string $key |
|
175 | + * @param mixed $value |
|
176 | + */ |
|
177 | + public function update($key, $value) |
|
178 | + { |
|
179 | + if (!$this->has($key)) { |
|
180 | + throw new InvalidArgumentException('Attribute \''.$key.'\' doesnt exists.'); |
|
181 | + } |
|
182 | + $this->attributes[$key] = $value; |
|
183 | + $this->data[array_search($key, $this->getColumns())] = $value; |
|
184 | + |
|
185 | + return $this; |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * Set new attribute value. |
|
190 | + * |
|
191 | + * @param string $key |
|
192 | + * @param mixed $value |
|
193 | + */ |
|
194 | + public function set($key, $value) |
|
195 | + { |
|
196 | + if ($this->has($key)) { |
|
197 | + return $this->update($key, $value); |
|
198 | + } |
|
199 | + $this->attributes[$key] = $value; |
|
200 | + $this->columns[] = $key; |
|
201 | + $this->data[] = $value; |
|
202 | + |
|
203 | + return $this; |
|
204 | + } |
|
205 | 205 | } |
@@ -4,8 +4,8 @@ |
||
4 | 4 | |
5 | 5 | class RowsPool extends Pool |
6 | 6 | { |
7 | - public function cast($element) |
|
8 | - { |
|
9 | - return array_values($element); |
|
10 | - } |
|
7 | + public function cast($element) |
|
8 | + { |
|
9 | + return array_values($element); |
|
10 | + } |
|
11 | 11 | } |
@@ -6,113 +6,113 @@ |
||
6 | 6 | |
7 | 7 | abstract class Pool implements DatasetInterface |
8 | 8 | { |
9 | - protected $dataset; |
|
9 | + protected $dataset; |
|
10 | 10 | |
11 | - /** |
|
12 | - * Contructor. |
|
13 | - */ |
|
14 | - public function __construct() |
|
15 | - { |
|
16 | - $this->init(); |
|
17 | - } |
|
11 | + /** |
|
12 | + * Contructor. |
|
13 | + */ |
|
14 | + public function __construct() |
|
15 | + { |
|
16 | + $this->init(); |
|
17 | + } |
|
18 | 18 | |
19 | - /** |
|
20 | - * Initializes a pool of elements. |
|
21 | - * |
|
22 | - * @return Pool |
|
23 | - */ |
|
24 | - public function init() |
|
25 | - { |
|
26 | - $this->dataset = []; |
|
19 | + /** |
|
20 | + * Initializes a pool of elements. |
|
21 | + * |
|
22 | + * @return Pool |
|
23 | + */ |
|
24 | + public function init() |
|
25 | + { |
|
26 | + $this->dataset = []; |
|
27 | 27 | |
28 | - return $this; |
|
29 | - } |
|
28 | + return $this; |
|
29 | + } |
|
30 | 30 | |
31 | - /** |
|
32 | - * Erase all information from dataset. |
|
33 | - * |
|
34 | - * @return Pool |
|
35 | - */ |
|
36 | - public function reset() |
|
37 | - { |
|
38 | - foreach ($this->dataset as $index => $element) { |
|
39 | - unset($this->dataset[$index]); |
|
40 | - } |
|
41 | - unset($this->dataset); |
|
42 | - $this->initDataset(); |
|
31 | + /** |
|
32 | + * Erase all information from dataset. |
|
33 | + * |
|
34 | + * @return Pool |
|
35 | + */ |
|
36 | + public function reset() |
|
37 | + { |
|
38 | + foreach ($this->dataset as $index => $element) { |
|
39 | + unset($this->dataset[$index]); |
|
40 | + } |
|
41 | + unset($this->dataset); |
|
42 | + $this->initDataset(); |
|
43 | 43 | |
44 | - return $this; |
|
45 | - } |
|
44 | + return $this; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * Checks if this element exists in this dataset. |
|
49 | - * |
|
50 | - * @param int $index |
|
51 | - * |
|
52 | - * @return bool |
|
53 | - */ |
|
54 | - public function has($index) |
|
55 | - { |
|
56 | - if (isset($this->dataset[$index])) { |
|
57 | - return true; |
|
58 | - } |
|
47 | + /** |
|
48 | + * Checks if this element exists in this dataset. |
|
49 | + * |
|
50 | + * @param int $index |
|
51 | + * |
|
52 | + * @return bool |
|
53 | + */ |
|
54 | + public function has($index) |
|
55 | + { |
|
56 | + if (isset($this->dataset[$index])) { |
|
57 | + return true; |
|
58 | + } |
|
59 | 59 | |
60 | - return false; |
|
61 | - } |
|
60 | + return false; |
|
61 | + } |
|
62 | 62 | |
63 | - /** |
|
64 | - * @aliasof has |
|
65 | - * |
|
66 | - * @param int $index |
|
67 | - * |
|
68 | - * @return bool |
|
69 | - */ |
|
70 | - public function exists($index) |
|
71 | - { |
|
72 | - return $this->has($index); |
|
73 | - } |
|
63 | + /** |
|
64 | + * @aliasof has |
|
65 | + * |
|
66 | + * @param int $index |
|
67 | + * |
|
68 | + * @return bool |
|
69 | + */ |
|
70 | + public function exists($index) |
|
71 | + { |
|
72 | + return $this->has($index); |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * Returns the element in this index from the dataset. |
|
77 | - * |
|
78 | - * @param int $index |
|
79 | - * |
|
80 | - * @return mixed |
|
81 | - */ |
|
82 | - public function elem($index) |
|
83 | - { |
|
84 | - if ($this->has($index)) { |
|
85 | - return $this->dataset[$index]; |
|
86 | - } |
|
87 | - throw new Exception('Element doesnt exist in this dataset.'); |
|
88 | - } |
|
75 | + /** |
|
76 | + * Returns the element in this index from the dataset. |
|
77 | + * |
|
78 | + * @param int $index |
|
79 | + * |
|
80 | + * @return mixed |
|
81 | + */ |
|
82 | + public function elem($index) |
|
83 | + { |
|
84 | + if ($this->has($index)) { |
|
85 | + return $this->dataset[$index]; |
|
86 | + } |
|
87 | + throw new Exception('Element doesnt exist in this dataset.'); |
|
88 | + } |
|
89 | 89 | |
90 | - /** |
|
91 | - * Function will show how to deal with the element. |
|
92 | - * |
|
93 | - * @param array $element |
|
94 | - * |
|
95 | - * @return mixed |
|
96 | - */ |
|
97 | - abstract public function cast($element); |
|
90 | + /** |
|
91 | + * Function will show how to deal with the element. |
|
92 | + * |
|
93 | + * @param array $element |
|
94 | + * |
|
95 | + * @return mixed |
|
96 | + */ |
|
97 | + abstract public function cast($element); |
|
98 | 98 | |
99 | - /** |
|
100 | - * Adds an element to the dataset. |
|
101 | - * |
|
102 | - * @param array $element |
|
103 | - */ |
|
104 | - public function add($element) |
|
105 | - { |
|
106 | - $this->dataset[] = $this->cast($element); |
|
107 | - } |
|
99 | + /** |
|
100 | + * Adds an element to the dataset. |
|
101 | + * |
|
102 | + * @param array $element |
|
103 | + */ |
|
104 | + public function add($element) |
|
105 | + { |
|
106 | + $this->dataset[] = $this->cast($element); |
|
107 | + } |
|
108 | 108 | |
109 | - /** |
|
110 | - * Return number of elements. |
|
111 | - * |
|
112 | - * @return int |
|
113 | - */ |
|
114 | - public function count() |
|
115 | - { |
|
116 | - return count($this->dataset); |
|
117 | - } |
|
109 | + /** |
|
110 | + * Return number of elements. |
|
111 | + * |
|
112 | + * @return int |
|
113 | + */ |
|
114 | + public function count() |
|
115 | + { |
|
116 | + return count($this->dataset); |
|
117 | + } |
|
118 | 118 | } |
@@ -4,15 +4,15 @@ |
||
4 | 4 | |
5 | 5 | abstract class Rule |
6 | 6 | { |
7 | - protected $length; |
|
7 | + protected $length; |
|
8 | 8 | |
9 | - public function setLength($n) |
|
10 | - { |
|
11 | - $this->length = $n; |
|
12 | - } |
|
9 | + public function setLength($n) |
|
10 | + { |
|
11 | + $this->length = $n; |
|
12 | + } |
|
13 | 13 | |
14 | - public function getLength() |
|
15 | - { |
|
16 | - return $this->length; |
|
17 | - } |
|
14 | + public function getLength() |
|
15 | + { |
|
16 | + return $this->length; |
|
17 | + } |
|
18 | 18 | } |
@@ -4,10 +4,10 @@ |
||
4 | 4 | |
5 | 5 | class SkipRule extends Rule implements RuleInterface |
6 | 6 | { |
7 | - const DEFAULT_LENGTH = 1; |
|
7 | + const DEFAULT_LENGTH = 1; |
|
8 | 8 | |
9 | - public function __construct($length = self::DEFAULT_LENGTH) |
|
10 | - { |
|
11 | - $this->setLength($length); |
|
12 | - } |
|
9 | + public function __construct($length = self::DEFAULT_LENGTH) |
|
10 | + { |
|
11 | + $this->setLength($length); |
|
12 | + } |
|
13 | 13 | } |