Skip to content

Instantly share code, notes, and snippets.

@janit
Last active January 25, 2017 19:18
Show Gist options
  • Save janit/9b5b08a8d5512be78696192f0bb2fec1 to your computer and use it in GitHub Desktop.
Save janit/9b5b08a8d5512be78696192f0bb2fec1 to your computer and use it in GitHub Desktop.
<?php
namespace AppBundle\State;
use Symfony\Component\Serializer\Serializer;
use Symfony\Component\Serializer\Encoder\JsonEncoder;
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
class AppState implements \JsonSerializable {
public $fetchMore = false;
public $sortBy = false;
public $selectedCountry = false;
public $apartments = [];
public function jsonSerialize() {
$encoders = array(new JsonEncoder());
$normalizers = array(new ObjectNormalizer());
$serializer = new Serializer($normalizers, $encoders);
return $serializer->serialize($this, 'json');
}
/**
* @return string
*/
public function getSortBy()
{
return $this->sortBy;
}
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment