php Pimcore-Tool-Serialize类(方法)实例源码

下面列出了php Pimcore-Tool-Serialize 类(方法)源码代码实例,从而了解它的用法。

作者:emanuel-londo    项目:pimcor   
/**
  *
  */
 public function save()
 {
     $data = $this->model->getDataForResource();
     if (is_array($data) or is_object($data)) {
         $data = \Pimcore\Tool\Serialize::serialize($data);
     }
     $element = array("data" => $data, "documentId" => $this->model->getDocumentId(), "name" => $this->model->getName(), "type" => $this->model->getType());
     $this->db->insertOrUpdate("documents_elements", $element);
 }

作者:sfi    项目:pimcor   
/**
  * @param mixed $data
  * @param bool $sendNow
  * @param bool $keepLayouts
  * @param bool $encodeData
  * @return string|void
  */
 public function direct($data, $sendNow = true, $keepLayouts = false, $encodeData = true)
 {
     if ($encodeData) {
         $data = \Pimcore\Tool\Serialize::removeReferenceLoops($data);
     }
     // hack for FCGI because ZF doesn't care of duplicate headers
     $this->getResponse()->clearHeader("Content-Type");
     $this->suppressExit = !$sendNow;
     $d = $this->sendJson($data, $keepLayouts, $encodeData);
     return $d;
 }

作者:rolandstol    项目:pimcor   
/**
  * @static
  * @param Document $doc
  * @return Document
  */
 public static function upperCastDocument(Document $doc)
 {
     $to_class = "Pimcore\\Model\\Document\\Hardlink\\Wrapper\\" . ucfirst($doc->getType());
     $old_serialized_prefix = "O:" . strlen(get_class($doc));
     $old_serialized_prefix .= ":\"" . get_class($doc) . "\":";
     // unset eventually existing children, because of performance reasons when serializing the document
     $doc->setChilds(null);
     $old_serialized_object = Serialize::serialize($doc);
     $new_serialized_object = 'O:' . strlen($to_class) . ':"' . $to_class . '":';
     $new_serialized_object .= substr($old_serialized_object, strlen($old_serialized_prefix));
     $document = Serialize::unserialize($new_serialized_object);
     return $document;
 }

作者:emanuel-londo    项目:pimcor   
public function encode($data, $returnData = false)
 {
     $data = \Pimcore\Tool\Serialize::removeReferenceLoops($data);
     $data = \Zend_Json::encode($data, null, array());
     if ($returnData) {
         return $data;
     } else {
         $response = \Zend_Controller_Front::getInstance()->getResponse();
         $response->setHeader('Content-Type', 'application/json', true);
         $response->setBody($data);
         $response->sendResponse();
         exit;
     }
 }

作者:pimcor    项目:pimcor   
/**
  * Save changes to database, it's an good idea to use save() instead
  *
  * @return void
  */
 public function update()
 {
     $site = get_object_vars($this->model);
     foreach ($site as $key => $value) {
         if (in_array($key, $this->getValidTableColumns("schedule_tasks"))) {
             if (is_array($value) || is_object($value)) {
                 $value = \Pimcore\Tool\Serialize::serialize($value);
             } elseif (is_bool($value)) {
                 $value = (int) $value;
             }
             $data[$key] = $value;
         }
     }
     $this->db->update("schedule_tasks", $data, $this->db->quoteInto("id = ?", $this->model->getId()));
 }

作者:ChristophWurs    项目:pimcor   
/**
  * @throws DAV\Exception\Forbidden
  * @throws \Exception
  */
 function delete()
 {
     if ($this->asset->isAllowed("delete")) {
         Asset\Service::loadAllFields($this->asset);
         $this->asset->delete();
         // add the asset to the delete history, this is used so come over problems with programs like photoshop (delete, create instead of replace => move)
         // for details see Asset\WebDAV\Tree::move()
         $log = Asset\WebDAV\Service::getDeleteLog();
         $this->asset->_fulldump = true;
         $log[$this->asset->getFullpath()] = array("id" => $this->asset->getId(), "timestamp" => time(), "data" => \Pimcore\Tool\Serialize::serialize($this->asset));
         unset($this->asset->_fulldump);
         Asset\WebDAV\Service::saveDeleteLog($log);
     } else {
         throw new DAV\Exception\Forbidden();
     }
 }

