Maslosoft Mangan API
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222
<?php
/**
* This software package is licensed under AGPL or Commercial license.
*
* @package maslosoft/mangan
* @licence AGPL or Commercial
* @copyright Copyright (c) Piotr Masełkowski <pmaselkowski@gmail.com>
* @copyright Copyright (c) Maslosoft
* @copyright Copyright (c) Others as mentioned in code
* @link https://maslosoft.com/mangan/
*/
namespace Maslosoft\Mangan\Interfaces;
use Maslosoft\Addendum\Interfaces\AnnotatedInterface;
use Maslosoft\Mangan\Criteria;
use Maslosoft\Mangan\Exceptions\ManganException;
use Maslosoft\Mangan\Modifier;
use MongoCollection;
/**
*
* @author Piotr Maselkowski <pmaselkowski at gmail.com>
*/
interface EntityManagerInterface
{
const EventBeforeSave = 'beforeSave';
const EventAfterSave = 'afterSave';
const EventBeforeInsert = 'beforeInsert';
const EventAfterInsert = 'afterInsert';
const EventBeforeUpdate = 'beforeUpdate';
const EventAfterUpdate = 'afterUpdate';
const EventBeforeDelete = 'beforeDelete';
const EventAfterDelete = 'afterDelete';
/**
* Replaces the current document.
*
* **NOTE: This will overwrite entire document.**
* Any filtered out properties will be removed as well.
*
* The record is inserted as a documnent into the database collection, if exists it will be replaced.
*
* Validation will be performed before saving the record. If the validation fails,
* the record will not be saved. You can call {@link getErrors()} to retrieve the
* validation errors.
*
* @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be saved to database.
*
* @return boolean whether the saving succeeds
* @since v1.0
*/
public function replace($runValidation = true);
/**
* Inserts a row into the table based on this active record attributes.
* If the table's primary key is auto-incremental and is null before insertion,
* it will be populated with the actual value after insertion.
* Note, validation is not performed in this method. You may call {@link validate} to perform the validation.
* After the record is inserted to DB successfully, its {@link isNewRecord} property will be set false,
* and its {@link scenario} property will be set to be 'update'.
*
* @param AnnotatedInterface $model if want to insert different model than set in constructor
* @return boolean whether the attributes are valid and the record is inserted successfully.
* @throws ManganException if the record is not new
* @throws ManganException on fail of insert or insert of empty document
* @throws ManganException on fail of insert, when safe flag is set to true
* @throws ManganException on timeout of db operation , when safe flag is set to true
* @since v1.0
*/
public function insert(AnnotatedInterface $model = null);
/**
* Updates the document represented by this active record.
* All loaded attributes will be saved to the database.
*
* Note, validation is not performed in this method. You may call {@link validate} to perform the validation.
*
* @param array $attributes list of attributes that need to be updated. Defaults to null,
* meaning all attributes that are loaded from DB will be saved.
* @return boolean whether the update is successful
* @throws ManganException if the record is new
* @throws ManganException on fail of update
* @throws ManganException on timeout of db operation , when safe flag is set to true
* @since v1.0
*/
public function update(array $attributes = null);
/**
* Updates one document with the specified criteria and attributes
*
* This is more *raw* update:
*
* * Does not raise any events or signals
* * Does not perform any validation
*
* @param array|CriteriaInterface $criteria query criteria.
* @param array $attributes list of attributes that need to be saved. Defaults to null,
* meaning all attributes that are loaded from DB will be saved.
* @param bool Whether tu force update/upsert document
* @since v1.0
*/
public function updateOne($criteria = null, array $attributes = null, $modify = false);
/**
* Atomic, in-place update method.
*
* @since v1.3.6
* @param Modifier $modifier updating rules to apply
* @param CriteriaInterface $criteria condition to limit updating rules
* @return boolean|mixed[]
*/
public function updateAll(Modifier $modifier, CriteriaInterface $criteria = null);
/**
* Saves the current record. Will insert new document, or update if exists.
*
* Validation will be performed before saving the document. If the validation fails,
* the record will not be saved. You can call {@link getErrors()} to retrieve the
* validation errors.
*
* @param boolean $runValidation whether to perform validation before saving the record.
* If the validation fails, the record will not be saved to database.
* @return boolean whether the saving succeeds
* @since v1.0
*/
public function save($runValidation = true);
/**
* Updates or inserts the current document. This will try to update existing fields.
* Will keep already stored data if present in document.
*
* If document does not exist, a new one will be inserted.
*
* @param boolean $runValidation
* @return boolean
* @throws ManganException
*/
public function upsert($runValidation = true);
/**
* Deletes the row corresponding to this Document.
*
* @return boolean whether the deletion is successful.
* @throws ManganException if the record is new
* @since v1.0
*/
public function delete();
/**
* Deletes one document with the specified primary key or by passed criteria.
*
* This is more *raw* method than delete:
*
* * Does not raise events
* * Does not emit signals
*
* See `Criteria` class for detailed explanation about $criteria param.
* @param array|CriteriaInterface $criteria query criteria.
* @see Criteria
* @see CriteriaInterface
* @since v1.0
*/
public function deleteOne($criteria = null);
/**
* Deletes document with the specified primary key with optional criteria.
*
* See `Criteria` class for detailed explanation about $criteria param.
*
* @param mixed $pkValue primary key value(s). Use array for multiple primary keys. For composite key, each key value must be an array (column name=>column value).
* @param array|CriteriaInterface $criteria query criteria.
* @see Criteria
* @see CriteriaInterface
* @since v1.0
*/
public function deleteByPk($pkValue, $criteria = null);
/**
* Deletes documents with the specified primary keys.
*
* See `Criteria` class for detailed explanation about $criteria param.
*
* @param mixed[] $pkValues Primary keys array
* @param array|CriteriaInterface $criteria query criteria.
* @see Criteria
* @see CriteriaInterface
* @since v1.0
*/
public function deleteAllByPk($pkValues, $criteria = null);
/**
* Deletes all documents specified by criteria.
*
* See `Criteria` class for detailed explanation about $criteria param.
*
* @param array|CriteriaInterface $criteria query criteria.
* @see Criteria
* @see CriteriaInterface
* @since v1.0
*/
public function deleteAll($criteria = null);
/**
* Repopulates this active record with the latest data.
*
* @return boolean whether the row still exists in the database. If true, the latest data will be populated to this active record.
* @since v1.0
*/
public function refresh();
/**
* Get mongodb collection
* @return MongoCollection PHP Driver MongoCollection instance
*/
public function getCollection();
}
API documentation generated by ApiGen