Doctrine\ODM\MongoDB\Mapping\MappingException::invalidStorageStrategy PHP Метод

invalidStorageStrategy() публичный статический Метод

public static invalidStorageStrategy ( string $className, string $fieldName, string $type, string $strategy ) : MappingException
$className string
$fieldName string
$type string
$strategy string
Результат MappingException
    public static function invalidStorageStrategy($className, $fieldName, $type, $strategy)
    {
        return new self("Invalid strategy {$strategy} used in {$className}::{$fieldName} with type {$type}");
    }

Usage Example

Пример #1
0
 /**
  * Validates the storage strategy of a mapping for consistency
  * @param array $mapping
  * @throws \Doctrine\ODM\MongoDB\Mapping\MappingException
  */
 private function applyStorageStrategy(array &$mapping)
 {
     if (!isset($mapping['type']) || isset($mapping['id'])) {
         return;
     }
     switch (true) {
         case $mapping['type'] == 'int':
         case $mapping['type'] == 'float':
         case $mapping['type'] == 'increment':
             $defaultStrategy = self::STORAGE_STRATEGY_SET;
             $allowedStrategies = [self::STORAGE_STRATEGY_SET, self::STORAGE_STRATEGY_INCREMENT];
             break;
         case $mapping['type'] == 'many':
             $defaultStrategy = CollectionHelper::DEFAULT_STRATEGY;
             $allowedStrategies = [self::STORAGE_STRATEGY_PUSH_ALL, self::STORAGE_STRATEGY_ADD_TO_SET, self::STORAGE_STRATEGY_SET, self::STORAGE_STRATEGY_SET_ARRAY, self::STORAGE_STRATEGY_ATOMIC_SET, self::STORAGE_STRATEGY_ATOMIC_SET_ARRAY];
             break;
         default:
             $defaultStrategy = self::STORAGE_STRATEGY_SET;
             $allowedStrategies = [self::STORAGE_STRATEGY_SET];
     }
     if (!isset($mapping['strategy'])) {
         $mapping['strategy'] = $defaultStrategy;
     }
     if (!in_array($mapping['strategy'], $allowedStrategies)) {
         throw MappingException::invalidStorageStrategy($this->name, $mapping['fieldName'], $mapping['type'], $mapping['strategy']);
     }
     if (isset($mapping['reference']) && $mapping['type'] === 'many' && $mapping['isOwningSide'] && !empty($mapping['sort']) && !CollectionHelper::usesSet($mapping['strategy'])) {
         throw MappingException::referenceManySortMustNotBeUsedWithNonSetCollectionStrategy($this->name, $mapping['fieldName'], $mapping['strategy']);
     }
 }