作者:Gerhard1    项目:pimcor   
/**
  * Save object to database
  *
  * @return void
  */
 public function save()
 {
     $data = $this->model->getData();
     if ($this->model->getType() == "object" || $this->model->getType() == "asset" || $this->model->getType() == "document") {
         if ($data instanceof Model\Element\ElementInterface) {
             $data = $data->getId();
         } else {
             $data = null;
         }
     }
     if (is_array($data) || is_object($data)) {
         $data = \Pimcore\Tool\Serialize::serialize($data);
     }
     $saveData = array("cid" => $this->model->getCid(), "ctype" => $this->model->getCtype(), "cpath" => $this->model->getCpath(), "name" => $this->model->getName(), "type" => $this->model->getType(), "inheritable" => (int) $this->model->getInheritable(), "data" => $data);
     $this->db->insertOrUpdate("properties", $saveData);
 }

作者:sfi    项目:pimcor   
/**
  * @return array
  */
 public function load()
 {
     $fields = array();
     $objectBricksFolder = PIMCORE_CLASS_DIRECTORY . "/objectbricks";
     if (is_dir($objectBricksFolder)) {
         $files = scandir($objectBricksFolder);
         foreach ($files as $file) {
             $file = $objectBricksFolder . "/" . $file;
             if (is_file($file)) {
                 $fieldData = file_get_contents($file);
                 $fields[] = \Pimcore\Tool\Serialize::unserialize($fieldData);
             }
         }
     }
     return $fields;
 }

作者:solvera    项目:pimcor   
/**
  * @return array
  */
 public function load()
 {
     $fields = [];
     $fieldCollectionFolder = PIMCORE_CLASS_DIRECTORY . "/fieldcollections";
     if (is_dir($fieldCollectionFolder)) {
         $files = scandir($fieldCollectionFolder);
         foreach ($files as $file) {
             $file = $fieldCollectionFolder . "/" . $file;
             if (is_file($file)) {
                 $fieldData = file_get_contents($file);
                 $fields[] = \Pimcore\Tool\Serialize::unserialize($fieldData);
             }
         }
     }
     return $fields;
 }

作者:rolandstol    项目:pimcor   
/**
  * Get the data for the object by the given id, or by the id which is set in the object
  *
  * @param integer $id
  * @throws \Exception
  */
 public function getById($id = null)
 {
     try {
         if ($id != null) {
             $this->model->setId($id);
         }
         $data = $this->db->fetchRow("SELECT documents.*, documents_page.*, tree_locks.locked FROM documents\n                LEFT JOIN documents_page ON documents.id = documents_page.id\n                LEFT JOIN tree_locks ON documents.id = tree_locks.id AND tree_locks.type = 'document'\n                    WHERE documents.id = ?", $this->model->getId());
         if ($data["id"] > 0) {
             $data["metaData"] = Serialize::unserialize($data["metaData"]);
             $this->assignVariablesToModel($data);
         } else {
             throw new \Exception("Page with the ID " . $this->model->getId() . " doesn't exists");
         }
     } catch (\Exception $e) {
         throw $e;
     }
 }

作者:cannoner    项目:pimcor   
/**
  * Moves a file/directory
  *
  * @param string $sourcePath
  * @param string $destinationPath
  * @return void
  */
 public function move($sourcePath, $destinationPath)
 {
     $nameParts = explode("/", $sourcePath);
     $nameParts[count($nameParts) - 1] = File::getValidFilename($nameParts[count($nameParts) - 1]);
     $sourcePath = implode("/", $nameParts);
     $nameParts = explode("/", $destinationPath);
     $nameParts[count($nameParts) - 1] = File::getValidFilename($nameParts[count($nameParts) - 1]);
     $destinationPath = implode("/", $nameParts);
     try {
         if (dirname($sourcePath) == dirname($destinationPath)) {
             $asset = null;
             if ($asset = Asset::getByPath("/" . $destinationPath)) {
                 // If we got here, this means the destination exists, and needs to be overwritten
                 $sourceAsset = Asset::getByPath("/" . $sourcePath);
                 $asset->setData($sourceAsset->getData());
                 $sourceAsset->delete();
             }
             // see: Asset\WebDAV\File::delete() why this is necessary
             $log = Asset\WebDAV\Service::getDeleteLog();
             if (!$asset && array_key_exists("/" . $destinationPath, $log)) {
                 $asset = \Pimcore\Tool\Serialize::unserialize($log["/" . $destinationPath]["data"]);
                 if ($asset) {
                     $sourceAsset = Asset::getByPath("/" . $sourcePath);
                     $asset->setData($sourceAsset->getData());
                     $sourceAsset->delete();
                 }
             }
             if (!$asset) {
                 $asset = Asset::getByPath("/" . $sourcePath);
             }
             $asset->setFilename(basename($destinationPath));
         } else {
             $asset = Asset::getByPath("/" . $sourcePath);
             $parent = Asset::getByPath("/" . dirname($destinationPath));
             $asset->setPath($parent->getFullPath() . "/");
             $asset->setParentId($parent->getId());
         }
         $user = \Pimcore\Tool\Admin::getCurrentUser();
         $asset->setUserModification($user->getId());
         $asset->save();
     } catch (\Exception $e) {
         \Logger::error($e);
     }
 }

