Alcaeus\MongoDbAdapter\TypeConverter::toLegacy PHP Метод

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

This method handles type conversion from ext-mongodb to ext-mongo: - For all instances of BSON\Type it returns an object of the corresponding legacy type (MongoId, MongoDate, etc.) - For arrays and objects it iterates over properties and converts each item individually - For other types it returns the value unconverted
public static toLegacy ( mixed $value ) : mixed
$value mixed
Результат mixed
    public static function toLegacy($value)
    {
        switch (true) {
            case $value instanceof BSON\Type:
                return self::convertBSONObjectToLegacy($value);
            case is_array($value):
            case is_object($value):
                $result = [];
                foreach ($value as $key => $item) {
                    $result[$key] = self::toLegacy($item);
                }
                return $result;
            default:
                return $value;
        }
    }

Usage Example

Пример #1
0
 /**
  * @link http://php.net/manual/en/mongocode.construct.php
  * @param string $code A string of code
  * @param array $scope The scope to use for the code
  */
 public function __construct($code, array $scope = [])
 {
     if ($code instanceof \MongoDB\BSON\Javascript) {
         $javascript = $code;
         $code = $javascript->getCode();
         $scope = TypeConverter::toLegacy($javascript->getScope());
     }
     $this->code = $code;
     $this->scope = $scope;
 }
All Usage Examples Of Alcaeus\MongoDbAdapter\TypeConverter::toLegacy