Last active
January 25, 2017 19:18
-
-
Save janit/9b5b08a8d5512be78696192f0bb2fec1 to your computer and use it in GitHub Desktop.
AppState.php from https://www.symfony.fi/entry/sharing-state-in-a-symfony-hybrid-app-with-twig-react-etc
This file contains hidden or 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
<?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