作者:rolandstol    项目:pimcor   
/**
  * @throws \Exception
  */
 public function update()
 {
     try {
         $type = get_object_vars($this->model);
         foreach ($type as $key => $value) {
             if (in_array($key, $this->getValidTableColumns("targeting_personas"))) {
                 if (is_array($value) || is_object($value)) {
                     $value = Serialize::serialize($value);
                 }
                 if (is_bool($value)) {
                     $value = (int) $value;
                 }
                 $data[$key] = $value;
             }
         }
         $this->db->update("targeting_personas", $data, $this->db->quoteInto("id = ?", $this->model->getId()));
     } catch (\Exception $e) {
         throw $e;
     }
 }

作者:pimcor    项目:pimcor   
/**
  * @throws \Exception
  */
 public function update()
 {
     try {
         $type = get_object_vars($this->model);
         foreach ($type as $key => $value) {
             if (in_array($key, $this->getValidTableColumns(self::TABLE_NAME_RELATIONS))) {
                 if (is_bool($value)) {
                     $value = (int) $value;
                 }
                 if (is_array($value) || is_object($value)) {
                     $value = \Pimcore\Tool\Serialize::serialize($value);
                 }
                 $data[$key] = $value;
             }
         }
         $this->db->insertOrUpdate(self::TABLE_NAME_RELATIONS, $data);
         return $this->model;
     } catch (\Exception $e) {
         throw $e;
     }
 }

作者:ChristophWurs    项目:pimcor   
/**
  * @throws \Exception
  */
 public function update()
 {
     try {
         $ts = time();
         $this->model->setModificationDate($ts);
         $type = get_object_vars($this->model);
         foreach ($type as $key => $value) {
             if (in_array($key, $this->getValidTableColumns(self::TABLE_NAME_KEYS))) {
                 if (is_bool($value)) {
                     $value = (int) $value;
                 }
                 if (is_array($value) || is_object($value)) {
                     if ($this->model->getType() == 'select') {
                         $value = \Zend_Json::encode($value);
                     } else {
                         $value = \Pimcore\Tool\Serialize::serialize($value);
                     }
                 }
                 $data[$key] = $value;
             }
         }
         $this->db->update(self::TABLE_NAME_KEYS, $data, $this->db->quoteInto("id = ?", $this->model->getId()));
         return $this->model;
     } catch (\Exception $e) {
         throw $e;
     }
 }

作者:emanuel-londo    项目:pimcor   
public function saveFolderAction()
 {
     $object = Object::getById($this->getParam("id"));
     $classId = $this->getParam("class_id");
     // general settings
     $general = \Zend_Json::decode($this->getParam("general"));
     $object->setValues($general);
     $object->setUserModification($this->getUser()->getId());
     $object = $this->assignPropertiesFromEditmode($object);
     if ($object->isAllowed("publish")) {
         try {
             // grid config
             $gridConfig = \Zend_Json::decode($this->getParam("gridconfig"));
             if ($classId) {
                 $configFile = PIMCORE_CONFIGURATION_DIRECTORY . "/object/grid/" . $object->getId() . "_" . $classId . "-user_" . $this->getUser()->getId() . ".psf";
             } else {
                 $configFile = PIMCORE_CONFIGURATION_DIRECTORY . "/object/grid/" . $object->getId() . "-user_" . $this->getUser()->getId() . ".psf";
             }
             $configDir = dirname($configFile);
             if (!is_dir($configDir)) {
                 File::mkdir($configDir);
             }
             File::put($configFile, Tool\Serialize::serialize($gridConfig));
             $object->save();
             $this->_helper->json(array("success" => true));
         } catch (\Exception $e) {
             $this->_helper->json(array("success" => false, "message" => $e->getMessage()));
         }
     }
     $this->_helper->json(array("success" => false, "message" => "missing_permission"));
 }

