-
Notifications
You must be signed in to change notification settings - Fork 494
Expand file tree
/
Copy pathTable.php
More file actions
68 lines (62 loc) · 1.5 KB
/
Copy pathTable.php
File metadata and controls
68 lines (62 loc) · 1.5 KB
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
<?php namespace Xethron\MigrationsGenerator\Syntax;
/**
* Class Table
* @package Xethron\MigrationsGenerator\Syntax
*/
abstract class Table extends \Way\Generators\Syntax\Table{
/**
* @var string
*/
protected $table;
/**
* @param array $fields
* @param string $table
* @param string $method
* @param null $connection
*
* @return string
*/
public function run(array $fields, $table, $connection = null, $method = 'table')
{
$table = substr($table, strlen(\DB::getTablePrefix()));
$this->table = $table;
if (!is_null($connection)) $method = 'connection(\''.$connection.'\')->'.$method;
$compiled = $this->compiler->compile($this->getTemplate(), ['table'=>$table,'method'=>$method]);
return $this->replaceFieldsWith($this->getItems($fields), $compiled);
}
/**
* Return string for adding all foreign keys
*
* @param array $items
* @return array
*/
protected function getItems(array $items)
{
$result = [];
foreach($items as $item) {
$result[] = $this->getItem($item);
}
return $result;
}
/**
* @param array $item
* @return string
*/
abstract protected function getItem(array $item);
/**
* @param $decorators
* @return string
*/
protected function addDecorators($decorators)
{
$output = '';
foreach ($decorators as $decorator) {
$output .= sprintf("->%s", $decorator);
// Do we need to tack on the parentheses?
if (strpos($decorator, '(') === false) {
$output .= '()';
}
}
return $output;
}
}