-
Notifications
You must be signed in to change notification settings - Fork 2
/
DataDogAudit.php
665 lines (590 loc) · 26.3 KB
/
DataDogAudit.php
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
<?php
namespace CubeTools\CubeCommonBundle\DataHandling\Logs;
use CubeTools\CubeCommonBundle\DataHandling\StringHelper;
use DataDog\AuditBundle\Entity\AuditLog;
use DataDog\AuditBundle\Entity\Association;
use Doctrine\ORM\EntityManagerInterface;
use Doctrine\ORM\QueryBuilder;
use Symfony\Component\Translation\TranslatorInterface;
/**
* Class handling data from DataDogAuditBundle.
*/
class DataDogAudit extends AbstractBaseAudit
{
use LogsFunctionsTrait;
const UNKNOWN_VERSION_CHANGE = 'unknown version';
const KEY_MODIFY_NEW = self::KEY_ADD;
const KEY_MODIFY_OLD = self::KEY_REMOVE;
const REMOVE_PARAMETER_NAME = ' element deleted';
const REMOVE_TEXT = 'element is deleted';
/**
* @var EntityManagerInterface
*/
protected $em;
/**
* @var mixed[] cached data for current entity type
*/
protected $cache;
/**
* @var mixed[] cached data for current entity
*/
protected $instanceCache = array();
/**
* @var DataDogAudit\AuditQueries
*/
protected $auditQueries;
/**
* @var \Symfony\Component\Translation\TranslatorInterface
*/
protected $translator;
public function __construct(EntityManagerInterface $em, TranslatorInterface $translator)
{
$this->em = $em;
$this->translator = $translator;
$this->auditQueries = new DataDogAudit\AuditQueries($em);
}
/**
* Method for getting AuditLog of all versions of given entity.
*
* Result is ordered with oldest changes first.
*
* @param object $entity entity for which we want to get all versions
*
* @return QueryBuilder
*/
protected function getAllVersionsQb($entity)
{
$class = $this->em->getMetadataFactory()->getMetadataFor(get_class($entity))->getName();
$id = $entity;
$this->instanceCache = array(
'id' => $id,
); // is only valid for one entity
if ((empty($this->cache['class'])) || ($class !== $this->cache['class'])) {
$this->cache = array('class' => $class);
}
$aQb = $this->auditQueries->createOwningSideQb($id, $class);
$assocClasses = array();
foreach ($aQb->getQuery()->getResult() as $infos) {
if ($infos['class'] !== $class) {
// avoid showing changes for parents
$assocClasses[$infos['class']][] = $infos['fk'];
}
}
$qb = $this->auditQueries->createAuditLogQb($id, $class);
foreach ($assocClasses as $assocClass => $ids) {
if ($ids) {
$this->auditQueries->extendAuditLogWithAttributeQb($qb, $assocClass, $ids);
}
}
return $qb;
}
public function getLastBlame($entity)
{
// doc is in interface
$qb = $this->getAllVersionsQb($entity);
$currentVersion = $qb->limit(1)->getQuery()->getResult();
return array(
'savedBy' => $currentVersion->getBlame() ? $currentVersion->getBlame()->getLabel() : '',
'savedAt' => $currentVersion->getLoggedAt(),
);
}
public function getFirstBlame($entity)
{
// doc is in interface
$qb = $this->getAllVersionsQb($entity);
$currentVersion = $qb->orderBy('a.id', 'DESC')->limit(1)->getQuery()->getResult();
return array(
'savedBy' => $currentVersion->getBlame() ? $currentVersion->getBlame()->getLabel() : '',
'savedAt' => $currentVersion->getLoggedAt(),
);
}
/**
* @deprecated since version 1.0.19
*
* @param object $entity
*
* @return mixed[]
*/
public function getAllVersionsDiffArray($entity)
{
@trigger_error('getAllVersionsDiffArray() is deprecated since version 1.0.19. Use getAllVersionsDiff instead.', E_USER_DEPRECATED);
$versions = array();
foreach ($this->getAllVersionsDiff($entity) as $verKey => $value) {
$versions[$verKey] = $value['changes'];
}
return $versions;
}
public function getAllVersionsDiff($entity)
{
// doc is in interface
$qb = $this->getAllVersionsQb($entity);
$outputArray = $this->auditLogToDiff($qb);
return array_reverse($outputArray, true);
}
/**
* Creates the diff format from related AuditLogs.
*
* @param AuditLog[]|iterable|QueryBuilder $entityVersions
*
* @return mixed[] {@see getAllVersionsDiff()}
*/
protected function auditLogToDiff($entityVersions)
{
$diffArray = array(self::UNKNOWN_VERSION_CHANGE => array());
if ($entityVersions instanceof QueryBuilder) {
$entityVersions = $entityVersions->getQuery()->getResult();
}
/** @var AuditLog $currentVersion */
foreach ($entityVersions as $currentVersion) {
$versionKey = $this->getVersionKey($currentVersion, $diffArray);
if (!isset($diffArray[$versionKey])) {
$diffArray[$versionKey] = array(
'changes' => array(),
'savedBy' => $currentVersion->getBlame() ? $currentVersion->getBlame()->getLabel() : '',
'savedAt' => $currentVersion->getLoggedAt(),
);
}
$changes = $this->getCurrentVersionElement($currentVersion, $diffArray[$versionKey]['changes']);
if ($changes) {
$diffArray[$versionKey]['changes'] = $changes;
} else {
unset($diffArray[$versionKey]);
}
}
return $this->filterFinalResult($diffArray);
}
public function getVersionsOfProperty($entity, $columnName)
{
// doc is in interface
$allVer = $this->getAllVersionsDiff($entity);
/*
* Could filter in db, but some properties are in diff, some are in an association.
* And only for associations: $columnName = $this->getColumnNameForAssociation($propertyName);
*/
return $this->filterLogForOneProperty($allVer, $columnName);
}
/**
* Method creating version key (to group table entries associated with the same user action).
*
* @param AuditLog $currentVersion entity for which version key is created
* @param array $diffArray subsequent elements are diff for each version
*
* @return string version key (timestamp and user id)
*/
protected function getVersionKey(AuditLog $currentVersion, array $diffArray)
{
$versionTimestamp = $currentVersion->getLoggedAt()->getTimestamp();
$versionUser = $currentVersion->getBlame() ? $currentVersion->getBlame()->getFk() : -1;
$versionKeyNormal = sprintf('%d_%d', $versionTimestamp, $versionUser); // having user and time prevent from logging in the same place simoultaneus changes from more then one user
$versionKeyBefore = sprintf('%d_%d', $versionTimestamp - 1, $versionUser); // 1 second before by the same user
$versionKeyAfter = sprintf('%d_%d', $versionTimestamp + 1, $versionUser); // 1 second after by the same user
if (isset($diffArray[$versionKeyBefore])) {
$versionKey = $versionKeyBefore;
} elseif (isset($diffArray[$versionKeyAfter])) {
$versionKey = $versionKeyAfter;
} else {
$versionKey = $versionKeyNormal;
}
return $versionKey;
}
/**
* Method creating diff for given log entry.
*
* @param AuditLog $currentVersion
* @param array $diffElement current state of diff for this version (one version can consist of more then one log entry)
*
* @return array diff element for given version
*/
protected function getCurrentVersionElement(AuditLog $currentVersion, array $diffElement)
{
if (empty($this->cache['entityTableName'])) {
$this->cache['entityTableName'] = $this->getEntitiesClassMetaData()->getTableName();
}
$entityTable = $this->cache['entityTableName'];
if ($currentVersion->getTbl() !== $entityTable && $currentVersion->getSource()->getTbl() !== $entityTable) {
// other side of association
$this->handleOtherAttributeSideChange($currentVersion, $diffElement);
} elseif (!$currentVersion->getDiff()) {
if ($currentVersion->getTarget()) {
$this->handleAssociateDissociate($currentVersion, $diffElement);
} elseif ('remove' === $currentVersion->getAction()) {
$this->removeThisEntity($currentVersion, $diffElement);
} else {
$this->logicWrong('Action '.$currentVersion->getAction().' is not supported here (with no diff).');
}
} else {
if ('insert' === $currentVersion->getAction()) {
if (!isset($this->instanceCache['insertCalled'])) {
$this->instanceCache['insertCalled'] = true;
}
} elseif (!isset($this->instanceCache['insertCalled'])) { // update/... before insert
$this->instanceCache['insertCalled'] = false;
}
foreach ($currentVersion->getDiff() as $columnName => $diffValue) {
if (isset($diffValue['new']['label'])) {
// ManyToOne relation has changed
$diffElement[$columnName] = $diffValue['new']['label'];
} else {
$diffElement[$columnName] = $diffValue['new'];
}
}
}
return $this->filterVersionElement($currentVersion, $diffElement);
}
/**
* Update the $diffElement with the change of $currentVersion of an associated class.
*
* @param AuditLog $currentVersion AuditLog of associated class
* @param array $diffElement where the result is written
*/
protected function handleOtherAttributeSideChange(AuditLog $currentVersion, array &$diffElement)
{
$id = $currentVersion->getSource()->getFk();
$assocClass = $currentVersion->getSource()->getClass();
// handle oneToMany associations
if ($currentVersion->getDiff() && isset($this->cache['oneToManyAssoc'][$assocClass])) {
/**
* @var function check if it the diff element is an association
* and if its class and foreign key match the current entity
*/
$isThisEntity = function ($check) {
return is_array($check) && $check['class'] === $this->cache['class'] && $check['fk'] === $this->instanceCache['id'];
};
foreach ($currentVersion->getDiff() as $fieldName => $fieldChange) {
if ($isThisEntity($fieldChange['new'])) { //associate, set registered to 1
$assocAttrName = $this->getAttributeNameFor1toN($currentVersion, $fieldName);
$this->instanceCache['currentAttributes'][$assocClass][$id][$assocAttrName] = 1;
}
if ($isThisEntity($fieldChange['old'])) { //dissociate, delete registration (registered is always 1)
$assocAttrName = $this->getAttributeNameFor1toN($currentVersion, $fieldName);
unset($this->instanceCache['currentAttributes'][$assocClass][$id][$assocAttrName]);
}
}
}
if (empty($this->instanceCache['currentAttributes'][$assocClass][$id])) {
return; // currently no attribute associated
}
$label = $this->getLabelForAssociation($currentVersion->getSource());
$oldLabel = $this->getCachedAssociationValue($currentVersion->getSource(), false);
if ($label !== $oldLabel) {
// a real change
} elseif (strlen($label) === 255) {
// limitation: if the label is trucated, the change is maybe hidden
// therefore currently show anyway
} else {
return; // change not visible to this entity
}
// update the label for all registered attributes
foreach ($this->instanceCache['currentAttributes'][$assocClass][$id] as $attrName => $registered) {
if ($registered <= 0) {
continue; // currently not associated => next $attrName
}
$this->setCachedAssociationValue($currentVersion->getSource(), $label);
$diffElement[$attrName][self::KEY_MODIFY_NEW][$id] = $label;
$diffElement[$attrName][self::KEY_MODIFY_OLD][$id] = $oldLabel;
}
}
/**
* Update the $diffElement with the change of $currentVersion of an assiciation change.
*
* @param AuditLog $currentVersion AuditLog with associate / dissociate (source is this class)
* @param array $diffElement where the result is written
*/
protected function handleAssociateDissociate(AuditLog $currentVersion, array &$diffElement)
{
if ('associate' === $currentVersion->getAction()) {
$id = $currentVersion->getTarget()->getFk();
$assocClass = $currentVersion->getTarget()->getClass();
$columnName = $this->getAttributeNameForNtoN($currentVersion);
if (empty($this->instanceCache['currentAttributes'][$assocClass][$id][$columnName])) {
// currently not yet registered => set as change (associate)
$label = $this->getLabelForAssociation($currentVersion->getTarget());
$diffElement[$columnName][self::KEY_ADD][$id] = $label;
$this->instanceCache['currentAttributes'][$assocClass][$id][$columnName] = 1;
$this->setCachedAssociationValue($currentVersion->getSource(), $label);
} else {
// already registered (because of associate before dissociate) => only update registered count
++$this->instanceCache['currentAttributes'][$assocClass][$id][$columnName];
}
} elseif ('dissociate' === $currentVersion->getAction()) {
$id = $currentVersion->getTarget()->getFk();
$assocClass = $currentVersion->getTarget()->getClass();
$columnName = $this->getAttributeNameForNtoN($currentVersion);
if (isset($this->instanceCache['currentAttributes'][$assocClass][$id][$columnName])) {
$registered = --$this->instanceCache['currentAttributes'][$assocClass][$id][$columnName];
} else { // auditLog was likely enabled after entity creation
$this->instanceCache['currentAttributes'][$assocClass][$id][$columnName] = 0;
$registered = 0;
}
if (0 === $registered) {
// no more registered => set as change (dissociate)
$oldLabel = $this->getLabelForAssociation($currentVersion->getTarget());
$diffElement[$columnName][self::KEY_REMOVE][$id] = $oldLabel;
if (isset($diffElement[$columnName][self::KEY_ADD][$id]) &&
$oldLabel === $diffElement[$columnName][self::KEY_ADD][$id] &&
empty($this->instanceCache['insertCalled'])
) { // likely associate + dissociate the same, when 1st association is missing
// write this once (as uncertainity), then go to a stable level
$this->instanceCache['currentAttributes'][$assocClass][$id][$columnName] = 1;
}
} elseif ($registered < 0) {
$this->logicWrong('registered for "'.$columnName.'" may not be < 0. It is '.$registered);
$this->instanceCache['currentAttributes'][$assocClass][$id][$columnName] = 0;
}
} else {
$this->logicWrong('Action '.$currentVersion->getAction().' is not supported by this method.');
}
}
/**
* Note in the $diffElement the removal of the logged entity.
*
* @todo Select a good default behaviour, current one may be unhandy. Unstable functionality!
* Default behaviour:
*
* Writes in the $diffElement that the value is deleted.
* What is written instead of a parameter name can be configured by `$options['parameter_name']` (default is
* `static::REMOVE_PARAMETER_NAME`). The text used instad of a parameter value is read from
* $options['parameter_value']
*
* Removing other changes noted for the same time is disabled (enable by setting `$options['only_remove']` to true).
*
* Associations are not tracked any longer (to track on, set $options['track_attributes'] = true).
*
* Can be override for customization needs.
*
* @param AuditLog $currentVersion AuditLog with associate / dissociate (source is this class)
* @param array $diffElement where the result is written
* @param array $options empty normally, for simple adapting by callling from subclasses
*/
protected function removeThisEntity(AuditLog $currentVersion, array &$diffElement, array $options = array())
{
if (isset($options['only_remove']) && false === $options['only_remove']) {
$diffElement = array();
}
$key = isset($options['parameter_name']) ? $options['parameter_name'] : static::REMOVE_PARAMETER_NAME;
$value = isset($options['parameter_value']) ? $options['parameter_value'] : static::REMOVE_TEXT;
$diffElement[$key] = $value;
if (!empty($options['track_attributes'])) {
$this->instanceCache['currentAttributes'] = array();
}
}
/**
* Filter the result before returning.
*
* @param array $diffArray subsequent elements are diff for each version
*
* @return array subsequent elements are diff for each version, filtered
*/
protected function filterFinalResult(array $diffArray)
{
if ((empty($this->instanceCache['insertCalled']) && // insert not called &&
isset($this->instanceCache['insertCalled'])) // value is false => data was added
) {
// insert call missing, incomplete log => update placeholder
$diffArray[self::UNKNOWN_VERSION_CHANGE] = array(
'changes' => array(' ' => 'unknown document versions before'),
'savedBy' => 'UNKNOWN USER',
'savedAt' => new \DateTime('1970-01-01 00:00'),
);
} else {
unset($diffArray[self::UNKNOWN_VERSION_CHANGE]); // complete log, remove placeholder
}
foreach ($diffArray as $versionKey => $versionValue) {
foreach (array_keys($versionValue['changes']) as $columnName) {
$currentElement = $diffArray[$versionKey]['changes'][$columnName];
if (is_array($currentElement)) {
// call custom filter for values containing several elements (manyToMany associations)
$filteredProp = $this->filterMultiValueProperty($versionValue['changes'][$columnName], $columnName);
if (array() === $filteredProp) { // cleared
unset($versionValue['changes'][$columnName]);
} else { // still a value, may even change the type to scalar
$versionValue['changes'][$columnName] = $filteredProp;
}
}
}
if ($versionValue['changes']) {
// call custom filter for value of each property
$filtered = $this->filterVersionChange($versionValue['changes']);
} else {
$filtered = null; // mark for remove
}
if (!$filtered) {
unset($diffArray[$versionKey]);
} else {
$diffArray[$versionKey]['changes'] = $filtered;
}
}
return $diffArray;
}
/**
* Method for getting key storing information about given on input column name with association. Can be override for customization needs.
*
* @param AuditLog $currentVersion
*
* @return string|null name
*/
protected function getColumnNameForAssociation(AuditLog $currentVersion)
{
return null; // => use default name
}
protected function getAttributeNameForNtoN(AuditLog $currentVersion)
{
$name = $this->getColumnNameForAssociation($currentVersion);
if (is_string($name)) {
return $name;
}
$joinTableName = $currentVersion->getTbl();
if (isset($this->cache['assocTable'][$joinTableName])) {
return $this->cache['assocTable'][$joinTableName];
}
foreach ($this->getEntitiesClassMetaData()->getAssociationMappings() as $assMapping) {
if (!empty($assMapping['joinTable'])) {
$assJoinTable = $assMapping['joinTable']['name'];
$this->cache['assocTable'][$assJoinTable] = $assMapping['fieldName'];
if ($joinTableName === $assJoinTable) {
return $assMapping['fieldName'];
}
}
}
$this->logicWrong(sprintf('no association for %s found.', $joinTableName));
return ' '.$currentVersion->getTbl(); // some fallback
}
protected function getAttributeNameFor1toN(AuditLog $currentVersion, $otherAttrName)
{
$name = $this->getColumnNameForAssociation($currentVersion);
if (is_string($name)) {
return $name;
}
$attrClass = $currentVersion->getSource()->getClass();
return $this->cache['oneToManyAssoc'][$attrClass][$otherAttrName];
}
/**
* Get the label of an association. Can be overridden for customization needs.
*
* @param Association $assoc
*
* @return string
*/
protected function getLabelForAssociation(Association $assoc)
{
return StringHelper::indicateStrippedKeepSize($assoc->getLabel(), 255); // 255 is the labels column size
}
/**
* Method for filtering diff element. Can be override for customization needs.
*
* May be called multiple times for one change.
*
* @param AuditLog $currentVersion
* @param array $diffElement
*
* @return array filtered diff element
*/
protected function filterVersionElement(AuditLog $currentVersion, array $diffElement)
{
return $diffElement;
}
/**
* Get data for attributes the entity is not the owning side.
*
* @param object $entity doctrine entity object
* @param string $attribute name of attribute to get
* @param mixed[][] $additionalConditions array(array('attr' => attrName, 'value' => value), ...)
*
* @return array array('class'=> classOfAttribute, 'ids' => array(id1, id2, ...))
*/
protected function getInverseSideAttributeIds($entity, $attribute, $additionalConditions = array())
{
$entId = $entity->getId();
$entClass = $this->em->getMetadataFactory()->getMetadataFor(get_class($entity))->getName();
$entMeta = $this->em->getClassMetadata($entClass);
if (isset($entMeta->getAssociationMapping($attribute)['joinTable'])) {
throw new \LogicException(sprintf(
'ManyToMany associations (for attribute %s) are not supported by this method',
$attribute
));
}
$attrClass = $entMeta->getAssociationMapping($attribute)['targetEntity'];
$entInAttr = $entMeta->getAssociationMapping($attribute)['mappedBy'];
$qb = $this->auditQueries->create1toNAssociationQb($attrClass, $entInAttr, $entClass, $entId);
$this->auditQueries->extend1toNAssociationQb($qb, $additionalConditions);
$candidates = $qb->getQuery()->getResult();
/// checking real values
$matchingIds = array();
/** @var AuditLog $candidate */
foreach ($candidates as $candidate) {
$diff = $candidate->getDiff();
if ($diff[$entInAttr]['new']['class'] !== $entClass || $diff[$entInAttr]['new']['fk'] != $entId) {
continue; // wrong class/id => next candidate (id may have type string or int)
}
foreach ($additionalConditions as $condition) {
if ($condition['value'] !== $diff[$condition['attr']]['new']) {
continue 2; // condition not fulfilled => next candidate
}
}
$matchingIds[] = $candidate->getSource()->getFk();
}
// register attribute name for lookup in {@see getAttributeNameFor1toN()}
$this->cache['oneToManyAssoc'][$attrClass][$entInAttr] = $attribute;
return array('class' => $attrClass, 'ids' => $matchingIds);
}
/**
* Extends the QueryBuilder from getAllVersionsQb with logs of attributes the entity is not the owning side.
*
* @param QueryBuilder $qb
* @param string $attributeClass probably ->getInverseSideAttributeIds()['class']
* @param int[] $ids probably ->getInverseSideAttributeIds()['ids']
*/
protected function extendQbWithInverseSideAttribute(QueryBuilder $qb, $attributeClass, $ids)
{
if ($ids) {
$this->auditQueries->extendAuditLogWithAttributeQb($qb, $attributeClass, $ids);
}
}
/**
* Reports a non-fatal logic exception, only shown in debug mode.
*
* @param string $message
*/
protected function logicWrong($message)
{
trigger_error('LogicException: '.$message, E_USER_WARNING);
}
/**
* Returns doctrines metadata for the main entity.
*
* @return \Doctrine\ORM\Mapping\ClassMetadata
*/
private function getEntitiesClassMetaData()
{
return $this->em->getClassMetadata($this->cache['class']);
}
/**
* Caches a value as current.
*
* @param Association $assoc
* @param string $value
*/
private function setCachedAssociationValue(Association $assoc, $value)
{
$this->instanceCache['assocCurrentValues'][$assoc->getTbl()][$assoc->getFk()] = $value;
}
/**
* Gets a cached current value, and optionally deletes it.
*
* @param Association $assoc
* @param bool $delete
*
* @return string the cached current value
*/
private function getCachedAssociationValue(Association $assoc, $delete)
{
if (!isset($this->instanceCache['assocCurrentValues'][$assoc->getTbl()][$assoc->getFk()])) {
return;
}
$value = $this->instanceCache['assocCurrentValues'][$assoc->getTbl()][$assoc->getFk()];
if ($delete) {
unset($this->instanceCache['assocCurrentValues'][$assoc->getTbl()][$assoc->getFk()]);
}
return $value;
}
}