/** * @inheritdoc */ public function sanitize($input) { if (!is_string($input)) { return $input; } return Serialize::unserialize($input, false); }
/** * Unserialize. * * @param string $value serialized array * @param array $params params: * * - key * - separator * * @return string */ public static function unserialize($value, array $params) { if (empty($value)) { return null; } if (!empty($params['key'])) { return ArrayHelper::getValue(Serialize::unserialize($value, false), explode(Helper::getValue($params['separator'], '.'), $params['key'])); } return Serialize::unserialize($value, false); }
/** * Callback to replace variables template. * * @param array $matches array of variables template. * @throws TemplateException * @return string */ protected function replaceCallback($matches) { if (!empty($matches['beforeSkip']) && !empty($matches['afterSkip'])) { return trim($matches[0], '{!} '); } // check: count quotes does not parity if (!NumericHelper::isParity(mb_substr_count($matches[0], '`', 'UTF-8'))) { return $matches[0]; } $matches[0] = preg_replace_callback('/ \\s*(?P<sugar> (?!`)\\*(?!`) | (?!`)\\*\\*(?!`) | (?!`)\\/(?!`) | (?!`)\\%(?!`) | \\s+(?!`)mod(?!`)\\s+ | (?!`)\\+(?!`) | (?!`)\\-(?!`) | (?!`)\\|(?!`) | (?!`)\\&(?!`) | (?!`)\\^(?!`) | (?!`)\\>\\>(?!`) | (?!`)\\<\\<(?!`) | (?!`)\\|\\|(?!`) | (?!`)\\&\\&(?!`) | \\s+(?!`)' . $this->_getInlineConditionNames() . '(?!`)\\s+ |`\\s+\\?\\s+|`\\s+\\:\\s+)\\s*` /x', [$this, 'replaceSugar'], $matches[0]); // replace `=` tpl mnemonics $matches[0] = preg_replace('/`([\\!\\<\\>]?)[\\=]+`/', '`$1=`', $matches[0]); // replace `text` to ““text”” $matches[0] = preg_replace(['/=\\s*\\`/', '/\\`/'], ['=““', '””'], $matches[0]); // replacement of internal recursion on {{{...}}} $i = 0; $dataRecursive = []; $matches[0] = preg_replace_callback('/\\“\\“(?:[^\\“\\”]++|(?R))*\\”\\”/iu', function ($value) use(&$dataRecursive, &$i) { $key = '{{{' . $i . '}}}'; $value = current($value); $dataRecursive[$key] = $value; $i++; return $key; }, $matches[0]); // Search params is variable of template $params = $this->_searchParams($matches[0], $dataRecursive); // Search of filters (modifiers) $filters = $this->_searchFilters($matches[0], $dataRecursive); $matches['name'] = trim($matches['name']); $params = Serialize::unserializeRecursive($params); // returns cache list($cacheKey, $cacheExpire, $cacheTags) = $this->calculateCacheParams($params); if (($resultCache = $this->getCacheContent($cacheKey)) !== false) { return $resultCache; } $filters = Serialize::unserializeRecursive($filters); $sanitize = $this->sanitize; if (isset($params['sanitize'])) { $sanitize = $params['sanitize']; } elseif (!empty($matches['sanitizeDisable'])) { $sanitize = self::SANITIZE_DISABLE; } // chunk if ($matches['type'] === '$') { $result = $this->getChunk($matches['name'], $params); // alias } elseif ($matches['type'] === '@@') { $result = Alias::getAlias("@{$matches['name']}"); // placeholder } elseif ($matches['type'] === '+') { $result = $this->getPlaceholder($matches['name'], $sanitize); // constant } elseif ($matches['type'] === '++') { $result = $this->getConst($matches['name'], $sanitize); // extension } elseif ($matches['type'] === '#') { $result = $this->getExtension($matches['name'], $params, $sanitize); // i18n } elseif ($matches['type'] === '%') { $result = $this->_calculateI18N($matches['name'], Helper::getValue($params['placeholders'], []), Helper::getValue($params['locale']), Helper::getValue($params['category'])); // link } elseif ($matches['type'] === '~') { $result = $this->_calculateLink($matches['name'], $params); // snippet } elseif (empty($matches['type'])) { $result = $this->getSnippet($matches['name'], $params, $sanitize); } else { return $matches[0]; } // make a filter if (!empty($filters)) { $result = $this->makeFilter($result, $filters); } if ($this->autoSerialize) { if (is_array($result) || is_object($result) && !$result instanceof \Closure) { $result = @serialize($result); } } if (!is_scalar($result) && !empty($result)) { throw new TemplateException('Wrong type is var: ' . Json::encode($result)); } // sets a content to cache $this->setCacheContent($cacheKey, $result, $cacheExpire, $cacheTags ?: []); return $result; }
/** * @inheritdoc */ public function add($name, $value) { if (is_array($value)) { $value = Serialize::serialize($value, $this->serializator); } if (!setcookie($name, $value, $this->expire, $this->path, $this->domain, $this->secure, $this->httpOnly)) { throw new CookieException(CookieException::INVALID_SET); } $_COOKIE[$name] = $value; }
/** * @param string $itemName * @return Item * @throws RBACException */ protected function processData($itemName) { if (empty(static::$items[$itemName]['data'])) { throw new RBACException(RBACException::NOT_DATA_PARAMS); } $data = static::$items[$itemName]['data']; if (is_string($data)) { $data = Serialize::unserialize($data); } if ($data instanceof Item) { $data->name = $itemName; return $data; } throw new RBACException(RBACException::UNKNOWN_TYPE, ['name' => serialize($data)]); }
/** * Unserialize value. * @param $value * @return mixed */ protected function unserialize($value) { return Serialize::unserialize($value, false); }
/** * Convert object to multi-array (recursive). * * @param mixed $value current object * @param array $only list of items whose value needs to be returned. * @param array $exclude list of items whose value should NOT be returned. * @param bool $unserialize * @return array */ public static function toArray($value, array $only = [], array $exclude = [], $unserialize = false) { if (is_array($value)) { return static::map($value, function ($value) use($only, $exclude, $unserialize) { return static::toArray($value, $only, $exclude, $unserialize); }, true); } if (is_object($value) && !$value instanceof \Closure) { if ($value instanceof Arrayable) { $attributes = $value->toArray($only, $exclude); } else { $attributes = $value instanceof \stdClass && isset($value->scalar) ? $value->scalar : get_object_vars($value); } if (is_array($attributes)) { return static::toArray($attributes, $only, $exclude, $unserialize); } $value = $attributes; } return $unserialize === true ? Serialize::unserialize($value, false) : $value; }