|
1
|
|
|
<?php |
|
2
|
|
|
/* |
|
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
|
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
|
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
|
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
|
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
|
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
|
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
14
|
|
|
* |
|
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
|
16
|
|
|
* and is licensed under the MIT license. For more information, see |
|
17
|
|
|
* <http://www.doctrine-project.org>. |
|
18
|
|
|
*/ |
|
19
|
|
|
|
|
20
|
|
|
namespace Doctrine\ODM\MongoDB\Aggregation\Stage; |
|
21
|
|
|
|
|
22
|
|
|
use Doctrine\Common\Persistence\Mapping\MappingException as BaseMappingException; |
|
23
|
|
|
use Doctrine\MongoDB\Aggregation\Stage as BaseStage; |
|
24
|
|
|
use Doctrine\ODM\MongoDB\Aggregation\Builder; |
|
25
|
|
|
use Doctrine\ODM\MongoDB\DocumentManager; |
|
26
|
|
|
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata; |
|
27
|
|
|
use Doctrine\ODM\MongoDB\Mapping\MappingException; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @author alcaeus <[email protected]> |
|
31
|
|
|
*/ |
|
32
|
|
|
class Out extends BaseStage\Out |
|
33
|
|
|
{ |
|
34
|
|
|
/** |
|
35
|
|
|
* @var DocumentManager |
|
36
|
|
|
*/ |
|
37
|
|
|
private $dm; |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param Builder $builder |
|
41
|
|
|
* @param string $collection |
|
42
|
|
|
* @param DocumentManager $documentManager |
|
43
|
|
|
*/ |
|
44
|
4 |
|
public function __construct(Builder $builder, $collection, DocumentManager $documentManager) |
|
45
|
|
|
{ |
|
46
|
4 |
|
$this->dm = $documentManager; |
|
47
|
|
|
|
|
48
|
4 |
|
parent::__construct($builder, $collection); |
|
49
|
3 |
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* {@inheritdoc} |
|
53
|
|
|
*/ |
|
54
|
4 |
|
public function out($collection) |
|
55
|
|
|
{ |
|
56
|
|
|
try { |
|
57
|
4 |
|
$class = $this->dm->getClassMetadata($collection); |
|
58
|
2 |
|
} catch (BaseMappingException $e) { |
|
59
|
2 |
|
return parent::out($collection); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
2 |
|
return $this->fromDocument($class); |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
/** |
|
66
|
|
|
* @param ClassMetadata $classMetadata |
|
67
|
|
|
* @return $this |
|
68
|
|
|
* |
|
69
|
|
|
* @throws MappingException |
|
70
|
|
|
*/ |
|
71
|
2 |
|
private function fromDocument(ClassMetadata $classMetadata) |
|
72
|
|
|
{ |
|
73
|
2 |
|
if ($classMetadata->isSharded()) { |
|
74
|
1 |
|
throw MappingException::cannotUseShardedCollectionInOutStage($classMetadata->name); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
1 |
|
return parent::out($classMetadata->getCollection()); |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.