本文整理汇总了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;
}
示例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));
}
示例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']);
}
}
}
示例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;
}