1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Author: Nil Portugués Calderó <[email protected]> |
4
|
|
|
* Date: 12/24/14 |
5
|
|
|
* Time: 1:14 PM. |
6
|
|
|
* |
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
8
|
|
|
* file that was distributed with this source code. |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace NilPortugues\Sql\QueryBuilder\Builder\Syntax; |
12
|
|
|
|
13
|
|
|
use NilPortugues\Sql\QueryBuilder\Builder\GenericBuilder; |
14
|
|
|
use NilPortugues\Sql\QueryBuilder\Manipulation\AbstractBaseQuery; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* Class AbstractBaseWriter. |
18
|
|
|
*/ |
19
|
|
|
abstract class AbstractBaseWriter |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @var GenericBuilder |
23
|
|
|
*/ |
24
|
|
|
protected $writer; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var PlaceholderWriter |
28
|
|
|
*/ |
29
|
|
|
protected $placeholderWriter; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var ColumnWriter |
33
|
|
|
*/ |
34
|
|
|
protected $columnWriter; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @param GenericBuilder $writer |
38
|
|
|
* @param PlaceholderWriter $placeholder |
39
|
|
|
*/ |
40
|
|
|
public function __construct(GenericBuilder $writer, PlaceholderWriter $placeholder) |
41
|
|
|
{ |
42
|
|
|
$this->writer = $writer; |
43
|
|
|
$this->placeholderWriter = $placeholder; |
44
|
|
|
|
45
|
|
|
$this->columnWriter = WriterFactory::createColumnWriter($writer, $placeholder); |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param AbstractBaseQuery $class |
50
|
|
|
* |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
public static function writeQueryComment(AbstractBaseQuery $class) |
54
|
|
|
{ |
55
|
|
|
$comment = ''; |
56
|
|
|
if ('' !== $class->getComment()) { |
57
|
|
|
$comment = $class->getComment(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
return $comment; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @param AbstractBaseQuery $class |
65
|
|
|
* @param GenericBuilder $writer |
66
|
|
|
* @param PlaceholderWriter $placeholderWriter |
67
|
|
|
* @param array $parts |
68
|
|
|
*/ |
69
|
|
|
public static function writeWhereCondition( |
70
|
|
|
AbstractBaseQuery $class, |
71
|
|
|
$writer, PlaceholderWriter |
72
|
|
|
$placeholderWriter, |
73
|
|
|
array &$parts |
74
|
|
|
) { |
75
|
|
|
if (!is_null($class->getWhere())) { |
76
|
|
|
$whereWriter = WriterFactory::createWhereWriter($writer, $placeholderWriter); |
77
|
|
|
$parts[] = "WHERE {$whereWriter->writeWhere($class->getWhere())}"; |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @param AbstractBaseQuery $class |
83
|
|
|
* @param PlaceholderWriter $placeholderWriter |
84
|
|
|
* @param array $parts |
85
|
|
|
*/ |
86
|
|
|
public static function writeLimitCondition( |
87
|
|
|
AbstractBaseQuery $class, |
88
|
|
|
PlaceholderWriter $placeholderWriter, |
89
|
|
|
array &$parts |
90
|
|
|
) { |
91
|
|
|
if (!is_null($class->getLimitStart())) { |
92
|
|
|
$start = $placeholderWriter->add($class->getLimitStart()); |
93
|
|
|
$parts[] = "LIMIT {$start}"; |
94
|
|
|
} |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|