本文整理汇总了PHP中Doctrine\ODM\MongoDB\Mapping\ClassMetadata::setChangeTrackingPolicy方法的典型用法代码示例。如果您正苦于以下问题:PHP ClassMetadata::setChangeTrackingPolicy方法的具体用法?PHP ClassMetadata::setChangeTrackingPolicy怎么用?PHP ClassMetadata::setChangeTrackingPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Doctrine\ODM\MongoDB\Mapping\ClassMetadata
的用法示例。
在下文中一共展示了ClassMetadata::setChangeTrackingPolicy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $class)
{
$element = $this->getElement($className);
if ( ! $element) {
return;
}
$element['type'] = isset($element['type']) ? $element['type'] : 'document';
if (isset($element['db'])) {
$class->setDB($element['db']);
}
if (isset($element['collection'])) {
$class->setCollection($element['collection']);
}
if ($element['type'] == 'document') {
if (isset($element['repositoryClass'])) {
$class->setCustomRepositoryClass($element['repositoryClass']);
}
} elseif ($element['type'] === 'mappedSuperclass') {
$class->isMappedSuperclass = true;
} elseif ($element['type'] === 'embeddedDocument') {
$class->isEmbeddedDocument = true;
}
if (isset($element['indexes'])) {
foreach($element['indexes'] as $index) {
$class->addIndex($index['keys'], isset($index['options']) ? $index['options'] : array());
}
}
if (isset($element['inheritanceType'])) {
$class->setInheritanceType(constant('Doctrine\ODM\MongoDB\Mapping\ClassMetadata::INHERITANCE_TYPE_' . strtoupper($element['inheritanceType'])));
}
if (isset($element['discriminatorField'])) {
$discrField = $element['discriminatorField'];
$class->setDiscriminatorField(array(
'name' => $discrField['name'],
'fieldName' => $discrField['fieldName']
));
}
if (isset($element['discriminatorMap'])) {
$class->setDiscriminatorMap($element['discriminatorMap']);
}
if (isset($element['changeTrackingPolicy'])) {
$class->setChangeTrackingPolicy(constant('Doctrine\ODM\MongoDB\Mapping\ClassMetadata::CHANGETRACKING_'
. strtoupper($element['changeTrackingPolicy'])));
}
if (isset($element['fields'])) {
foreach ($element['fields'] as $fieldName => $mapping) {
if (is_string($mapping)) {
$type = $mapping;
$mapping = array();
$mapping['type'] = $type;
}
if ( ! isset($mapping['fieldName'])) {
$mapping['fieldName'] = $fieldName;
}
if (isset($mapping['type']) && $mapping['type'] === 'collection') {
$mapping['strategy'] = isset($mapping['strategy']) ? $mapping['strategy'] : 'pushAll';
}
$this->addFieldMapping($class, $mapping);
}
}
if (isset($element['embedOne'])) {
foreach ($element['embedOne'] as $fieldName => $embed) {
$this->addMappingFromEmbed($class, $fieldName, $embed, 'one');
}
}
if (isset($element['embedMany'])) {
foreach ($element['embedMany'] as $fieldName => $embed) {
$this->addMappingFromEmbed($class, $fieldName, $embed, 'many');
}
}
if (isset($element['referenceOne'])) {
foreach ($element['referenceOne'] as $fieldName => $reference) {
$this->addMappingFromReference($class, $fieldName, $reference, 'one');
}
}
if (isset($element['referenceMany'])) {
foreach ($element['referenceMany'] as $fieldName => $reference) {
$this->addMappingFromReference($class, $fieldName, $reference, 'many');
}
}
if (isset($element['lifecycleCallbacks'])) {
foreach ($element['lifecycleCallbacks'] as $type => $methods) {
foreach ($methods as $method) {
$class->addLifecycleCallback($method, constant('Doctrine\ODM\MongoDB\Events::' . $type));
}
}
}
}
示例2: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $class)
{
$xmlRoot = $this->getElement($className);
if (!$xmlRoot) {
return;
}
if ($xmlRoot->getName() == 'document') {
if (isset($xmlRoot['repository-class'])) {
$class->setCustomRepositoryClass((string) $xmlRoot['repository-class']);
}
} elseif ($xmlRoot->getName() == 'mapped-superclass') {
$class->isMappedSuperclass = true;
} elseif ($xmlRoot->getName() == 'embedded-document') {
$class->isEmbeddedDocument = true;
}
if (isset($xmlRoot['db'])) {
$class->setDatabase((string) $xmlRoot['db']);
}
if (isset($xmlRoot['collection'])) {
$class->setCollection((string) $xmlRoot['collection']);
}
if (isset($xmlRoot['inheritance-type'])) {
$inheritanceType = (string) $xmlRoot['inheritance-type'];
$class->setInheritanceType(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceType));
}
if (isset($xmlRoot->{'discriminator-field'})) {
$discrField = $xmlRoot->{'discriminator-field'};
$class->setDiscriminatorField(array('name' => (string) $discrField['name'], 'fieldName' => (string) $discrField['fieldName']));
}
if (isset($xmlRoot->{'discriminator-map'})) {
$map = array();
foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} as $discrMapElement) {
$map[(string) $discrMapElement['value']] = (string) $discrMapElement['class'];
}
$class->setDiscriminatorMap($map);
}
if (isset($xmlRoot->{'change-tracking-policy'})) {
$class->setChangeTrackingPolicy(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper((string) $xmlRoot->{'change-tracking-policy'})));
}
if (isset($xmlRoot->{'indexes'})) {
foreach ($xmlRoot->{'indexes'}->{'index'} as $index) {
$this->addIndex($class, $index);
}
}
if (isset($xmlRoot->field)) {
foreach ($xmlRoot->field as $field) {
$mapping = array();
$attributes = $field->attributes();
foreach ($attributes as $key => $value) {
$mapping[$key] = (string) $value;
$booleanAttributes = array('id', 'reference', 'embed', 'unique');
if (in_array($key, $booleanAttributes)) {
$mapping[$key] = 'true' === $mapping[$key] ? true : false;
}
}
$this->addFieldMapping($class, $mapping);
}
}
if (isset($xmlRoot->{'embed-one'})) {
foreach ($xmlRoot->{'embed-one'} as $embed) {
$this->addEmbedMapping($class, $embed, 'one');
}
}
if (isset($xmlRoot->{'embed-many'})) {
foreach ($xmlRoot->{'embed-many'} as $embed) {
$this->addEmbedMapping($class, $embed, 'many');
}
}
if (isset($xmlRoot->{'reference-many'})) {
foreach ($xmlRoot->{'reference-many'} as $reference) {
$this->addReferenceMapping($class, $reference, 'many');
}
}
if (isset($xmlRoot->{'reference-one'})) {
foreach ($xmlRoot->{'reference-one'} as $reference) {
$this->addReferenceMapping($class, $reference, 'one');
}
}
if (isset($xmlRoot->{'lifecycle-callbacks'})) {
foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) {
$class->addLifecycleCallback((string) $lifecycleCallback['method'], constant('Doctrine\\ODM\\MongoDB\\Events::' . (string) $lifecycleCallback['type']));
}
}
}
示例3: loadMetadataForClass
/**
* {@inheritdoc}
*/
public function loadMetadataForClass($className, ClassMetadata $class)
{
$xmlRoot = $this->getElement($className);
if (!$xmlRoot) {
return;
}
if ($xmlRoot->getName() == 'document') {
if (isset($xmlRoot['repository-class'])) {
$class->setCustomRepositoryClass((string) $xmlRoot['repository-class']);
}
} elseif ($xmlRoot->getName() == 'mapped-superclass') {
$class->isMappedSuperclass = true;
} elseif ($xmlRoot->getName() == 'embedded-document') {
$class->isEmbeddedDocument = true;
}
if (isset($xmlRoot['db'])) {
$class->setDB((string) $xmlRoot['db']);
}
if (isset($xmlRoot['collection'])) {
$class->setCollection((string) $xmlRoot['collection']);
}
if (isset($xmlRoot['indexes'])) {
foreach ($xmlRoot['indexes'] as $index) {
$class->addIndex((array) $index['keys'], (array) $index['options']);
}
}
if (isset($xmlRoot['customId']) && (string) $xmlRoot['customId'] === true) {
$class->setAllowCustomId(true);
}
if (isset($xmlRoot['inheritance-type'])) {
$inheritanceType = (string) $xmlRoot['inheritance-type'];
$class->setInheritanceType(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::INHERITANCE_TYPE_' . $inheritanceType));
}
if (isset($xmlRoot->{'discriminator-field'})) {
$discrField = $xmlRoot->{'discriminator-field'};
$class->setDiscriminatorField(array('name' => (string) $discrField['name'], 'fieldName' => (string) $discrField['fieldName']));
}
if (isset($xmlRoot->{'discriminator-map'})) {
$map = array();
foreach ($xmlRoot->{'discriminator-map'}->{'discriminator-mapping'} as $discrMapElement) {
$map[(string) $discrMapElement['value']] = (string) $discrMapElement['class'];
}
$class->setDiscriminatorMap($map);
}
if (isset($xmlRoot->{'change-tracking-policy'})) {
$class->setChangeTrackingPolicy(constant('Doctrine\\ODM\\MongoDB\\Mapping\\ClassMetadata::CHANGETRACKING_' . strtoupper((string) $xmlRoot->{'change-tracking-policy'})));
}
if (isset($xmlRoot->field)) {
foreach ($xmlRoot->field as $field) {
$mapping = $this->getFieldMapping($field);
$class->mapField($mapping);
}
}
if (isset($xmlRoot->{'embed-one'})) {
foreach ($xmlRoot->{'embed-one'} as $embed) {
$mapping = $this->getEmbedMapping($embed, 'one');
$class->mapField($mapping);
}
}
if (isset($xmlRoot->{'embed-many'})) {
foreach ($xmlRoot->{'embed-many'} as $embed) {
$mapping = $this->getEmbedMapping($embed, 'many');
$class->mapField($mapping);
}
}
if (isset($xmlRoot->{'reference-many'})) {
foreach ($xmlRoot->{'reference-many'} as $reference) {
$mapping = $this->getReferenceMapping($reference, 'many');
$class->mapField($mapping);
}
}
if (isset($xmlRoot->{'reference-one'})) {
foreach ($xmlRoot->{'reference-one'} as $reference) {
$mapping = $this->getReferenceMapping($reference, 'one');
$class->mapField($mapping);
}
}
if (isset($xmlRoot->{'lifecycle-callbacks'})) {
foreach ($xmlRoot->{'lifecycle-callbacks'}->{'lifecycle-callback'} as $lifecycleCallback) {
$class->addLifecycleCallback((string) $lifecycleCallback['method'], constant('Doctrine\\ODM\\MongoDB\\ODMEvents::' . (string) $lifecycleCallback['type']));
}
}
}