当前位置: 首页>>代码示例>>PHP>>正文


PHP SplObjectStorage::unserialize方法代码示例

本文整理汇总了PHP中SplObjectStorage::unserialize方法的典型用法代码示例。如果您正苦于以下问题:PHP SplObjectStorage::unserialize方法的具体用法?PHP SplObjectStorage::unserialize怎么用?PHP SplObjectStorage::unserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SplObjectStorage的用法示例。


在下文中一共展示了SplObjectStorage::unserialize方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
 }
开发者ID:brainlabs,项目名称:NFCUploadBundle,代码行数:43,代码来源:UploadController.php

示例2: handleFilesAndSave

 public function handleFilesAndSave($field, $dir, $json = false)
 {
     $this->sessionAttr = 'file_upload_' . $field;
     if ($this->session->has($this->sessionAttr)) {
         $filesInfo = new \SplObjectStorage();
         $filesInfo->unserialize($this->session->get($this->sessionAttr));
         if ($this->config[$filesInfo->type]['type'] == 'file') {
             $result = $this->saveFiles($filesInfo, $dir);
         } elseif ($this->config[$filesInfo->type]['type'] == 'image') {
             $result = $this->saveImages($filesInfo, $dir, $this->config[$filesInfo->type]['thumbnails']);
         } else {
             throw new \Exception('Unrecognized file type!');
         }
         $this->clearSessionAttr();
         if ($json) {
             $result = json_encode($result);
         }
         return $result;
     } else {
         return false;
     }
 }
开发者ID:brainlabs,项目名称:NFCUploadBundle,代码行数:22,代码来源:FileHandler.php

示例3: SplObjectStorage

<?php

try {
    $s = new SplObjectStorage();
    $s->unserialize('s:31:"something which is not an array";');
} catch (UnexpectedValueException $e) {
    var_dump($e->getMessage());
}
var_dump($s->count() == 0);
echo "===RUN2===\n";
try {
    $s = new SplObjectStorage();
    $s->unserialize('s:60:"something broken";');
} catch (UnexpectedValueException $e) {
    var_dump($e->getMessage());
}
var_dump($s->count() == 0);
开发者ID:badlamer,项目名称:hhvm,代码行数:17,代码来源:serialize_bad.php

示例4: array

<?php

$data_provider = array(array(), new stdClass());
foreach ($data_provider as $input) {
    $s = new SplObjectStorage();
    var_dump($s->unserialize($input));
}
开发者ID:badlamer,项目名称:hhvm,代码行数:7,代码来源:SplObjectStorage_unserialize_invalid_parameter1.php

示例5: SplObjectStorage

<?php

$s = new SplObjectStorage();
try {
    $s->unserialize(NULL);
} catch (UnexpectedValueException $e) {
    echo $e->getMessage();
}
开发者ID:clifton98,项目名称:hhvm,代码行数:8,代码来源:SplObjectStorage_unserialize_invalid_parameter3.php

示例6: SplObjectStorage

echo 'serialize $myStorage into $serializedString';
echo '<br />';
echo 'create new SplObjectStorage as $ourStorageObject';
echo '<br />';
echo 'unserialize $serializedString into $ourStorageObject';
echo '<br />';
echo 'var_dump $myStorage and $ourStorageObject';
echo '<br />';
echo 'Is it the same object as $myStorage?';
echo '<br />';
echo 'result: ';
echo "    It worked.  It's the same object.";
echo '<br /><br />';
$serializedString = $myStorage->serialize();
$ourStorageObject = new SplObjectStorage();
$ourStorageObject->unserialize($serializedString);
var_dump($myStorage);
echo '<br /><br />';
echo '------------------------';
echo '<br /><br />';
var_dump($ourStorageObject);
echo '<br /><br />';
?>
    </pre>
    
    <p><a href="../index.html">back to data structures list</a></p>
    <!-- END CUSTOM CONTENT -->
    
    <!-- JAVASCRIPT FILES -->
    <!-- libraries go here -->
    
开发者ID:roypenrod,项目名称:my-php-playground,代码行数:30,代码来源:index.php

示例7: 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);
开发者ID:ray0916,项目名称:learn,代码行数:31,代码来源:splObjectStorage.php

示例8: array

<?php

$badblobs = array('x:i:2;i:0;,i:1;;i:0;,i:2;;m:a:0:{}', 'x:i:3;O:8:"stdClass":0:{},O:8:"stdClass":0:{};R:2;,i:1;;O:8:"stdClass":0:{},r:2;;m:a:0:{}', 'x:i:3;O:8:"stdClass":0:{},O:8:"stdClass":0:{};r:2;,i:1;;O:8:"stdClass":0:{},r:2;;m:a:0:{}', 'x:i:1;O:8:"stdClass":0:{},N;;m:s:40:"1234567890123456789012345678901234567890"');
foreach ($badblobs as $blob) {
    try {
        $so = new SplObjectStorage();
        $so->unserialize($blob);
        var_dump($so);
    } catch (UnexpectedValueException $e) {
        echo $e->getMessage() . "\n";
    }
}
echo "DONE\n";
开发者ID:badlamer,项目名称:hhvm,代码行数:13,代码来源:SplObjectStorage_unserialize_bad.php

示例9: array

<?php

$data_provider = array(12345, 1.2345, PHP_INT_MAX, 'x:rubbish', 'x:i:2;O:8:"stdClass":0:{},s:5:"value";;m:a:0:{}');
foreach ($data_provider as $input) {
    $s = new SplObjectStorage();
    try {
        $s->unserialize($input);
    } catch (UnexpectedValueException $e) {
        echo $e->getMessage() . PHP_EOL;
    }
}
开发者ID:badlamer,项目名称:hhvm,代码行数:11,代码来源:SplObjectStorage_unserialize_invalid_parameter2.php

示例10: 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);
开发者ID:badlamer,项目名称:hhvm,代码行数:11,代码来源:serialize.php


注:本文中的SplObjectStorage::unserialize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。