本文整理汇总了PHP中Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo::setShardKey方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadataInfo::setShardKey方法的具体用法?PHP ClassMetadataInfo::setShardKey怎么用?PHP ClassMetadataInfo::setShardKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\Mapping\ClassMetadataInfo
的用法示例。
在下文中一共展示了ClassMetadataInfo::setShardKey方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setShardKey
/**
* @param ClassMetadataInfo $class
* @param ODM\ShardKey $shardKey
*
* @throws MappingException
*/
private function setShardKey(ClassMetadataInfo $class, ODM\ShardKey $shardKey)
{
$options = array();
$allowed = array('unique', 'numInitialChunks');
foreach ($allowed as $name) {
if (isset($shardKey->{$name})) {
$options[$name] = $shardKey->{$name};
}
}
$class->setShardKey($shardKey->keys, $options);
}
示例2: setShardKey
private function setShardKey(ClassMetadataInfo $class, \SimpleXmlElement $xmlShardkey)
{
$attributes = $xmlShardkey->attributes();
$keys = array();
$options = array();
foreach ($xmlShardkey->{'key'} as $key) {
$keys[(string) $key['name']] = isset($key['order']) ? (string) $key['order'] : 'asc';
}
if (isset($attributes['unique'])) {
$options['unique'] = 'true' === (string) $attributes['unique'];
}
if (isset($attributes['numInitialChunks'])) {
$options['numInitialChunks'] = (int) $attributes['numInitialChunks'];
}
if (isset($xmlShardkey->{'option'})) {
foreach ($xmlShardkey->{'option'} as $option) {
$value = (string) $option['value'];
if ($value === 'true') {
$value = true;
} elseif ($value === 'false') {
$value = false;
} elseif (is_numeric($value)) {
$value = preg_match('/^[-]?\\d+$/', $value) ? (int) $value : (double) $value;
}
$options[(string) $option['name']] = $value;
}
}
$class->setShardKey($keys, $options);
}
示例3: testNoReferenceManyInShardKey
/**
* @expectedException \Doctrine\ODM\MongoDB\Mapping\MappingException
* @expectedExceptionMessage No multikey indexes are allowed in the shard key
*/
public function testNoReferenceManyInShardKey()
{
$cm = new ClassMetadataInfo('stdClass');
$cm->mapManyEmbedded(['fieldName' => 'referenceMany']);
$cm->setShardKey(array('referenceMany' => 1));
}
示例4: setShardKey
private function setShardKey(ClassMetadataInfo $class, array $shardKey)
{
$keys = $shardKey['keys'];
$options = array();
if (isset($shardKey['options'])) {
$allowed = array('unique', 'numInitialChunks');
foreach ($shardKey['options'] as $name => $value) {
if (!in_array($name, $allowed, true)) {
continue;
}
$options[$name] = $value;
}
}
$class->setShardKey($keys, $options);
}
示例5: testEmbeddedDocumentCantHaveShardKey
/**
* @expectedException \Doctrine\ODM\MongoDB\Mapping\MappingException
* @expectedExceptionMessage Embedded document can't have shard key: stdClass
*/
public function testEmbeddedDocumentCantHaveShardKey()
{
$cm = new ClassMetadataInfo('stdClass');
$cm->isEmbeddedDocument = true;
$cm->setShardKey(array('id' => 'asc'));
}