├── .gitignore ├── .whitesource ├── composer.json ├── provides.json ├── readme.md └── src └── VTalbot └── Pjax └── PjaxServiceProvider.php /.gitignore: -------------------------------------------------------------------------------- 1 | /vendor 2 | composer.phar 3 | composer.lock 4 | .DS_Store -------------------------------------------------------------------------------- /.whitesource: -------------------------------------------------------------------------------- 1 | ########################################################## 2 | #### WhiteSource Integration configuration file #### 3 | ########################################################## 4 | 5 | # Configuration # 6 | #---------------# 7 | ws.repo.scan=true 8 | vulnerable.check.run.conclusion.level=failure 9 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "vtalbot/pjax", 3 | "description": "PJAX for Laravel 4", 4 | "license": "MIT", 5 | "authors": [ 6 | { 7 | "name": "Vincent Talbot", 8 | "email": "vtalbot@re-bot.co" 9 | } 10 | ], 11 | "require": { 12 | "php": ">=5.3.0", 13 | "illuminate/support": "4.x" 14 | }, 15 | "autoload": { 16 | "psr-0": { 17 | "VTalbot\\Pjax": "src/" 18 | } 19 | }, 20 | "minimum-stability": "dev" 21 | } -------------------------------------------------------------------------------- /provides.json: -------------------------------------------------------------------------------- 1 | { 2 | "providers": [ 3 | "VTalbot\\Pjax\\PjaxServiceProvider" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## PJAX for Laravel 4 2 | 3 | Enable the use of PJAX in Laravel 4. 4 | 5 | If using **Laravel 5**, please see [jacobbennett/pjax](https://github.com/JacobBennett/pjax) 6 | 7 | #### Installation 8 | 9 | Add `vtalbot/pjax` to `require` section in your `composer.json` 10 | 11 | composer require vtalbot/pjax 12 | 13 | Add `'VTalbot\Pjax\PjaxServiceProvider',` to `providers` in your `app/config/app.php` 14 | 15 | #### How to use 16 | 17 | This service provider will check, before output the http response, for the `X-PJAX`'s 18 | header in the request. If found, it will crawl the response to return the requested 19 | element defined by `X-PJAX-Container`'s header. 20 | 21 | Works great with [jquery.pjax.js](https://github.com/defunkt/jquery-pjax). 22 | 23 | Example project: https://github.com/vtalbot/laravel-pjax-example 24 | 25 | ### Contribution 26 | 27 | I'm open to any idea of features to add to it. 28 | -------------------------------------------------------------------------------- /src/VTalbot/Pjax/PjaxServiceProvider.php: -------------------------------------------------------------------------------- 1 | app; 27 | 28 | $this->app->after(function(Request $request, Response $response) use ($app) { 29 | if ($response->isRedirection()) 30 | { 31 | return $response; 32 | } 33 | 34 | if ($request->server->get('HTTP_X_PJAX')) { 35 | $crawler = new Crawler($response->getContent()); 36 | 37 | $html = $crawler->filter($request->server->get('HTTP_X_PJAX_CONTAINER'))->html(); 38 | $title = $crawler->filter('head title')->html(); 39 | 40 | $response->setContent('