作者:Gerhard1    项目:pimcor   
/**
  * Update data from object to the database
  *
  * @throws \Exception
  */
 public function update()
 {
     try {
         $this->model->setModificationDate(time());
         $asset = get_object_vars($this->model);
         foreach ($asset as $key => $value) {
             if (in_array($key, $this->getValidTableColumns("assets"))) {
                 if (is_array($value)) {
                     $value = \Pimcore\Tool\Serialize::serialize($value);
                 }
                 $data[$key] = $value;
             }
         }
         // metadata
         $this->db->delete("assets_metadata", "cid = " . $this->model->getId());
         $metadata = $this->model->getMetadata();
         $data["hasMetaData"] = 0;
         if (!empty($metadata)) {
             foreach ($metadata as $metadataItem) {
                 $metadataItem["cid"] = $this->model->getId();
                 unset($metadataItem['config']);
                 if ($metadataItem["data"] instanceof Model\Element\ElementInterface) {
                     $metadataItem["data"] = $metadataItem["data"]->getId();
                 }
                 if (strlen($metadataItem["data"]) > 0) {
                     $this->db->insert("assets_metadata", $metadataItem);
                     $data["hasMetaData"] = 1;
                 }
             }
         }
         $this->db->insertOrUpdate("assets", $data);
         // tree_locks
         $this->db->delete("tree_locks", "id = " . $this->model->getId() . " AND type = 'asset'");
         if ($this->model->getLocked()) {
             $this->db->insert("tree_locks", array("id" => $this->model->getId(), "type" => "asset", "locked" => $this->model->getLocked()));
         }
     } catch (\Exception $e) {
         throw $e;
     }
 }

作者:emanuel-londo    项目:pimcor   
/**
  * @see Object\ClassDefinition\Data::getDataFromResource
  * @param string $data
  * @return string
  */
 public function getDataFromResource($data)
 {
     return Serialize::unserialize($data);
 }

作者:pimcor    项目:pimcor   
/**
  * This is just for compatibility, this method will be removed with the next major release
  * @depricated
  * @static
  * @param $config
  * @return self
  */
 public static function getByLegacyConfig($config)
 {
     $pipe = new self();
     if (isset($config["format"])) {
         $pipe->setFormat($config["format"]);
     }
     if (isset($config["quality"])) {
         $pipe->setQuality($config["quality"]);
     }
     if (isset($config["cover"])) {
         $pipe->addItem("cover", ["width" => $config["width"], "height" => $config["height"], "positioning" => "center"]);
     } elseif (isset($config["contain"])) {
         $pipe->addItem("contain", ["width" => $config["width"], "height" => $config["height"]]);
     } elseif (isset($config["frame"])) {
         $pipe->addItem("frame", ["width" => $config["width"], "height" => $config["height"]]);
     } elseif (isset($config["aspectratio"]) && $config["aspectratio"]) {
         if (isset($config["height"]) && isset($config["width"]) && $config["height"] > 0 && $config["width"] > 0) {
             $pipe->addItem("contain", ["width" => $config["width"], "height" => $config["height"]]);
         } elseif (isset($config["height"]) && $config["height"] > 0) {
             $pipe->addItem("scaleByHeight", ["height" => $config["height"]]);
         } else {
             $pipe->addItem("scaleByWidth", ["width" => $config["width"]]);
         }
     } else {
         if (!isset($config["width"]) && isset($config["height"])) {
             $pipe->addItem("scaleByHeight", ["height" => $config["height"]]);
         } elseif (isset($config["width"]) && !isset($config["height"])) {
             $pipe->addItem("scaleByWidth", ["width" => $config["width"]]);
         } elseif (isset($config["width"]) && isset($config["height"])) {
             $pipe->addItem("resize", ["width" => $config["width"], "height" => $config["height"]]);
         }
     }
     if (isset($config["highResolution"])) {
         $pipe->setHighResolution($config["highResolution"]);
     }
     $hash = md5(Serialize::serialize($pipe));
     $pipe->setName("auto_" . $hash);
     return $pipe;
 }

