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; |
21
|
|
|
|
22
|
|
|
use Doctrine\Common\Persistence\Mapping\ClassMetadata; |
23
|
|
|
use Doctrine\MongoDB\Aggregation\Expr as BaseExpr; |
24
|
|
|
use Doctrine\ODM\MongoDB\DocumentManager; |
25
|
|
|
use Doctrine\ODM\MongoDB\Types\Type; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Fluent interface for building aggregation pipelines. |
29
|
|
|
*/ |
30
|
|
|
class Expr extends BaseExpr |
31
|
|
|
{ |
32
|
|
|
/** |
33
|
|
|
* @var DocumentManager |
34
|
|
|
*/ |
35
|
|
|
private $dm; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var ClassMetadata |
39
|
|
|
*/ |
40
|
|
|
private $class; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @inheritDoc |
44
|
|
|
*/ |
45
|
4 |
|
public function __construct(DocumentManager $dm, ClassMetadata $class) |
46
|
|
|
{ |
47
|
4 |
|
$this->dm = $dm; |
48
|
4 |
|
$this->class = $class; |
49
|
4 |
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param string $fieldName |
53
|
|
|
* @return self |
54
|
|
|
*/ |
55
|
4 |
|
public function field($fieldName) |
56
|
|
|
{ |
57
|
4 |
|
$fieldName = $this->getDocumentPersister()->prepareFieldName($fieldName); |
58
|
|
|
|
59
|
4 |
|
parent::field($fieldName); |
60
|
|
|
|
61
|
4 |
|
return $this; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @param mixed|self $expression |
66
|
|
|
* @return mixed |
67
|
|
|
*/ |
68
|
|
|
protected function ensureArray($expression) |
69
|
|
|
{ |
70
|
|
|
// Convert field names in expressions |
71
|
|
|
if (is_string($expression) && substr($expression, 0, 1) === '$') { |
72
|
|
|
return '$' . $this->getDocumentPersister()->prepareFieldName(substr($expression, 1)); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
// Convert PHP types to MongoDB types for everything else |
76
|
|
|
return Type::convertPHPToDatabaseValue(parent::ensureArray($expression)); |
|
|
|
|
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @return \Doctrine\ODM\MongoDB\Persisters\DocumentPersister |
81
|
|
|
*/ |
82
|
4 |
|
private function getDocumentPersister() |
83
|
|
|
{ |
84
|
4 |
|
return $this->dm->getUnitOfWork()->getDocumentPersister($this->class->name); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
This method has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.