Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

UpdateDoctrineQuery.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Publish\Core\Persistence\Doctrine;
8
9 use eZ\Publish\Core\Persistence\Database\UpdateQuery;
10 use eZ\Publish\Core\Persistence\Database\QueryException;
11
18 class UpdateDoctrineQuery extends AbstractDoctrineQuery implements UpdateQuery
19 {
21 private $table;
22
24 private $values = [];
25
27 private $where = [];
28
38 public function update($table)
39 {
40 $this->table = $table;
41
42 return $this;
43 }
44
53 public function set($column, $expression)
54 {
55 $this->values[$column] = $expression;
56
57 return $this;
58 }
59
83 public function where()
84 {
85 $args = $this->parseArguments(func_get_args());
86
87 foreach ($args as $whereExpression) {
88 $this->where[] = $whereExpression;
89 }
90
91 return $this;
92 }
93
97 public function getQuery()
98 {
99 if (strlen($this->table) === 0) {
100 throw new QueryException('Missing table name');
101 }
102
103 if (count($this->values) === 0) {
104 throw new QueryException('Missing values');
105 }
106
107 if (count($this->where) === 0) {
108 throw new QueryException('Executing update without where clause is not allowed');
109 }
110
111 $set = [];
112
113 foreach ($this->values as $column => $expression) {
114 $set[] = $column . ' = ' . $expression;
115 }
116
117 return 'UPDATE ' . $this->table . ' SET ' . implode(', ', $set)
118 . ' WHERE ' . implode(' AND ', $this->where);
119 }
120 }
eZ\Publish\Core\Persistence\Database\QueryException
Class QueryException.
Definition: QueryException.php:18
eZ\Publish\Core\Persistence\Doctrine\AbstractDoctrineQuery
Class AbstractDoctrineQuery.
Definition: AbstractDoctrineQuery.php:21
eZ\Publish\Core\Persistence\Doctrine\AbstractDoctrineQuery\parseArguments
parseArguments(array $args)
Parse the arguments and validate for existance of values.
Definition: AbstractDoctrineQuery.php:212
eZ\Publish\Core\Persistence\Doctrine\UpdateDoctrineQuery
Class UpdateDoctrineQuery.
Definition: UpdateDoctrineQuery.php:19
eZ\Publish\Core\Persistence\Doctrine\UpdateDoctrineQuery\$where
$where
Definition: UpdateDoctrineQuery.php:27
eZ\Publish\Core\Persistence\Doctrine\UpdateDoctrineQuery\getQuery
getQuery()
Definition: UpdateDoctrineQuery.php:97
eZ\Publish\Core\Persistence\Doctrine\UpdateDoctrineQuery\$table
$table
Definition: UpdateDoctrineQuery.php:21
eZ\Publish\Core\Persistence\Doctrine\UpdateDoctrineQuery\update
update($table)
Opens the query and sets the target table to $table.
Definition: UpdateDoctrineQuery.php:38
eZ\Publish\Core\Persistence\Doctrine\UpdateDoctrineQuery\$values
$values
Definition: UpdateDoctrineQuery.php:24
eZ\Publish\Core\Persistence\Doctrine\UpdateDoctrineQuery\where
where()
Adds a where clause with logical expressions to the query.
Definition: UpdateDoctrineQuery.php:83
eZ\Publish\Core\Persistence\Database\UpdateQuery
Definition: UpdateQuery.php:16
eZ\Publish\Core\Persistence\Doctrine
Definition: AbstractDoctrineQuery.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.