public function SerializeClass($ObjectInstance, $ClassName) { Serializer::$Data .= "<" . $ClassName . ">"; $Class = new ReflectionClass($ClassName); $ClassArray = array($ObjectInstance); $Properties = $Class->getProperties(); $i = 0; foreach ($ClassArray as $ClassMember) { $prpName = $Properties[$i]->getName(); Serializer::$Data .= "<" . $prpName . ">"; $prpType = gettype($ClassMember); if ($prpType == 'object') { $serializerinstance = new Serializer(); $serializerinstance->SerializeClass($ClassMember, get_class($ClassMember)); } if ($prpType == 'array') { $this->GetaArray($ClassMember); } else { Serializer::$Data .= $ClassMember; } Serializer::$Data .= "</" . $prpName . ">"; $i++; } Serializer::$Data .= "</" . $ClassName . ">"; return Serializer::$Data; }
/** * Load config. * * @param string $filename * * @return Config * * @throws \InvalidArgumentException */ public function load($filename) { $data = file_get_contents($filename); try { $config = $this->serializer->deserialize($data, Config::class, 'json'); } catch (UnexpectedValueException $exception) { throw new \InvalidArgumentException('Invalid configuration file', 0, $exception); } return $config; }
public function after($controller, $metadata, &$data) { if ($metadata->map && $metadata->item && isset($data[$metadata->item])) { switch ($_SERVER['HTTP_ACCEPT']) { case 'application/xml': case 'text/xml': content_type('application/xml'); echo Serializer::SerializeObject($data[$metadata->item], Serializer::FORMAT_XML, null, $metadata->map); die; break; case 'application/json': case 'text/json': case '*/*, application/json': content_type('text/json'); $response = Serializer::SerializeObject($data[$metadata->item], Serializer::FORMAT_JSON, null, $metadata->map); header("X-JSON:{$response}"); echo $response; die; break; case 'text/yaml': content_type('text/yaml'); echo Serializer::SerializeObject($data[$metadata->item], Serializer::FORMAT_YAML, null, $metadata->map); die; break; } } }
static function deSerializeArray($array) { $newArray = array(); foreach ($array as $string) { array_push($newArray, Serializer::deserialize($string)); } return $newArray; }
/** * Registers the reviver with the serializer. * * @throws UnserializationException */ public function __wakeup() { try { Serializer::registerReviver($this); } catch (\Exception $e) { // Preserving the exception trace by re-throwing or nesting crashes PHP... throw new UnserializationException($e->getMessage()); } }
/** * Sets common parameters and arguments for all XSLT views and displays this view. * @param Request $request Request * @param Response $response Response */ public function display(Request $request, Response $response) { $this->proc->importStyleSheet($this->template); if ($this->resource != null) { $xml = Serializer::serialize($this->resource); $this->doc->loadXML($xml); } $xml = $this->proc->transformToXML($this->doc); $response->write($xml); }
private function makeVideo(VideoServiceDetector $detector) { $user = Session::get('user'); $video = new Video(); $video->setSourceId($detector->getId()); $video->setUserid($user->getId()); $video->setAdded(null); $video->setType($detector->getType()->getId()); $video->setFeed(Serializer::serialize($detector->getFeed())); return $video; }
public function testUnserializeString() { //Valid string $result = Serializer::unserializeString('O:1:"a":1:{s:5:"value";s:3:"100";}'); $this->assertNotNull($result); $this->assertIsA($result, "Object"); //Invalid string $this->expectException("SerializerException"); $result = Serializer::unserializeString("{'Organization': 'ThinkUp Documentation Team'}"); $this->assertNull($result); }
/** * * @param string $fileName * * @return CacheEntry */ public function readEntry($key) { if (!$this->exists($key)) { return false; } $fileInfos = implode(DIRECTORY_SEPARATOR, array($this->cacheDirectory, md5('cacheKey:' . $key) . '.cache')); $contents = file_get_contents($fileInfos); $entry = $this->serializer->unserialize($contents); if (!$entry instanceof \Fwk\Cache\CacheEntry) { throw new \Fwk\Cache\Exceptions\ReadError("contents is not a valid CacheEntry"); } $entry->setSerializer($this->serializer); return $entry; }
public function __construct() { header('access-control-allow-origin: *'); if ($this->checkMethod($_SERVER['REQUEST_METHOD']) && ($file = $this->getInputFile())) { $parser = new Parser($this->getPostValue('from'), $_FILES['input']['name'], $this->getPostValue('title')); $this->logs = []; $parser->setLogger($this); try { $dictionary = $parser->parse($file); $parserLogs = $this->logs; $serializer = new Serializer($this->getPostValue('to') ?? '汎用辞書'); $this->logs = []; $serializer->setLogger($this); $outputFile = $serializer->serialize($dictionary); $serializerLogs = $this->logs; $formData = new xmlhttprequest\FormData(); $formData->append('output', $outputFile['bytes'], $outputFile['name'], $outputFile['type']); if ($parserLogs) { $parserLogsFile = $this->convertLogsToFile($parserLogs, _('構文解析時に1つ以上のロギングが発生しました。')); $formData->append('parser-logs', $parserLogsFile['bytes'], null, $parserLogsFile['type']); } if ($serializerLogs) { $serializerLogsFile = $this->convertLogsToFile($serializerLogs, _('直列化時に1つ以上のロギングが発生しました。')); $formData->append('serializer-logs', $serializerLogsFile['bytes'], null, $serializerLogsFile['type']); } header($formData->getContentType()); echo $formData->encode(); } catch (SyntaxException $e) { $this->responseError(['type' => 'https://github.com/esperecyan/dictionary-api/blob/master/malformed-syntax.md', 'title' => 'Malformed Syntax', 'status' => 400, 'detail' => $e->getMessage()]); } catch (SerializeExceptionInterface $e) { $this->responseError(['type' => 'https://github.com/esperecyan/dictionary-api/blob/master/serialize-error.md', 'title' => 'Serialize Error', 'status' => 400, 'detail' => $e->getMessage()]); } catch (\Throwable $e) { $this->responseError(['title' => 'Internal Server Error', 'status' => 500, 'detail' => _('ファイルの変換に失敗しました。')]); throw $e; } } }
/** * Push job to redis * * @param string $jobId * @param string $class * @param array $args * @param string $queue * @param bool $retry * @param float|null $doAt * @throws exception Exception */ private function atomicPush($jobId, $class, $args = [], $queue = self::QUEUE, $retry = true, $doAt = null) { if (array_values($args) !== $args) { throw new Exception('Associative arrays in job args are not allowed'); } if (!is_null($doAt) && !is_float($doAt) && is_string($doAt)) { throw new Exception('at argument needs to be in a unix epoch format. Use microtime(true).'); } $job = $this->serializer->serialize($jobId, $class, $args, $retry); if ($doAt === null) { $this->redis->sadd($this->name('queues'), $queue); $this->redis->lpush($this->name('queue', $queue), $job); } else { $this->redis->zadd($this->name('schedule'), [$job => $doAt]); } }
/** * Get fully-rendered HTML markup for this insight. * @param Insight $insight Test insight to render in HTML. * @return str Insight HTML with this insight */ protected function getRenderedInsightInHTML(Insight $insight) { if ($insight->related_data !== null && is_string($insight->related_data)) { $insight->related_data = Serializer::unserializeString($insight->related_data); } $view = new ViewManager(); $view->caching = false; $view->assign('insights', array($insight)); $view->assign('expand', true); $view->assign('tpl_path', THINKUP_WEBAPP_PATH . 'plugins/insightsgenerator/view/'); $view->assign('enable_bootstrap', true); $view->assign('thinkup_application_url', Utils::getApplicationURL()); $view->assign('site_root_path', 'https://thinkup.thinkup.com/'); $html_insight = $view->fetch(THINKUP_WEBAPP_PATH . '_lib/view/insights.tpl'); return $html_insight; }
/** * * @param string $fileName * * @return CacheEntry */ public function readEntry($key) { $query = "SELECT * FROM %s WHERE `key` = ? LIMIT 1"; $stmt = $this->pdo->prepare(sprintf($query, $this->options['table.infos'])); $stmt->execute(array($key)); $res = $stmt->fetch(); if (!$res) { throw new \Fwk\Cache\Exceptions\ReadError("invalid CacheEntry key: {$key}"); } $entry = new \Fwk\Cache\CacheEntry(null, $key); $entry->setCreatedOn($res['created_on']); $entry->setKey($res['key']); if (strlen($res['max_age']) > 50) { $maxAge = $this->serializer->unserialize($res['max_age']); } else { $maxAge = $res['max_age']; } $entry->setMaxAge($maxAge); $entry->setSerializer($this->serializer); return $entry; }
/** * {@inheritdoc} */ public function unserializeable($data) { return Serializer::unserializeable($data); }
/** * @expectedException \Link0\Profiler\SerializerException * @expectedExceptionMessage Unable to unserialize data: FDSAfoobar */ public function testUnexpectedDataToThrowException() { $this->serializer->unserialize('FDSAfoobar'); }
/** * @param array $data * @param string $type * @return object */ private function reconstructType(array $data, string $type) { return $this->serializer->deserialize($this->serializer->serialize($data), $type); }
/** * @param array $serialized */ public function arrayUnserialize(array $serialized) { Serializer::unserialize($this, $serialized); }
<?php error_reporting(E_ALL); ini_set('display_errors', 1); require_once 'Serializer.php'; //borramos todas las estrellas guardadas $arrId = Serializer::showIds(); $arrId = array_filter($arrId); asort($arrId); $respon = array(); foreach ($arrId as $arr) { echo unlink("./database/{$arr}"); }
/** * @param string $serialized */ public function jsonUnserialize(string $serialized) { Serializer::unserialize($this, json_decode($serialized, true)); }
/** * Get serializer with default visitors * @return Serializer */ public static function getSerializer() { $serializer = new Serializer(); $serializer->setVisitor(new Visitors\Json())->setVisitor(new Visitors\UrlEncode())->setVisitor(new Visitors\MultipartFormData()); return $serializer; }
public function getMostRecentInsight($slug, $instance_id) { $q = "SELECT * FROM #prefix#insights WHERE instance_id=:instance_id "; $q .= " AND slug=:slug "; $q .= "ORDER BY time_updated DESC LIMIT 1"; $vars = array(':instance_id' => $instance_id, ":slug" => $slug); if ($this->profiler_enabled) { Profiler::setDAOMethod(__METHOD__); } $ps = $this->execute($q, $vars); $insight = $this->getDataRowAsObject($ps, "Insight"); if ($insight->related_data !== null) { try { $insight->related_data = Serializer::unserializeString($insight->related_data); } catch (SerializerException $e) { $insight->related_data = null; } } return $insight; }
<?php error_reporting(E_ALL); ini_set('display_errors', 1); require_once 'Serializer.php'; require_once 'Star.php'; //Actualizamos al estrella recibida $starString = $_REQUEST['star']; $obj = json_decode($starString); $star = new Star($obj->id, $obj->posX, $obj->posY, $obj->size, $obj->type, $obj->playerName); Serializer::save($star, $star->id); //devolvemos un array con todas las estrellas $arrId = Serializer::showIds(); $arrId = array_filter($arrId); asort($arrId); $respon = array(); foreach ($arrId as $arr) { $obj = Serializer::restore($arr); array_push($respon, $obj); } $json = json_encode($respon); echo $json;
public function serialize() { return Serializer::serialize($this); }
public function getDataByPath($path, $expands) { $part = explode('/', $path); if ($part[0] != '') { throw new InvalidArgument("URI should start with a slash: " . $path); } $serializer = new Serializer($this); $typeName = $part[1]; $type = $this->getType($typeName); if (isset($part[2])) { $resourceId = $part[2]; $resource = new Resource($type, $resourceId); $resource = $this->loadResource($resource, $expands); $data = $serializer->serializeResource($resource); return $data; } else { $collection = $this->getResourceCollection($typeName); $data = $serializer->serializeCollection($collection); return $data; } }
public function toJSON() { $serializer = new Serializer(); return $serializer->serialize($this); }
protected function getVideoDetails() { $unserialized = Serializer::unserialize($this->video->getFeed()); return XMLLoader::loadString($unserialized); }
/** * @param resource|string $stream * @param mixed $object * @param string $format * @return mixed */ public function unserialize($stream, &$object = null, $format = null) { return $this->serializer->unserialize($stream, $format ?: $this->format, $this->type, $this->options, $object); }
/** * @param $fileName * @param Serializer $serializer */ public function saveTo($fileName, Serializer $serializer) { $this->fetch(); file_put_contents($fileName, $serializer->serialize($this->countries)); }
/** * @param string $serialized */ public function unserialize($serialized) { Serializer::unserialize($this, unserialize($serialized)); }
/** * @param int $maxDepth * @param string $configurationPath */ public function __construct($maxDepth = self::MAX_DEPTH_NOT_SET, $configurationPath = '') { parent::__construct(self::FORMAT_JSON, $maxDepth, $configurationPath); }