本文整理汇总了PHP中Doctrine\ODM\MongoDB\Mapping\ClassMetadata::hasDiscriminator方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::hasDiscriminator方法的具体用法?PHP ClassMetadata::hasDiscriminator怎么用?PHP ClassMetadata::hasDiscriminator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::hasDiscriminator方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addDiscriminatorToPreparedQuery
/**
* Adds discriminator criteria to an already-prepared query.
*
* This method should be used once for query criteria and not be used for
* nested expressions. It should be called before
* {@link DocumentPerister::addFilterToPreparedQuery()}.
*
* @param array $preparedQuery
* @return array
*/
public function addDiscriminatorToPreparedQuery(array $preparedQuery)
{
/* If the class has a discriminator field, which is not already in the
* criteria, inject it now. The field/values need no preparation.
*/
if ($this->class->hasDiscriminator() && !isset($preparedQuery[$this->class->discriminatorField])) {
$discriminatorValues = $this->getClassDiscriminatorValues($this->class);
$preparedQuery[$this->class->discriminatorField] = array('$in' => $discriminatorValues);
}
return $preparedQuery;
}
示例2: prepareInsertData
/**
* Prepares insert data for document
*
* @param mixed $document
* @return array
*/
public function prepareInsertData($document)
{
$oid = spl_object_hash($document);
$changeset = $this->uow->getDocumentChangeSet($document);
$insertData = array();
foreach ($this->class->fieldMappings as $mapping) {
if (isset($mapping['notSaved']) && $mapping['notSaved'] === true) {
continue;
}
$new = isset($changeset[$mapping['fieldName']][1]) ? $changeset[$mapping['fieldName']][1] : null;
if ($new === null && $mapping['nullable'] === false) {
continue;
}
if ($this->class->isIdentifier($mapping['fieldName'])) {
$insertData['_id'] = $this->prepareValue($mapping, $new);
continue;
}
$value = $this->prepareValue($mapping, $new);
if ($value === null && $mapping['nullable'] === false) {
continue;
}
$insertData[$mapping['name']] = $value;
if (isset($mapping['reference'])) {
$scheduleForUpdate = false;
if ($mapping['type'] === 'one') {
if (!isset($insertData[$mapping['name']][$this->cmd . 'id'])) {
$scheduleForUpdate = true;
}
} elseif ($mapping['type'] === 'many') {
foreach ($insertData[$mapping['name']] as $ref) {
if (!isset($ref[$this->cmd . 'id'])) {
$scheduleForUpdate = true;
break;
}
}
}
if ($scheduleForUpdate) {
unset($insertData[$mapping['name']]);
$id = spl_object_hash($document);
$this->documentsToUpdate[$id] = $document;
$this->fieldsToUpdate[$id][$mapping['fieldName']] = array($mapping, $new);
}
}
}
// add discriminator if the class has one
if ($this->class->hasDiscriminator()) {
$insertData[$this->class->discriminatorField['name']] = $this->class->discriminatorValue;
}
return $insertData;
}
示例3: prepareQuery
/**
* Prepares a query and converts values to the types mongodb expects.
*
* @param string|array $query
* @return array $query
*/
public function prepareQuery($query)
{
if (is_scalar($query)) {
$query = array('_id' => $query);
}
if ($this->class->hasDiscriminator() && !isset($query[$this->class->discriminatorField['name']])) {
$discriminatorValues = $this->getClassDiscriminatorValues($this->class);
$query[$this->class->discriminatorField['name']] = array('$in' => $discriminatorValues);
}
$newQuery = array();
foreach ($query as $key => $value) {
$value = $this->prepareQueryValue($key, $value);
$newQuery[$key] = $value;
}
return $newQuery;
}
示例4: prepareQuery
/**
* Prepares a query array by converting the portable Doctrine types to the types mongodb expects.
*
* @param string|array $query
* @return array $newQuery
*/
public function prepareQuery($query)
{
if (is_scalar($query) || $query instanceof \MongoId) {
$query = array('_id' => $query);
}
if ($this->class->hasDiscriminator() && !isset($query[$this->class->discriminatorField['name']])) {
$discriminatorValues = $this->getClassDiscriminatorValues($this->class);
$query[$this->class->discriminatorField['name']] = array('$in' => $discriminatorValues);
}
$newQuery = array();
if ($query) {
foreach ($query as $key => $value) {
if (isset($key[0]) && $key[0] === $this->cmd && is_array($value)) {
$newQuery[$key] = $this->prepareSubQuery($value);
} else {
$newQuery[$key] = $this->prepareQueryElement($key, $value, null, true);
}
}
$newQuery = $this->convertTypes($newQuery);
}
return $newQuery;
}
示例5: serializeClassNameAndDiscriminator
protected function serializeClassNameAndDiscriminator(ClassMetadata $metadata)
{
$return = array();
if (isset($metadata->serializer['className']) && $metadata->serializer['className']) {
$return[$this->classNameField] = $metadata->name;
}
if (isset($metadata->serializer['discriminator']) && $metadata->serializer['discriminator'] && $metadata->hasDiscriminator()) {
$return[$metadata->discriminatorField['name']] = $metadata->discriminatorValue;
}
return $return;
}