1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of UnderQuery package. |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2016 Beniamin Jonatan Šimko |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Phuria\UnderQuery\QueryCompiler\ConcreteCompiler; |
13
|
|
|
|
14
|
|
|
use Phuria\UnderQuery\QueryBuilder\BuilderInterface; |
15
|
|
|
use Phuria\UnderQuery\QueryBuilder\UpdateBuilder; |
16
|
|
|
use Phuria\UnderQuery\QueryCompiler\ClausesCompiler; |
17
|
|
|
use Phuria\UnderQuery\QueryCompiler\CompilerPayload; |
18
|
|
|
use Phuria\UnderQuery\QueryCompiler\ReferenceCompiler; |
19
|
|
|
use Phuria\UnderQuery\QueryCompiler\TableCompiler; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Beniamin Jonatan Šimko <[email protected]> |
23
|
|
|
*/ |
24
|
|
|
class UpdateCompiler extends AbstractConcreteCompiler |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* UpdateCompiler constructor. |
28
|
|
|
*/ |
29
|
|
|
public function __construct() |
30
|
|
|
{ |
31
|
|
|
$tableCompiler = new TableCompiler(); |
32
|
|
|
$referenceCompiler = new ReferenceCompiler(); |
33
|
|
|
$clauseCompiler = new ClausesCompiler(); |
34
|
|
|
|
35
|
|
|
parent::__construct([ |
36
|
|
|
[$this, 'compileUpdate'], |
37
|
|
|
[$tableCompiler, 'compileRootTables'], |
38
|
|
|
[$tableCompiler, 'compileJoinTables'], |
39
|
|
|
[$clauseCompiler, 'compileSet'], |
40
|
|
|
[$clauseCompiler, 'compileWhere'], |
41
|
|
|
[$clauseCompiler, 'compileOrderBy'], |
42
|
|
|
[$clauseCompiler, 'compileLimit'], |
43
|
|
|
[$referenceCompiler, 'compileReference'], |
44
|
|
|
]); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @inheritdoc |
49
|
|
|
*/ |
50
|
|
|
public function supportsBuilder(BuilderInterface $builder) |
51
|
|
|
{ |
52
|
|
|
return $builder instanceof UpdateBuilder; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @param CompilerPayload $payload |
57
|
|
|
* |
58
|
|
|
* @return CompilerPayload |
59
|
|
|
*/ |
60
|
|
|
public function compileUpdate(CompilerPayload $payload) |
61
|
|
|
{ |
62
|
|
|
$builder = $payload->getBuilder(); |
63
|
|
|
|
64
|
|
|
if ($builder instanceof UpdateBuilder) { |
65
|
|
|
$newSQL = $builder->isIgnore() ? 'UPDATE IGNORE' : 'UPDATE'; |
66
|
|
|
$payload = $payload->updateSQL($newSQL); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
return $payload; |
70
|
|
|
} |
71
|
|
|
} |