PersistenceOperation.php
1 <?php
2 /**
3  * wCMF - wemove Content Management Framework
4  * Copyright (C) 2005-2020 wemove digital solutions GmbH
5  *
6  * Licensed under the terms of the MIT License.
7  *
8  * See the LICENSE file distributed with this work for
9  * additional information.
10  */
11 namespace wcmf\lib\persistence;
12 
14 
15 /**
16  * A PersistenceOperation instance holds data necessary to accomplish
17  * an operation on the persistent store.
18  *
19  * @author ingo herwig <ingo@wemove.com>
20  */
21 abstract class PersistenceOperation {
22 
23  protected $type = null;
24  protected $values = null;
25  protected $criteria = null;
26 
27  /**
28  * Constructor.
29  * @param $type The type of PersistentObject on which the operation
30  * should be executed
31  * @param $values An array of attribute/value pairs to apply
32  * @param $criteria An array of criteria instances to select the objects on
33  * which the operation will be executed
34  */
35  public function __construct($type, array $values, array $criteria) {
36  $this->type = $type;
37  $this->values = $values;
38  $this->criteria = $criteria;
39  }
40 
41  /**
42  * Get the type of PersistentObject on which the operation should be executed
43  * @return String
44  */
45  public function getType() {
46  return $this->type;
47  }
48 
49  /**
50  * Get values to apply
51  * @return Array of attribute/value pairs
52  */
53  public function getValues() {
54  return $this->values;
55  }
56 
57  /**
58  * Get criteria to match
59  * @return Array of Criteria instances
60  */
61  public function getCriteria() {
62  return $this->criteria;
63  }
64 
65  /**
66  * Get a string representation of the operation
67  * @return String
68  */
69  public function __toString() {
70  $str = get_class($this).":type=".$this->type.",values=(";
71  foreach($this->values as $key => $val) {
72  $str .= $key."=".$val.",";
73  }
75  $str .= "),criteria=(";
76  foreach($this->criteria as $criteria) {
77  $str .= $criteria->__toString();
78  }
80  $str .= ")";
81  return $str;
82  }
83 }
84 ?>
static removeTrailingComma($string)
Remove a trailing comma, if existing.
Definition: StringUtil.php:396
A PersistenceOperation instance holds data necessary to accomplish an operation on the persistent sto...
__toString()
Get a string representation of the operation.
__construct($type, array $values, array $criteria)
Constructor.
Persistence layer related interfaces and classes.
Definition: namespaces.php:42
StringUtil provides support for string manipulation.
Definition: StringUtil.php:18
getType()
Get the type of PersistentObject on which the operation should be executed.