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


PHP Library::smartUnserialize方法代码示例

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


在下文中一共展示了Library::smartUnserialize方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: __construct

 public function __construct(Silex\Application $app)
 {
     $this->app = $app;
     $currentuser = $this->app['users']->getCurrentUser();
     $stackItems = false;
     if (isset($_SESSION['stack'])) {
         $stackItems = Lib::smartUnserialize($_SESSION['stack']);
     }
     if (!is_array($stackItems)) {
         $stackItems = Lib::smartUnserialize($currentuser['stack']);
     }
     if (!is_array($stackItems)) {
         $stackItems = [];
     }
     // intersect the allowed types with the types set
     $this->imagetypes = array_intersect($this->imagetypes, $app['config']->get('general/accept_file_types'));
     $this->documenttypes = array_intersect($this->documenttypes, $app['config']->get('general/accept_file_types'));
     $this->items = $stackItems;
 }
开发者ID:Johardmeier,项目名称:bolt,代码行数:19,代码来源:Stack.php

示例2: testSmartUnserialize

 public function testSmartUnserialize()
 {
     $json = json_encode(range(1, 100));
     $this->assertEquals(Library::smartUnserialize($json), range(1, 100));
     $php = serialize(range(1, 100));
     $this->assertEquals(Library::smartUnserialize($php), range(1, 100));
 }
开发者ID:johndotcat,项目名称:bolt,代码行数:7,代码来源:BoltLibraryTest.php

示例3: setValues

 /**
  * Set a Contenttype record's values.
  *
  * @param array $values
  */
 public function setValues(array $values)
 {
     // Since Bolt 1.4, we use 'ownerid' instead of 'username' in the DB tables. If we get an array that has an
     // empty 'ownerid', attempt to set it from the 'username'. In $this->setValue the user will be set, regardless
     // of ownerid is an 'id' or a 'username'.
     if (empty($values['ownerid']) && !empty($values['username'])) {
         $values['ownerid'] = $values['username'];
         unset($values['username']);
     }
     foreach ($values as $key => $value) {
         if ($key !== 'templatefields') {
             $this->setValue($key, $value);
         }
     }
     // If default status is set in contentttype.
     if (empty($this->values['status']) && isset($this->contenttype['default_status'])) {
         $this->values['status'] = $this->contenttype['default_status'];
     }
     $serializedFieldTypes = ['geolocation', 'imagelist', 'image', 'file', 'filelist', 'video', 'select', 'templateselect', 'checkbox'];
     // Check if the values need to be unserialized, and pre-processed.
     foreach ($this->values as $key => $value) {
         if (in_array($this->fieldtype($key), $serializedFieldTypes) || $key == 'templatefields') {
             if (!empty($value) && is_string($value) && (substr($value, 0, 2) == "a:" || $value[0] === '[' || $value[0] === '{')) {
                 try {
                     $unserdata = Lib::smartUnserialize($value);
                 } catch (\Exception $e) {
                     $unserdata = false;
                 }
                 if ($unserdata !== false) {
                     $this->values[$key] = $unserdata;
                 }
             }
         }
         if ($this->fieldtype($key) == "video" && is_array($this->values[$key]) && !empty($this->values[$key]['url'])) {
             $video = $this->values[$key];
             // update the HTML, according to given width and height
             if (!empty($video['width']) && !empty($video['height'])) {
                 $video['html'] = preg_replace("/width=(['\"])([0-9]+)(['\"])/i", 'width=${1}' . $video['width'] . '${3}', $video['html']);
                 $video['html'] = preg_replace("/height=(['\"])([0-9]+)(['\"])/i", 'height=${1}' . $video['height'] . '${3}', $video['html']);
             }
             $responsiveclass = "responsive-video";
             // See if it's widescreen or not.
             if (!empty($video['height']) && $video['width'] / $video['height'] > 1.76) {
                 $responsiveclass .= " widescreen";
             }
             if (strpos($video['url'], "vimeo") !== false) {
                 $responsiveclass .= " vimeo";
             }
             $video['responsive'] = sprintf('<div class="%s">%s</div>', $responsiveclass, $video['html']);
             // Mark them up as Twig_Markup.
             $video['html'] = new \Twig_Markup($video['html'], 'UTF-8');
             $video['responsive'] = new \Twig_Markup($video['responsive'], 'UTF-8');
             $this->values[$key] = $video;
         }
         if ($this->fieldtype($key) == "date" || $this->fieldtype($key) == "datetime") {
             if ($this->values[$key] === "") {
                 $this->values[$key] = null;
             }
         }
     }
     // Template fields need to be done last
     // As the template has to have been selected
     if ($this->isRootType) {
         if (empty($values['templatefields'])) {
             $this->setValue('templatefields', []);
         } else {
             $this->setValue('templatefields', $values['templatefields']);
         }
     }
 }
开发者ID:somekoala,项目名称:bolt,代码行数:75,代码来源:ContentValuesTrait.php

示例4: setValue

 /**
  * Set a Contenttype record's individual value.
  *
  * @param string $key
  * @param mixed  $value
  */
 public function setValue($key, $value)
 {
     // Don't set templateFields if not a real contenttype
     if ($key === 'templatefields' && !$this->isRootType) {
         return;
     }
     // Check if the value need to be unserialized.
     if (is_string($value) && substr($value, 0, 2) === "a:") {
         try {
             $unserdata = Lib::smartUnserialize($value);
         } catch (\Exception $e) {
             $unserdata = false;
         }
         if ($unserdata !== false) {
             $value = $unserdata;
         }
     }
     if ($key == 'id') {
         $this->id = $value;
     }
     // Set the user in the object.
     if ($key === 'ownerid' && !empty($value)) {
         $this->user = $this->app['users']->getUser($value);
     }
     // Only set values if they have are actually a field.
     $allowedcolumns = self::getBaseColumns();
     $allowedcolumns[] = 'taxonomy';
     if (!isset($this->contenttype['fields'][$key]) && !in_array($key, $allowedcolumns)) {
         return;
     }
     if (in_array($key, ['datecreated', 'datechanged', 'datepublish', 'datedepublish'])) {
         if (!preg_match("/(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})/", $value)) {
             // @todo Try better date-parsing, instead of just setting it to
             // 'now' (or 'the past' for datedepublish)
             if ($key == 'datedepublish') {
                 $value = null;
             } else {
                 $value = date('Y-m-d H:i:s');
             }
         }
     }
     if ($key === 'templatefields') {
         if (is_string($value) || is_array($value)) {
             if (is_string($value)) {
                 try {
                     $unserdata = Lib::smartUnserialize($value);
                 } catch (\Exception $e) {
                     $unserdata = false;
                 }
             } else {
                 $unserdata = $value;
             }
             if (is_array($unserdata)) {
                 $templateContent = new Content($this->app, $this->getTemplateFieldsContentType(), [], false);
                 $value = $templateContent;
                 $this->populateTemplateFieldsContenttype($value);
                 $templateContent->setValues($unserdata);
             } else {
                 $value = null;
             }
         }
     }
     if (!isset($this->values['datechanged']) || !preg_match("/(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})/", $this->values['datechanged'])) {
         $this->values['datechanged'] = date("Y-m-d H:i:s");
     }
     $this->values[$key] = $value;
 }
开发者ID:peteryu1,项目名称:bolt,代码行数:73,代码来源:Content.php


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