dev-master
9999999-dev http://github.com/PHPFluent/JSONSerializerJSON Serializer implementation.
New BSD
The Requires
The Development Requires
JSON Serializer implementation.
JSON Serializer implementation.
, (*1)
Install:
shell
composer.phar require phpfluent/jsonserializer:dev-master
Usage:
```php
<?php
use PHPFluent\JSONSerializer\Serializer;, (*2)
class Nested extends Serializer { /** * @PHPFluent\JSONSerializer\Attribute */ private $array;, (*3)
public function setArray(array $array) { $this->array = $array; return $this; }
}, (*4)
class MyFancyClass extends Serializer { /** * @PHPFluent\JSONSerializer\Attribute */ private $email;, (*5)
/** * @PHPFluent\JSONSerializer\Attribute */ private $nested; private $iWontBeSerialized; public function setEmail($email) { if ( ! filter_var($email, FILTER_VALIDATE_EMAIL)) { throw new \InvalidArgumentException("Invalid email"); } $this->email = $email; return $this; } public function setNested(Nested $nested) { $this->nested = $nested; return $this; }
}, (*6)
$nested = (new Nested)->setArray(array(1, 2, 3)); $fancy = (new MyFancyClass)->setEmail("foo@bar.com")->setNested($nested);, (*7)
json_encode($fancy); /* $serialized = json_encode( (new MyFancyClass)->setEmail("foo@bar.com")->setNested( (new Nested)->setArray(array(1, 2, 3)) ); ); */, (*8)
```, (*9)
Test:
shell
cd phpfluent/jsonserializer
composer.phar install --dev
make test
, (*10)
JSON Serializer implementation.
New BSD