Skip to content

Commit

Permalink
Added 404 header support
Browse files Browse the repository at this point in the history
More efficient error support
  • Loading branch information
Xavier Coureau committed Aug 1, 2014
1 parent e12089d commit 62e1436
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions Controller/WordpressController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@

namespace Ekino\WordpressBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

use Ekino\WordpressBundle\Wordpress\WordpressResponse;
use Ekino\WordpressBundle\Wordpress\Wordpress;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpKernel\Exception\NotAcceptableHttpException;

/**
* Class WordpressController
Expand All @@ -27,10 +28,20 @@ class WordpressController extends Controller
* Wordpress catch-all route action
*
* @return WordpressResponse
*
* @throws NotAcceptableHttpException
*/
public function catchAllAction()
{
return $this->getWordpress()->initialize()->getResponse();
$content = $this->getWordpress()->getContent();

global $wp_query;

if (!$wp_query) {
throw new NotAcceptableHttpException('The "$wp_query" wordpress global variable is not defined');
}

return new WordpressResponse($content, $wp_query->is_404() ? WordpressResponse::HTTP_NOT_FOUND : WordpressResponse::HTTP_OK);
}

/**
Expand Down

0 comments on commit 62e1436

Please sign in to comment.