Skip to content

Commit

Permalink
Update JsonWrapper.php
Browse files Browse the repository at this point in the history
  • Loading branch information
parsidev committed Jun 15, 2015
1 parent 1a0ac3c commit 2b90e64
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions src/Parsidev/Json/JsonWrapper.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<?php namespace Parsidev\Json;

use Webmozart\Json\JsonDecoder;
use Webmozart\Json\JsonEncoder;

class JsonWrapper
{

Expand All @@ -15,22 +12,24 @@ public function __construct()
$this->encoder = new JsonEncoder;
}

public static function __callStatic($method, $parameters)
public function encoder($data, $schema = null)
{
return $this->encoder->encode($data, $schema);
}

public function encoderFile($data, $file, $schema = null)
{
$this->encoder->encodeFile($data, $file, $schema);
}


public function decoder($json, $schema = null)
{
$self = new static;
return $self->__call($method, $parameters);
return $this->decoder->decode($json, $schema);
}

public function __call($method, $parameters)
public function decoderFile($file, $schema = null)
{
$encoder = new ReflectionClass(JsonEncoder::class);
if ($encoder->hasMethod($method)) {
return call_user_func_array(array($this->encoder, $method), $parameters);
}
$decoder = new ReflectionClass(JsonDecoder::class);
if ($decoder->hasMethod($method)) {
return call_user_func_array(array($this->decoder, $method), $parameters);
}
throw new BadMethodCallException;
return $this->decoder->decodeFile($file, $schema);
}
}
}

0 comments on commit 2b90e64

Please sign in to comment.