本文整理汇总了PHP中Pimcore\Tool\Serialize::serialize方法的典型用法代码示例。如果您正苦于以下问题:PHP Serialize::serialize方法的具体用法?PHP Serialize::serialize怎么用?PHP Serialize::serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pimcore\Tool\Serialize
的用法示例。
在下文中一共展示了Serialize::serialize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
/**
*
*/
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);
}
示例2: upperCastDocument
/**
* @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;
}
示例3: update
/**
* 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()));
}
示例4: delete
/**
* @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();
}
}
示例5: save
/**
* 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);
}
示例6: update
/**
* @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;
}
}
示例7: update
/**
* @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;
}
}
示例8: save
/**
* @return void
*/
public function save()
{
// check if versioning is disabled for this process
if (self::$disabled) {
return;
}
if (!$this->date) {
$this->setDate(time());
}
$data = $this->getData();
// if necessary convert the data to save it to filesystem
if (is_object($data) or is_array($data)) {
// this is because of lazy loaded element inside documents and objects (eg: multihref, objects, fieldcollections, ...)
if ($data instanceof Element\ElementInterface) {
Element\Service::loadAllFields($data);
}
$this->setSerialized(true);
$data->_fulldump = true;
$dataString = Serialize::serialize($data);
// revert all changed made by __sleep()
if (method_exists($data, "__wakeup")) {
$data->__wakeup();
}
unset($data->_fulldump);
} else {
$dataString = $data;
}
$this->id = $this->getDao()->save();
// check if directory exists
$saveDir = dirname($this->getFilePath());
if (!is_dir($saveDir)) {
File::mkdir($saveDir);
}
// save data to filesystem
if (!is_writable(dirname($this->getFilePath())) || is_file($this->getFilePath()) && !is_writable($this->getFilePath())) {
throw new \Exception("Cannot save version for element " . $this->getCid() . " with type " . $this->getCtype() . " because the file " . $this->getFilePath() . " is not writeable.");
} else {
File::put($this->getFilePath(), $dataString);
// assets are kina special because they can contain massive amount of binary data which isn't serialized, we append it to the data file
if ($data instanceof Asset && $data->getType() != "folder") {
// append binary data to version file
$handle = fopen($this->getBinaryFilePath(), "w+");
$src = $data->getStream();
stream_copy_to_stream($src, $handle);
fclose($handle);
}
}
}
示例9: getDataForResource
/**
* @see Object\ClassDefinition\Data::getDataForResource
* @param string $data
* @param null|Model\Object\AbstractObject $object
* @return string
*/
public function getDataForResource($data, $object = null)
{
return Serialize::serialize($data);
}
示例10: getForCsvExport
/**
* converts object data to a simple string value or CSV Export
* @abstract
* @param Model\Object\AbstractObject $object
* @return string
*/
public function getForCsvExport($object)
{
$data = $this->getDataFromObjectParam($object);
if ($data instanceof Object\Data\Hotspotimage) {
return base64_encode(Serialize::serialize($data));
} else {
return null;
}
}
示例11: update
/**
* 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;
}
}
示例12: save
/**
* @throws \Exception
* @return void
*/
public function save()
{
if (!$this->getKey()) {
throw new \Exception("A object-brick needs a key to be saved!");
}
$objectBrickFolder = PIMCORE_CLASS_DIRECTORY . "/objectbricks";
// create folder if not exist
if (!is_dir($objectBrickFolder)) {
File::mkdir($objectBrickFolder);
}
$newClassDefinitions = array();
$classDefinitionsToDelete = array();
foreach ($this->classDefinitions as $cl) {
if (!$cl['deleted']) {
$newClassDefinitions[] = $cl;
} else {
$classDefinitionsToDelete[] = $cl;
}
}
$this->classDefinitions = $newClassDefinitions;
$serialized = Serialize::serialize($this);
$serializedFilename = $objectBrickFolder . "/" . $this->getKey() . ".psf";
$this->cleanupOldFiles($serializedFilename);
File::put($serializedFilename, $serialized);
$extendClass = "Object\\Objectbrick\\Data\\AbstractData";
if ($this->getParentClass()) {
$extendClass = $this->getParentClass();
$extendClass = "\\" . ltrim($extendClass, "\\");
}
// create class
$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\\Objectbrick\\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())) {
foreach ($this->getFieldDefinitions() as $key => $def) {
/**
* @var $def Object\ClassDefinition\Data
*/
$cd .= $def->getGetterCodeObjectbrick($this);
$cd .= $def->getSetterCodeObjectbrick($this);
}
}
$cd .= "}\n";
$cd .= "\n";
$fieldClassFolder = PIMCORE_CLASS_DIRECTORY . "/Object/Objectbrick/Data";
if (!is_dir($fieldClassFolder)) {
File::mkdir($fieldClassFolder);
}
$fieldClassFile = $fieldClassFolder . "/" . ucfirst($this->getKey()) . ".php";
File::put($fieldClassFile, $cd);
$this->createContainerClasses();
$this->updateDatabase();
}
示例13: getForCsvExport
/**
* converts object data to a simple string value or CSV Export
* @abstract
* @param Object\AbstractObject $object
* @param array $params
* @return string
*/
public function getForCsvExport($object, $params = array())
{
$data = $this->getDataFromObjectParam($object);
if (is_array($data)) {
return base64_encode(Serialize::serialize($data));
} else {
return null;
}
}
示例14: getThumbnail
/**
* @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);
}
示例15: update
/**
* @throws \Exception
* @throws \Zend_Db_Adapter_Exception
*/
public function update()
{
$class = get_object_vars($this->model);
$data = array();
foreach ($class as $key => $value) {
if (in_array($key, $this->getValidTableColumns("classes"))) {
if (is_array($value) || is_object($value)) {
$value = Serialize::serialize($value);
} else {
if (is_bool($value)) {
$value = (int) $value;
}
}
$data[$key] = $value;
}
}
$this->db->update("classes", $data, $this->db->quoteInto("id = ?", $this->model->getId()));
// save definition as a serialized file
$definitionFile = PIMCORE_CLASS_DIRECTORY . "/definition_" . $this->model->getId() . ".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, Serialize::serialize($this->model->layoutDefinitions));
$objectTable = "object_query_" . $this->model->getId();
$objectDatastoreTable = "object_store_" . $this->model->getId();
$objectDatastoreTableRelation = "object_relations_" . $this->model->getId();
$objectView = "object_" . $this->model->getId();
// create object table if not exists
$protectedColums = array("oo_id", "oo_classId", "oo_className");
$protectedDatastoreColumns = array("oo_id");
$this->db->query("CREATE TABLE IF NOT EXISTS `" . $objectTable . "` (\n\t\t\t `oo_id` int(11) NOT NULL default '0',\n\t\t\t `oo_classId` int(11) default '" . $this->model->getId() . "',\n\t\t\t `oo_className` varchar(255) default '" . $this->model->getName() . "',\n\t\t\t PRIMARY KEY (`oo_id`)\n\t\t\t) DEFAULT CHARSET=utf8;");
// update default value of classname columns
$this->db->query('ALTER TABLE `' . $objectTable . "` ALTER COLUMN `oo_className` SET DEFAULT '" . $this->model->getName() . "';");
$this->db->query("CREATE TABLE IF NOT EXISTS `" . $objectDatastoreTable . "` (\n\t\t\t `oo_id` int(11) NOT NULL default '0',\n\t\t\t PRIMARY KEY (`oo_id`)\n\t\t\t) DEFAULT CHARSET=utf8;");
$this->db->query("CREATE TABLE IF NOT EXISTS `" . $objectDatastoreTableRelation . "` (\n `src_id` int(11) NOT NULL DEFAULT '0',\n `dest_id` int(11) NOT NULL DEFAULT '0',\n `type` varchar(50) NOT NULL DEFAULT '',\n `fieldname` varchar(70) NOT NULL DEFAULT '0',\n `index` int(11) unsigned NOT NULL DEFAULT '0',\n `ownertype` enum('object','fieldcollection','localizedfield','objectbrick') NOT NULL DEFAULT 'object',\n `ownername` varchar(70) NOT NULL DEFAULT '',\n `position` varchar(70) NOT NULL DEFAULT '0',\n PRIMARY KEY (`src_id`,`dest_id`,`ownertype`,`ownername`,`fieldname`,`type`,`position`),\n KEY `index` (`index`),\n KEY `src_id` (`src_id`),\n KEY `dest_id` (`dest_id`),\n KEY `fieldname` (`fieldname`),\n KEY `position` (`position`),\n KEY `ownertype` (`ownertype`),\n KEY `type` (`type`),\n KEY `ownername` (`ownername`)\n ) DEFAULT CHARSET=utf8;");
$existingColumns = $this->getValidTableColumns($objectTable, false);
// no caching of table definition
$existingDatastoreColumns = $this->getValidTableColumns($objectDatastoreTable, false);
// no caching of table definition
$columnsToRemove = $existingColumns;
$datastoreColumnsToRemove = $existingDatastoreColumns;
Object\ClassDefinition\Service::updateTableDefinitions($this->tableDefinitions, array($objectTable, $objectDatastoreTable));
// add non existing columns in the table
if (is_array($this->model->getFieldDefinitions()) && count($this->model->getFieldDefinitions())) {
foreach ($this->model->getFieldDefinitions() as $key => $value) {
// if a datafield requires more than one column in the query table
if (is_array($value->getQueryColumnType())) {
foreach ($value->getQueryColumnType() as $fkey => $fvalue) {
$this->addModifyColumn($objectTable, $key . "__" . $fkey, $fvalue, "", "NULL");
$protectedColums[] = $key . "__" . $fkey;
}
}
// if a datafield requires more than one column in the datastore table => only for non-relation types
if (!$value->isRelationType() && is_array($value->getColumnType())) {
foreach ($value->getColumnType() as $fkey => $fvalue) {
$this->addModifyColumn($objectDatastoreTable, $key . "__" . $fkey, $fvalue, "", "NULL");
$protectedDatastoreColumns[] = $key . "__" . $fkey;
}
}
// everything else
// if (!is_array($value->getQueryColumnType()) && !is_array($value->getColumnType())) {
if (!is_array($value->getQueryColumnType()) && $value->getQueryColumnType()) {
$this->addModifyColumn($objectTable, $key, $value->getQueryColumnType(), "", "NULL");
$protectedColums[] = $key;
}
if (!is_array($value->getColumnType()) && $value->getColumnType() && !$value->isRelationType()) {
$this->addModifyColumn($objectDatastoreTable, $key, $value->getColumnType(), "", "NULL");
$protectedDatastoreColumns[] = $key;
}
// }
// add indices
$this->addIndexToField($value, $objectTable);
$this->addIndexToField($value, $objectDatastoreTable);
}
}
// remove unused columns in the table
$this->removeUnusedColumns($objectTable, $columnsToRemove, $protectedColums);
$this->removeUnusedColumns($objectDatastoreTable, $datastoreColumnsToRemove, $protectedDatastoreColumns, true);
// create view
try {
//$this->db->query('CREATE OR REPLACE VIEW `' . $objectView . '` AS SELECT * FROM `objects` left JOIN `' . $objectTable . '` ON `objects`.`o_id` = `' . $objectTable . '`.`oo_id` WHERE `objects`.`o_classId` = ' . $this->model->getId() . ';');
$this->db->query('CREATE OR REPLACE VIEW `' . $objectView . '` AS SELECT * FROM `' . $objectTable . '` JOIN `objects` ON `objects`.`o_id` = `' . $objectTable . '`.`oo_id`;');
} catch (\Exception $e) {
\Logger::debug($e);
}
$this->tableDefinitions = null;
}