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

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

public static findWebserviceClass ( $object, $type ) : null | string
$object
$type
Результат null | string
    public static function findWebserviceClass($object, $type)
    {
        $mappingClasses = ["Asset\\File", "Asset\\Folder", "Document\\Folder", "Document\\Page", "Document\\Snippet", "Document\\Link", "Document\\Hardlink", "Document\\Email", "Object\\Folder", "Object\\Concrete"];
        $retVal = null;
        if ($object instanceof Model\Property) {
            $retVal = "\\Pimcore\\Model\\Webservice\\Data\\Property";
        } elseif ($object instanceof Model\Document\Tag) {
            $retVal = "\\Pimcore\\Model\\Webservice\\Data\\Document\\Element";
        } elseif (is_object($object)) {
            $orgclass = str_replace("Pimcore\\Model\\", "", get_class($object));
            if (in_array($orgclass, $mappingClasses)) {
                $apiclass = "\\Pimcore\\Model\\Webservice\\Data\\" . $orgclass . "\\" . ucfirst($type);
                if (!Tool::classExists($apiclass)) {
                    $apiclass = "\\Pimcore\\Model\\Webservice\\Data\\" . $orgclass;
                    if (!Tool::classExists($apiclass)) {
                        throw new \Exception("Webservice\\Data\\Mapper: no API class found for [ " . $orgclass . " ]");
                    }
                }
            } else {
                $apiclass = $orgclass;
            }
            $retVal = $apiclass;
        } else {
            $retVal = "Array";
        }
        return $retVal;
    }

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::findWebserviceClass