-
-
Notifications
You must be signed in to change notification settings - Fork 99
/
Copy pathDocumentManager.php
933 lines (806 loc) · 26.3 KB
/
DocumentManager.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
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
<?php
/*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the MIT license. For more information, see
* <http://www.doctrine-project.org>.
*/
namespace Doctrine\ODM\PHPCR;
use Doctrine\ODM\PHPCR\Exception\ClassMismatchException;
use Doctrine\ODM\PHPCR\Exception\InvalidArgumentException;
use Doctrine\ODM\PHPCR\Mapping\ClassMetadataFactory;
use Doctrine\ODM\PHPCR\Proxy\ProxyFactory;
use Doctrine\ODM\PHPCR\Repository\RepositoryFactory;
use Doctrine\ODM\PHPCR\Translation\TranslationStrategy\TranslationStrategyInterface;
use Doctrine\ODM\PHPCR\Translation\TranslationStrategy\AttributeTranslationStrategy;
use Doctrine\ODM\PHPCR\Translation\TranslationStrategy\ChildTranslationStrategy;
use Doctrine\ODM\PHPCR\Translation\LocaleChooser\LocaleChooserInterface;
use Doctrine\ODM\PHPCR\Query\Query;
use Doctrine\ODM\PHPCR\Query\Builder\QueryBuilder;
use Doctrine\ODM\PHPCR\Query\Builder\ConverterPhpcr;
use Doctrine\Common\EventManager;
use Doctrine\Common\Persistence\ObjectManager;
use Doctrine\Common\Collections\ArrayCollection;
use PHPCR\SessionInterface;
use PHPCR\Query\QueryInterface;
use PHPCR\UnsupportedRepositoryOperationException;
use PHPCR\Util\UUIDHelper;
use PHPCR\PropertyType;
use PHPCR\Util\QOM\QueryBuilder as PhpcrQueryBuilder;
use PHPCR\ItemNotFoundException;
use PHPCR\PathNotFoundException;
use PHPCR\Util\ValueConverter;
/**
* Document Manager
*
* @author Jordi Boggiano <[email protected]>
* @author Pascal Helfenstein <[email protected]>
* @author Daniel Barsotti <[email protected]>
* @author David Buchmann <[email protected]>
*/
class DocumentManager implements DocumentManagerInterface
{
/**
* @var SessionInterface
*/
private $session;
/**
* @var Configuration
*/
private $config;
/**
* @var ClassMetadataFactory
*/
private $metadataFactory;
/**
* @var UnitOfWork
*/
private $unitOfWork = null;
/**
* @var ProxyFactory
*/
private $proxyFactory = null;
/**
* The repository factory used to create dynamic repositories.
*
* @var RepositoryFactory
*/
private $repositoryFactory;
/**
* @var EventManager
*/
private $evm;
/**
* Whether the DocumentManager is closed or not.
*
* @var bool
*/
private $closed = false;
/**
* @var TranslationStrategyInterface[]
*/
protected $translationStrategy;
/**
* @var LocaleChooserInterface
*/
protected $localeChooserStrategy;
public function __construct(SessionInterface $session, Configuration $config = null, EventManager $evm = null)
{
$this->session = $session;
$this->config = $config ?: new Configuration();
$this->evm = $evm ?: new EventManager();
$metadataFactoryClassName = $this->config->getClassMetadataFactoryName();
$this->metadataFactory = new $metadataFactoryClassName($this);
$this->unitOfWork = new UnitOfWork($this);
$this->valueConverter = new ValueConverter();
$this->proxyFactory = new ProxyFactory($this,
$this->config->getProxyDir(),
$this->config->getProxyNamespace(),
$this->config->getAutoGenerateProxyClasses()
);
$this->repositoryFactory = $this->config->getRepositoryFactory();
// initialize default translation strategies
$this->translationStrategy = array(
AttributeTranslationStrategy::NAME => new AttributeTranslationStrategy($this),
ChildTranslationStrategy::NAME => new ChildTranslationStrategy($this),
);
}
/**
* {@inheritDoc}
*/
public function setTranslationStrategy($key, TranslationStrategyInterface $strategy)
{
$this->translationStrategy[$key] = $strategy;
}
/**
* {@inheritDoc}
*/
public function getTranslationStrategy($key)
{
if (!isset($this->translationStrategy[$key])) {
throw new InvalidArgumentException("You must set a valid translator strategy for a document that contains translatable fields ($key is not a valid strategy or was not previously registered)");
}
return $this->translationStrategy[$key];
}
/**
* {@inheritDoc}
*/
public function hasLocaleChooserStrategy()
{
return isset($this->localeChooserStrategy);
}
/**
* {@inheritDoc}
*/
public function getLocaleChooserStrategy()
{
if (!isset($this->localeChooserStrategy)) {
throw new InvalidArgumentException("You must configure a language chooser strategy when having documents with the translatable annotation");
}
return $this->localeChooserStrategy;
}
/**
* {@inheritDoc}
*/
public function setLocaleChooserStrategy(LocaleChooserInterface $strategy)
{
$this->localeChooserStrategy = $strategy;
}
/**
* {@inheritDoc}
*/
public function getProxyFactory()
{
return $this->proxyFactory;
}
/**
* {@inheritDoc}
*/
public function getEventManager()
{
return $this->evm;
}
/**
* {@inheritDoc}
*/
public function getPhpcrSession()
{
return $this->session;
}
/**
* Factory method for a Document Manager.
*
* @param SessionInterface $session
* @param Configuration $config
* @param EventManager $evm
*
* @return DocumentManager
*/
public static function create(SessionInterface $session, Configuration $config = null, EventManager $evm = null)
{
return new self($session, $config, $evm);
}
/**
* {@inheritDoc}
*/
public function getMetadataFactory()
{
return $this->metadataFactory;
}
/**
* {@inheritDoc}
*/
public function getConfiguration()
{
return $this->config;
}
/**
* Throws an exception if the DocumentManager is closed or currently not active.
*
* @throws PHPCRException If the DocumentManager is closed.
*/
private function errorIfClosed()
{
if ($this->closed) {
throw PHPCRException::documentManagerClosed();
}
}
/**
* {@inheritDoc}
*/
public function isOpen()
{
return !$this->closed;
}
/**
* {@inheritDoc}
*/
public function getClassMetadata($className)
{
return $this->metadataFactory->getMetadataFor($className);
}
/**
* {@inheritDoc}
*
* Find the Document with the given id.
*
* Will return null if the document was not found. A document is considered
* not found if the data at $id is not instance of of the specified
* $className. To get the document regardless of its class, pass null.
*
* If the document is translatable, then the language chooser strategy is
* used to load the best suited language for the translatable fields.
*
* @param null|string $className optional object class name to use
* @param string $id the path or uuid of the document to find
*
* @return object|null the document if found, otherwise null
*/
public function find($className, $id)
{
if (!UUIDHelper::isUUID($id) && strpos($id, '/') !== 0) {
$id = '/'.$id;
}
// try to get a manage document
$document = $this->unitOfWork->getDocumentByPathOrUuid($id);
if ($document) {
try {
$this->unitOfWork->validateClassName($document, $className);
return $document;
} catch (ClassMismatchException $e) {
return null;
}
}
// get the node
try {
$node = $this->unitOfWork->getNodeByPathOrUuid($id);
} catch (PathNotFoundException $e) {
return null;
} catch (ItemNotFoundException $e) {
return null;
}
$hints = array('fallback' => true);
try {
return $this->unitOfWork->getOrCreateDocument($className, $node, $hints);
} catch (ClassMismatchException $e) {
return null;
}
}
/**
* {@inheritDoc}
*/
public function findMany($className, array $ids)
{
$uuids = array();
foreach ($ids as $key => $id) {
if (UUIDHelper::isUUID($id)) {
$uuids[$id] = $key;
} elseif (strpos($id, '/') !== 0) {
$ids[$key] = '/'.$id;
}
}
if (!empty($uuids)) {
$nodes = $this->session->getNodesByIdentifier(array_keys($uuids));
foreach ($nodes as $node) {
/** @var $node \PHPCR\NodeInterface */
$id = $node->getPath();
$ids[$uuids[$node->getIdentifier()]] = $id;
unset($uuids[$id]);
}
if (!empty($uuids)) {
// skip not found ids
$ids = array_diff($ids, array_keys($uuids));
}
}
$nodes = $this->session->getNodes($ids);
$hints = array('fallback' => true);
$documents = $this->unitOfWork->getOrCreateDocuments($className, $nodes, $hints);
return new ArrayCollection($documents);
}
/**
* {@inheritDoc}
*/
public function findTranslation($className, $id, $locale, $fallback = true)
{
try {
if (UUIDHelper::isUUID($id)) {
try {
$id = $this->session->getNodeByIdentifier($id)->getPath();
} catch (ItemNotFoundException $e) {
return null;
}
} elseif (strpos($id, '/') !== 0) {
$id = '/'.$id;
}
$document = $this->unitOfWork->getDocumentByPathOrUuid($id);
if ($document) {
$this->unitOfWork->validateClassName($document, $className);
$class = $this->getClassMetadata(get_class($document));
$this->unitOfWork->doLoadTranslation($document, $class, $locale, $fallback);
return $document;
}
$node = $this->session->getNode($id);
} catch (PathNotFoundException $e) {
return null;
}
$hints = array('locale' => $locale, 'fallback' => $fallback);
return $this->unitOfWork->getOrCreateDocument($className, $node, $hints);
}
/**
* {@inheritDoc}
*/
public function getRepository($className)
{
return $this->repositoryFactory->getRepository($this, $className);
}
/**
* {@inheritDoc}
*/
public function quote($val, $type = PropertyType::STRING)
{
if (null !== $type) {
$val = $this->valueConverter->convertType($val, $type);
}
return "'".str_replace("'", "''", $val)."'";
}
/**
* {@inheritDoc}
*/
public function escapeFullText($string)
{
$illegalCharacters = array(
'!' => '\\!', '(' => '\\(', ':' => '\\:', '^' => '\\^',
'[' => '\\[', ']' => '\\]', '{' => '\\{', '}' => '\\}',
'\"' => '\\\"', '?' => '\\?', "'" => "''",
);
return strtr($string, $illegalCharacters);
}
/**
* {@inheritDoc}
*/
public function createPhpcrQuery($statement, $language)
{
$qm = $this->session->getWorkspace()->getQueryManager();
return $qm->createQuery($statement, $language);
}
/**
* {@inheritDoc}
*/
public function createQuery($statement, $language)
{
$phpcrQuery = $this->createPhpcrQuery($statement, $language);
return new Query($phpcrQuery, $this);
}
/**
* {@inheritDoc}
*/
public function createQueryBuilder()
{
$qm = $this->session->getWorkspace()->getQueryManager();
$qomf = $qm->getQOMFactory();
$converter = new ConverterPhpcr($this, $qomf);
$builder = new QueryBuilder();
$builder->setConverter($converter);
return $builder;
}
/**
* {@inheritDoc}
*/
public function createPhpcrQueryBuilder()
{
$qm = $this->session->getWorkspace()->getQueryManager();
return new PhpcrQueryBuilder($qm->getQOMFactory());
}
/**
* {@inheritDoc}
*/
public function getDocumentsByPhpcrQuery(QueryInterface $query, $className = null, $primarySelector = null)
{
$this->errorIfClosed();
$result = $query->execute();
$ids = array();
foreach ($result->getRows() as $row) {
/** @var $row \PHPCR\Query\RowInterface */
$ids[] = $row->getPath($primarySelector);
}
return $this->findMany($className, $ids);
}
/**
* {@inheritDoc}
*
* No PHPCR node will be created yet, this only happens on flush.
*
* For translatable documents has to determine the locale:
*
* - If there is a non-empty Locale mapping that field value is used
* - If the document was previously loaded from the DocumentManager it
* has a non-empty Locale mapping
* - Otherwise its a new document. The language chooser strategy is asked
* for the default language and that is used to store. The field is
* updated with the locale.
*
* @param object $document the document to persist
*
* @throws InvalidArgumentException if $document is not an object.
*/
public function persist($document)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
}
$this->errorIfClosed();
$this->unitOfWork->scheduleInsert($document);
}
/**
* {@inheritDoc}
*/
public function bindTranslation($document, $locale)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
}
$this->errorIfClosed();
$this->unitOfWork->bindTranslation($document, $locale);
}
/**
* {@inheritDoc}
*/
public function removeTranslation($document, $locale)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
}
$this->errorIfClosed();
$this->unitOfWork->removeTranslation($document, $locale);
}
/**
* {@inheritDoc}
*/
public function getLocalesFor($document, $includeFallbacks = false)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
}
$this->errorIfClosed();
$metadata = $this->getClassMetadata(get_class($document));
$locales = $this->unitOfWork->getLocalesFor($document);
if ($includeFallbacks) {
$fallBackLocales = array();
foreach ($locales as $locale) {
$fallBackLocales = array_merge($fallBackLocales, $this->localeChooserStrategy->getFallbackLocales($document, $metadata, $locale));
}
$locales = array_unique(array_merge($locales, $fallBackLocales));
}
return $locales;
}
/**
* {@inheritDoc}
*/
public function isDocumentTranslatable($document)
{
$metadata = $this->getClassMetadata(get_class($document));
return $this->unitOfWork->isDocumentTranslatable($metadata);
}
/**
* {@inheritDoc}
*/
public function move($document, $targetPath)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
}
if (strpos($targetPath, '/') !== 0) {
$targetPath = '/'.$targetPath;
}
$this->errorIfClosed();
$this->unitOfWork->scheduleMove($document, $targetPath);
}
/**
* {@inheritDoc}
*/
public function reorder($document, $srcName, $targetName, $before)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
}
$this->errorIfClosed();
$this->unitOfWork->scheduleReorder($document, $srcName, $targetName, $before);
}
/**
* {@inheritDoc}
*
* Remove the previously persisted document and all its children from the tree
*
* Be aware of the PHPCR tree structure: this removes all nodes with a path under
* the path of this object, even if there are no Parent / Child mappings
* that make the relationship explicit.
*
* @param object $document
*
* @throws InvalidArgumentException if $document is not an object.
*/
public function remove($document)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
}
$this->errorIfClosed();
$this->unitOfWork->scheduleRemove($document);
}
/**
* {@inheritDoc}
*
* Merge the state of the detached object into the persistence context of
* this ObjectManager and returns the managed copy of the object.
*
* This will copy all fields of $document over the fields of the managed
* document and then cascade the merge to relations as configured.
*
* The object passed to merge will *not* become associated/managed with
* this ObjectManager.
*
* @param object $document The document to merge over a persisted document
* with the same id.
*
* @return object The managed document where $document has been merged
* into. This is *not* the same instance as the parameter.
*
* @throws InvalidArgumentException if $document is not an object.
*/
public function merge($document)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
}
$this->errorIfClosed();
return $this->unitOfWork->merge($document);
}
/**
* {@inheritDoc}
*
* Detaches an object from the ObjectManager
*
* If there are any not yet flushed changes on this object (including
* removal of the object) will not be synchronized to the database.
* Objects which previously referenced the detached object will continue to
* reference it.
*
* @param object $document The object to detach.
*
* @throws InvalidArgumentException if $document is not an object.
*/
public function detach($document)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
}
$this->errorIfClosed();
$this->unitOfWork->detach($document);
}
/**
* {@inheritDoc}
*
* Refresh the given document by querying the PHPCR to get the current state.
*
* @param object $document
*
* @throws InvalidArgumentException if $document is not an object.
*/
public function refresh($document)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
}
$this->errorIfClosed();
$this->unitOfWork->refresh($document);
}
/**
* {@inheritDoc}
*/
public function getChildren($document, $filter = null, $fetchDepth = -1, $locale = null)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
}
$this->errorIfClosed();
return new ChildrenCollection($this, $document, $filter, $fetchDepth, $locale);
}
/**
* {@inheritDoc}
*/
public function getReferrers($document, $type = null, $name = null, $locale = null, $refClass = null)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
}
$this->errorIfClosed();
return new ReferrersCollection($this, $document, $type, $name, $locale, $refClass);
}
/**
* {@inheritDoc}
*
* Flush all current changes, that is save them within the phpcr session
* and commit that session to permanent storage.
*
* @param object|array|null $document optionally limit to a specific
* document or an array of documents
*
* @throws InvalidArgumentException if $document is neither null nor a
* document or an array of documents
*/
public function flush($document = null)
{
if (null !== $document && !is_object($document) && !is_array($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
}
$this->errorIfClosed();
$this->unitOfWork->commit($document);
}
/**
* {@inheritDoc}
*/
public function getReference($documentName, $id)
{
return $this->unitOfWork->getOrCreateProxy($id, $documentName);
}
/**
* {@inheritDoc}
*/
public function checkin($document)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
}
$this->errorIfClosed();
$this->unitOfWork->checkin($document);
}
/**
* {@inheritDoc}
*/
public function checkout($document)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
}
$this->errorIfClosed();
$this->unitOfWork->checkout($document);
}
/**
* {@inheritDoc}
*/
public function checkpoint($document)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
}
$this->errorIfClosed();
$this->unitOfWork->checkpoint($document);
}
/**
* {@inheritDoc}
*/
public function restoreVersion($documentVersion, $removeExisting = true)
{
$this->errorIfClosed();
$this->unitOfWork->restoreVersion($documentVersion, $removeExisting);
}
/**
* {@inheritDoc}
*/
public function removeVersion($documentVersion)
{
$this->errorIfClosed();
$this->unitOfWork->removeVersion($documentVersion);
}
/**
* {@inheritDoc}
*/
public function getAllLinearVersions($document, $limit = -1)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
}
$this->errorIfClosed();
return $this->unitOfWork->getAllLinearVersions($document, $limit);
}
/**
* {@inheritDoc}
*/
public function findVersionByName($className, $id, $versionName)
{
$this->errorIfClosed();
return $this->unitOfWork->findVersionByName($className, $id, $versionName);
}
/**
* {@inheritDoc}
*
* Check if this repository contains the object
*
* @param object $document
*
* @return boolean true if the repository contains the object, false otherwise
*
* @throws InvalidArgumentException if $document is not an object.
*/
public function contains($document)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
}
return $this->unitOfWork->contains($document);
}
/**
* {@inheritDoc}
*/
public function getUnitOfWork()
{
return $this->unitOfWork;
}
/**
* {@inheritDoc}
*
* Clears the DocumentManager. All entities that are currently managed
* by this DocumentManager become detached.
*
* @param string $className
*/
public function clear($className = null)
{
if ($className === null) {
$this->unitOfWork->clear();
} else {
//TODO
throw new PHPCRException('DocumentManager#clear($className) not yet implemented.');
}
}
/**
* {@inheritDoc}
*
* Closes the DocumentManager. All entities that are currently managed
* by this DocumentManager become detached. The DocumentManager may no longer
* be used after it is closed.
*/
public function close()
{
$this->clear();
$this->closed = true;
}
/**
* {@inheritDoc}
*/
public function initializeObject($document)
{
if (!is_object($document)) {
throw new InvalidArgumentException('Parameter $document needs to be an object, '.gettype($document).' given');
}
$this->unitOfWork->initializeObject($document);
}
/**
* {@inheritDoc}
*/
public function getNodeForDocument($document)
{
if (null === $identifier = $this->unitOfWork->getDocumentId($document)) {
throw new InvalidArgumentException('This document is not managed by this manager.');
}
return $this->unitOfWork->getNodeByPathOrUuid($identifier);
}
/**
* {@inheritdoc}
*/
public function getDocumentId($document)
{
return $this->unitOfWork->getDocumentId($document);
}
}