Skip to content

Commit

Permalink
Don't PHP serialize the data but save the data in the data property i…
Browse files Browse the repository at this point in the history
…nstead
  • Loading branch information
Pim Widdershoven committed Dec 29, 2014
1 parent 860237f commit 731ea02
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
6 changes: 2 additions & 4 deletions EventListener/AjaxResponseListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,8 @@ public function onKernelResponse(FilterResponseEvent $event)
return;
}

// Get PHP serialized content - serialize()
$content = $response->getContent();
// Deserialize it
$data = unserialize($content);
// Get the data
$data = $response->getData();

// Do nothing if the type is a redirect
if ($data['type'] == AjaxResponse::TYPE_REDIRECT) {
Expand Down
20 changes: 18 additions & 2 deletions Response/AjaxResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,25 @@ public function __construct($content = '', $type = self::TYPE_DATA, $data = null
// serialization context configured by the YAML files on the entities. If a new serialization context class
// is initialized in this class we don't know what the settings are in the YAML files. We can't access these
// configuration files because that would result in a massive performance degradation.
// INFO: This isn't a really nice solution but it's only possible to add a string to the content
parent::__construct(serialize($this->data), $status, $headers);
// The AjaxResponseListener will serialize the data property and set the content of the response
parent::__construct('', $status, $headers);
// Set content type
$this->headers->set('Content-Type', 'application/json');
}

/**
* @return array
*/
public function getData()
{
return $this->data;
}

/**
* @param array $data
*/
public function setData($data)
{
$this->data = $data;
}
}

0 comments on commit 731ea02

Please sign in to comment.