Pimcore\Model\Webservice\Data\Mapper::map PHP Метод

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

public static map ( $object, $apiclass, $type, null $options = null ) : array | string
$object
$apiclass
$type
$options null
Результат array | string
    public static function map($object, $apiclass, $type, $options = null)
    {
        if ($object instanceof \Zend_Date || $object instanceof \DateTimeInterface) {
            $object = $object->getTimestamp();
        } elseif (is_object($object)) {
            if (Tool::classExists($apiclass)) {
                $new = new $apiclass();
                if (method_exists($new, "map")) {
                    $new->map($object, $options);
                    $object = $new;
                }
            } else {
                throw new \Exception("Webservice\\Data\\Mapper: Cannot map [ {$apiclass} ] - class does not exist");
            }
        } elseif (is_array($object)) {
            $tmpArray = [];
            foreach ($object as $v) {
                $className = self::findWebserviceClass($v, $type);
                $tmpArray[] = self::map($v, $className, $type);
            }
            $object = $tmpArray;
        }
        return $object;
    }

Usage Example

Пример #1
0
 /**
  * @param $object
  * @param null $options
  * @throws \Exception
  */
 public function map($object, $options = null)
 {
     $keys = get_object_vars($this);
     $blockedKeys = array("childs");
     foreach ($keys as $key => $value) {
         $method = "get" . $key;
         if (method_exists($object, $method) && !in_array($key, $blockedKeys)) {
             if ($object->{$method}()) {
                 $this->{$key} = $object->{$method}();
                 // check for a pimcore data type
                 if ($this->{$key} instanceof Element\ElementInterface) {
                     $this->{$key} = $this->{$key}->getId();
                 }
                 // if the value is an object or array call the mapper again for the value
                 if (is_object($this->{$key}) || is_array($this->{$key})) {
                     $type = "out";
                     if (strpos(get_class($this), "_In") !== false) {
                         $type = "in";
                     }
                     $className = Webservice\Data\Mapper::findWebserviceClass($this->{$key}, "out");
                     $this->{$key} = Webservice\Data\Mapper::map($this->{$key}, $className, $type);
                 }
             }
         }
     }
 }
All Usage Examples Of Pimcore\Model\Webservice\Data\Mapper::map