Exemple #1
0
 public function testSerialization()
 {
     $foo = array('foo' => 'bar');
     $serializedData = $this->serializer->serialize($foo);
     $unserializedData = $this->serializer->unserialize($serializedData);
     $this->assertEquals($foo, $unserializedData);
 }
Exemple #2
0
 /**
  *
  * @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;
 }
 static function serializeArray($array)
 {
     $newArray = array();
     foreach ($array as $object) {
         array_push($newArray, Serializer::serialize($object));
     }
     return $newArray;
 }
 /**
  * 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;
 }
Exemple #6
0
 /**
  *
  * @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;
 }
Exemple #7
0
 /**
  * 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]);
     }
 }
 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;
         }
     }
 }
 /**
  * @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);
 }
Exemple #10
0
 /**
  * @param array $data
  * @param string $type
  * @return object
  */
 private function reconstructType(array $data, string $type)
 {
     return $this->serializer->deserialize($this->serializer->serialize($data), $type);
 }
Exemple #11
0
 /**
  * @return array
  */
 public function arraySerialize() : array
 {
     $data = Serializer::serialize($this);
     return $data;
 }
Exemple #12
0
 /**
  * @param $fileName
  * @param Serializer $serializer
  */
 public function saveTo($fileName, Serializer $serializer)
 {
     $this->fetch();
     file_put_contents($fileName, $serializer->serialize($this->countries));
 }
Exemple #13
0
 /**
  * @return string
  */
 public function serialize() : string
 {
     $data = Serializer::serialize($this);
     return serialize($data);
 }
 public function serialize(Serializer $serializer)
 {
     return $serializer->serialize($this);
 }
 public function toJSON()
 {
     $serializer = new Serializer();
     return $serializer->serialize($this);
 }
Exemple #16
0
 public function serialize()
 {
     return Serializer::serialize($this);
 }
Exemple #17
0
 /**
  * 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);
 }