コード例 #1
0
ファイル: SerializerTest.php プロジェクト: link0/profiler
 public function testSerialization()
 {
     $foo = array('foo' => 'bar');
     $serializedData = $this->serializer->serialize($foo);
     $unserializedData = $this->serializer->unserialize($serializedData);
     $this->assertEquals($foo, $unserializedData);
 }
コード例 #2
0
ファイル: Filesystem.php プロジェクト: fwk/cache
 /**
  *
  * @param string $fileName
  * @param string $contents 
  * 
  * @return int
  */
 public function write(\Fwk\Cache\CacheEntry $entry)
 {
     $fileInfos = implode(DIRECTORY_SEPARATOR, array($this->cacheDirectory, md5('cacheKey:' . $entry->getKey()) . '.cache'));
     $fileContents = implode(DIRECTORY_SEPARATOR, array($this->cacheDirectory, md5('cacheKey:' . $entry->getKey())));
     $entry->setSerializer($this->serializer);
     $serialized = $entry->getSerializedContents();
     file_put_contents($fileInfos, $this->serializer->serialize($entry));
     file_put_contents($fileContents, $serialized);
     return true;
 }
コード例 #3
0
 static function serializeArray($array)
 {
     $newArray = array();
     foreach ($array as $object) {
         array_push($newArray, Serializer::serialize($object));
     }
     return $newArray;
 }
コード例 #4
0
ファイル: XSLTView.class.php プロジェクト: tejdeeps/tejcs.com
 /**
  * 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);
 }
コード例 #5
0
 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;
 }
コード例 #6
0
ファイル: Database.php プロジェクト: fwk/cache
 /**
  *
  * @param string $fileName
  * @param string $contents 
  * 
  * @return int
  */
 public function write(\Fwk\Cache\CacheEntry $entry)
 {
     if ($this->exists($entry->getKey())) {
         $this->delete($entry->getKey());
     }
     $maxAge = $entry->getMaxAge();
     if (is_object($maxAge)) {
         $maxAge = $this->serializer->serialize($maxAge);
     }
     $query = "INSERT INTO %s VALUES (%s,%s,%s,%s)";
     $stmt = $this->pdo->exec(sprintf($query, $this->options['table.infos'], $this->pdo->quote($entry->getKey()), $this->pdo->quote($entry->getCreatedOn()), $this->pdo->quote($maxAge), $this->pdo->quote(implode(self::TAGS_SEPARATOR, $entry->getTags()))));
     $entry->setSerializer($this->serializer);
     $query = "INSERT INTO %s VALUES (%s, %s)";
     $stmt = $this->pdo->exec(sprintf($query, $this->options['table.entries'], $this->pdo->quote($entry->getKey()), $this->pdo->quote($entry->getSerializedContents())));
     return true;
 }
コード例 #7
0
ファイル: Client.php プロジェクト: spinx/sidekiq-job-php
 /**
  * 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]);
     }
 }
コード例 #8
0
 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;
         }
     }
 }
コード例 #9
0
 /**
  * @param  mixed         $object
  * @param  resource|bool $stream
  * @param  string        $format
  * @return mixed
  */
 public function serialize($object, $stream, $format = null)
 {
     return $this->serializer->serialize($object, $this->type, $stream, $format ?: $this->format, $this->options);
 }
コード例 #10
0
ファイル: ArrayConverter.php プロジェクト: martyn82/apha
 /**
  * @param array $data
  * @param string $type
  * @return object
  */
 private function reconstructType(array $data, string $type)
 {
     return $this->serializer->deserialize($this->serializer->serialize($data), $type);
 }
コード例 #11
0
ファイル: ArraySerializable.php プロジェクト: cawaphp/cawa
 /**
  * @return array
  */
 public function arraySerialize() : array
 {
     $data = Serializer::serialize($this);
     return $data;
 }
コード例 #12
0
ファイル: Fetcher.php プロジェクト: moneyphp/iso-currencies
 /**
  * @param $fileName
  * @param Serializer $serializer
  */
 public function saveTo($fileName, Serializer $serializer)
 {
     $this->fetch();
     file_put_contents($fileName, $serializer->serialize($this->countries));
 }
コード例 #13
0
ファイル: Serializable.php プロジェクト: cawaphp/cawa
 /**
  * @return string
  */
 public function serialize() : string
 {
     $data = Serializer::serialize($this);
     return serialize($data);
 }
コード例 #14
0
 public function serialize(Serializer $serializer)
 {
     return $serializer->serialize($this);
 }
コード例 #15
0
 public function toJSON()
 {
     $serializer = new Serializer();
     return $serializer->serialize($this);
 }
コード例 #16
0
ファイル: Error.php プロジェクト: xud/jimber-php-framework
 public function serialize()
 {
     return Serializer::serialize($this);
 }
コード例 #17
0
ファイル: Response.php プロジェクト: lukaskorl/restful
 /**
  * Create YAML response
  *
  * @param array $vars
  * @param int $status
  * @param array $header
  * @return \Illuminate\Http\Response
  */
 public function yaml(array $vars, $status = 200, array $header = [])
 {
     return $this->make($this->serializer->serialize($vars, 'yml'), $status, $header);
 }