-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added writeJsonObject method for write JsonSerializable object (#10)
- Loading branch information
Showing
4 changed files
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ | |
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Tests\\Fixtures\\": "tests/fixtures" | ||
} | ||
}, | ||
"scripts": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Tests\Fixtures; | ||
|
||
use JsonSerializable; | ||
|
||
class JsonObject implements JsonSerializable | ||
{ | ||
|
||
/** @var string */ | ||
private $foo; | ||
|
||
/** | ||
* JsonObject constructor. | ||
* | ||
* @param string $foo | ||
*/ | ||
public function __construct($foo) | ||
{ | ||
$this->foo = $foo; | ||
} | ||
|
||
/** | ||
* Specify data which should be serialized to JSON | ||
* | ||
* @link http://php.net/manual/en/jsonserializable.jsonserialize.php | ||
* @return mixed data which can be serialized by <b>json_encode</b>, which is a value of any type other than a resource. | ||
* @since 5.4.0 | ||
*/ | ||
public function jsonSerialize() | ||
{ | ||
return ['foo' => $this->foo]; | ||
} | ||
|
||
} |