|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Phossa Project |
|
4
|
|
|
* |
|
5
|
|
|
* PHP version 5.4 |
|
6
|
|
|
* |
|
7
|
|
|
* @category Library |
|
8
|
|
|
* @package Phossa2\Query |
|
9
|
|
|
* @copyright Copyright (c) 2016 phossa.com |
|
10
|
|
|
* @license http://mit-license.org/ MIT License |
|
11
|
|
|
* @link http://www.phossa.com/ |
|
12
|
|
|
*/ |
|
13
|
|
|
/*# declare(strict_types=1); */ |
|
14
|
|
|
|
|
15
|
|
|
namespace Phossa2\Query\Traits\Clause; |
|
16
|
|
|
|
|
17
|
|
|
use Phossa2\Query\Interfaces\Clause\ExtraClauseInterface; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* ExtraClauseTrait |
|
21
|
|
|
* |
|
22
|
|
|
* @package Phossa2\Query |
|
23
|
|
|
* @author Hong Zhang <[email protected]> |
|
24
|
|
|
* @see ExtraClauseInterface |
|
25
|
|
|
* @version 2.0.0 |
|
26
|
|
|
* @since 2.0.0 added |
|
27
|
|
|
*/ |
|
28
|
|
|
trait ExtraClauseTrait |
|
29
|
|
|
{ |
|
30
|
|
|
use AbstractTrait; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritDoc} |
|
34
|
|
|
*/ |
|
35
|
|
|
public function before(/*# string */ $position, /*# string */ $rawString) |
|
36
|
|
|
{ |
|
37
|
|
|
$rawString = $this->positionedParam($rawString, func_get_args(), 2); |
|
38
|
|
|
return $this->beforeAfter('BEFORE', $position, $rawString); |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* {@inheritDoc} |
|
43
|
|
|
*/ |
|
44
|
|
|
public function after(/*# string */ $position, /*# string */ $rawString) |
|
45
|
|
|
{ |
|
46
|
|
|
$rawString = $this->positionedParam($rawString, func_get_args(), 2); |
|
47
|
|
|
return $this->beforeAfter('AFTER', $position, $rawString); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* {@inheritDoc} |
|
52
|
|
|
*/ |
|
53
|
|
|
public function hint(/*# string */ $hintString) |
|
54
|
|
|
{ |
|
55
|
|
|
return $this->beforeAfter('AFTER', 'TYPE', $hintString); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* {@inheritDoc} |
|
60
|
|
|
*/ |
|
61
|
|
|
public function option(/*# string */ $optionString) |
|
62
|
|
|
{ |
|
63
|
|
|
return $this->beforeAfter('AFTER', 'STMT', $optionString); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @param string $type |
|
68
|
|
|
* @param string $position |
|
69
|
|
|
* @param string $rawString |
|
70
|
|
|
* @return $this |
|
71
|
|
|
* @access protected |
|
72
|
|
|
*/ |
|
73
|
|
|
protected function beforeAfter( |
|
74
|
|
|
/*# string */ $type, |
|
75
|
|
|
/*# string */ $position, |
|
76
|
|
|
/*# string */ $rawString |
|
77
|
|
|
) { |
|
78
|
|
|
$clause = &$this->getClause($type); |
|
79
|
|
|
$pos = strtoupper($position); |
|
80
|
|
|
$clause[$pos][] = $rawString; |
|
81
|
|
|
return $this; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
* Build AFTER/BEFORE |
|
86
|
|
|
* |
|
87
|
|
|
* @param string $beforeOrAfter BEFORE|AFTER |
|
88
|
|
|
* @param string $position |
|
89
|
|
|
* @param array $settings |
|
90
|
|
|
* @return string |
|
91
|
|
|
* @access protected |
|
92
|
|
|
*/ |
|
93
|
|
|
protected function buildBeforeAfter( |
|
94
|
|
|
/*# string */ $beforeOrAfter, |
|
95
|
|
|
/*# string */ $position, |
|
96
|
|
|
array $settings |
|
97
|
|
|
)/*# : string */ { |
|
98
|
|
|
$clause = &$this->getClause($beforeOrAfter); |
|
99
|
|
|
if (isset($clause[$position])) { |
|
100
|
|
|
$line = $clause[$position]; |
|
101
|
|
|
$sepr = $settings['seperator']; |
|
102
|
|
|
return $sepr . join($sepr, $line); |
|
103
|
|
|
} else { |
|
104
|
|
|
return ''; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
} |
|
108
|
|
|
|