作者:ptaferne    项目:pimcor   
/**
  * @param null $thumbnailName
  * @return mixed
  */
 public function getThumbnail($thumbnailName = null)
 {
     if (!$this->getImage()) {
         return "";
     }
     $crop = null;
     if (is_array($this->getCrop())) {
         $crop = $this->getCrop();
     }
     $thumbConfig = $this->getImage()->getThumbnailConfig($thumbnailName);
     if (!$thumbConfig && $crop) {
         $thumbConfig = new Asset\Image\Thumbnail\Config();
     }
     if ($crop) {
         $thumbConfig->addItemAt(0, "cropPercent", array("width" => $crop["cropWidth"], "height" => $crop["cropHeight"], "y" => $crop["cropTop"], "x" => $crop["cropLeft"]));
         $hash = md5(\Pimcore\Tool\Serialize::serialize($thumbConfig->getItems()));
         $thumbConfig->setName($thumbConfig->getName() . "_auto_" . $hash);
     }
     return $this->getImage()->getThumbnail($thumbConfig);
 }

作者:Gerhard1    项目:pimcor   
/**
  * @throws \Exception
  */
 public function save()
 {
     if (!$this->getKey()) {
         throw new \Exception("A field-collection needs a key to be saved!");
     }
     $fieldCollectionFolder = PIMCORE_CLASS_DIRECTORY . "/fieldcollections";
     // create folder if not exist
     if (!is_dir($fieldCollectionFolder)) {
         File::mkdir($fieldCollectionFolder);
     }
     $serialized = Serialize::serialize($this);
     $definitionFile = $fieldCollectionFolder . "/" . $this->getKey() . ".psf";
     if (!is_writable(dirname($definitionFile)) || is_file($definitionFile) && !is_writable($definitionFile)) {
         throw new \Exception("Cannot write definition file in: " . $definitionFile . " please check write permission on this directory.");
     }
     File::put($definitionFile, $serialized);
     $extendClass = "Object\\Fieldcollection\\Data\\AbstractData";
     if ($this->getParentClass()) {
         $extendClass = $this->getParentClass();
         $extendClass = "\\" . ltrim($extendClass, "\\");
     }
     // create class file
     $cd = '<?php ';
     $cd .= "\n\n";
     $cd .= "/** Generated at " . date('c') . " */";
     $cd .= "\n\n";
     $cd .= "/**\n";
     if ($_SERVER["REMOTE_ADDR"]) {
         $cd .= "* IP:          " . $_SERVER["REMOTE_ADDR"] . "\n";
     }
     $cd .= "*/\n";
     $cd .= "\n\n";
     $cd .= "namespace Pimcore\\Model\\Object\\Fieldcollection\\Data;";
     $cd .= "\n\n";
     $cd .= "use Pimcore\\Model\\Object;";
     $cd .= "\n\n";
     $cd .= "class " . ucfirst($this->getKey()) . " extends " . $extendClass . "  {";
     $cd .= "\n\n";
     $cd .= 'public $type = "' . $this->getKey() . "\";\n";
     if (is_array($this->getFieldDefinitions()) && count($this->getFieldDefinitions())) {
         foreach ($this->getFieldDefinitions() as $key => $def) {
             $cd .= "public \$" . $key . ";\n";
         }
     }
     $cd .= "\n\n";
     if (is_array($this->getFieldDefinitions()) && count($this->getFieldDefinitions())) {
         $relationTypes = array();
         foreach ($this->getFieldDefinitions() as $key => $def) {
             /**
              * @var $def Object\ClassDefinition\Data
              */
             $cd .= $def->getGetterCodeFieldcollection($this);
             $cd .= $def->getSetterCodeFieldcollection($this);
         }
     }
     $cd .= "}\n";
     $cd .= "\n";
     $fieldClassFolder = PIMCORE_CLASS_DIRECTORY . "/Object/Fieldcollection/Data";
     if (!is_dir($fieldClassFolder)) {
         File::mkdir($fieldClassFolder);
     }
     $classFile = $fieldClassFolder . "/" . ucfirst($this->getKey()) . ".php";
     if (!is_writable(dirname($classFile)) || is_file($classFile) && !is_writable($classFile)) {
         throw new \Exception("Cannot write definition file in: " . $classFile . " please check write permission on this directory.");
     }
     File::put($classFile, $cd);
     // update classes
     $classList = new Object\ClassDefinition\Listing();
     $classes = $classList->load();
     if (is_array($classes)) {
         foreach ($classes as $class) {
             foreach ($class->getFieldDefinitions() as $fieldDef) {
                 if ($fieldDef instanceof Object\ClassDefinition\Data\Fieldcollections) {
                     if (in_array($this->getKey(), $fieldDef->getAllowedTypes())) {
                         $this->getResource()->createUpdateTable($class);
                         break;
                     }
                 }
             }
         }
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号