本文整理汇总了PHP中SplObjectStorage::serialize方法的典型用法代码示例。如果您正苦于以下问题:PHP SplObjectStorage::serialize方法的具体用法?PHP SplObjectStorage::serialize怎么用?PHP SplObjectStorage::serialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SplObjectStorage
的用法示例。
在下文中一共展示了SplObjectStorage::serialize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uploadAction
public function uploadAction()
{
$request = $this->get('request');
$this->uploadFile = $request->files->get('file');
if (is_null($this->uploadFile)) {
die('File not found!');
}
$data = array('success' => false, 'error' => 'Upload error');
if ($this->uploadFile->isValid() && $request->get('secure_token') === $this->get('session')->get('secure_token')) {
$filesConfig = $this->container->getParameter('nfc_upload.types');
$fileSettings = $filesConfig[$request->get('type', 'default')];
$sessionAttr = $request->get('field');
$siteWebDir = $this->container->getParameter('nfc_upload.web_dir');
$validator = $this->getFileValidator($fileSettings);
if (!$validator) {
$data = array('success' => false, 'error' => 'To upload files on a website, you need to have JavaScript enabled in your browser');
return new JsonResponse($data);
}
$errorList = $this->get('validator')->validateValue($this->uploadFile, $validator);
if (count($errorList) == 0) {
$uploadDir = $this->get('kernel')->getRootDir() . '/../' . $siteWebDir . $fileSettings['upload_dir'];
if (!is_dir($uploadDir)) {
mkdir($uploadDir, 0777, true);
}
$fileName = 'file' . uniqid() . '.' . $this->uploadFile->getClientOriginalExtension();
$this->uploadFile->move($uploadDir, $fileName);
$fileObj = new \stdClass();
$fileObj->path = $uploadDir . '/' . $fileName;
$fileObj->extension = $this->uploadFile->getClientOriginalExtension();
$filesInfo = new \SplObjectStorage();
if ($this->get('session')->has('file_upload_' . $sessionAttr)) {
$filesInfo->unserialize($this->get('session')->get('file_upload_' . $sessionAttr));
}
$filesInfo->type = $request->get('type', 'default');
$filesInfo->attach($fileObj);
$this->get('session')->set('file_upload_' . $sessionAttr, $filesInfo->serialize());
$data = array('success' => true, 'file' => $fileSettings['upload_dir'] . '/' . $fileName, 'name' => $this->uploadFile->getClientOriginalName());
} else {
$data = array('success' => false, 'error' => $errorList[0]->getMessage());
}
}
return new JsonResponse($data);
}
示例2: SplObjectStorage
// 获得当前节点的值。也必须是调用rewind后,才可以调用getInfo。
$obj->getInfo();
// current()
// 获得当前节点对象
$obj->current();
// getHash()
// 获得参数的hash值
$obj->getHash($a2);
// next()
// 指针移到下一个节点
$obj->next();
// offsetExists
// 判断对象容器中是否存在该对象
$obj->offsetExists($a2);
// offsetSet()
// 给对象容器中的某个对象设置值
$obj->offsetSet($a2, 'BBB');
// offsetGet()
// 获得对象容器中的某个针对象对应的值
$obj->offsetGet($a2);
// offsetUnset()
// 将某节点删除
//$obj->offsetUnset($a1);
// serialize()
// 将对象容器序列化
$serialize_obj = $obj->serialize();
// unserialize()
// 将对象容器反序列化
$obj_2 = new SplObjectStorage();
$obj_2->unserialize($serialize_obj);
var_dump($obj_2);
示例3: SplObjectStorage
<?php
$s = new SplObjectStorage();
$o1 = new StdClass();
$o2 = new StdClass();
$s->attach($o1, "d1");
$s->attach($o2, "d2");
$serialized = $s->serialize();
$s2 = new SplObjectStorage();
$s2->unserialize($serialized);
var_dump($s == $s2);