Skip to content
This repository was archived by the owner on Jan 8, 2024. It is now read-only.

Commit 1671411

Browse files
committed
Updated docs & samples
1 parent 64a17cc commit 1671411

File tree

8 files changed

+78
-98
lines changed

8 files changed

+78
-98
lines changed

README.md

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
[![Code Climate](https://codeclimate.com/github/PHPSocialNetwork/phpfastcache-bundle/badges/gpa.svg)](https://codeclimate.com/github/PHPSocialNetwork/phpfastcache-bundle) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/PHPSocialNetwork/phpfastcache-bundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/PHPSocialNetwork/phpfastcache-bundle/?branch=master) [![Build Status](https://travis-ci.org/PHPSocialNetwork/phpfastcache-bundle.svg?branch=master)](https://travis-ci.org/PHPSocialNetwork/phpfastcache-bundle) [![Latest Stable Version](http://img.shields.io/packagist/v/phpfastcache/phpfastcache-bundle.svg)](https://packagist.org/packages/phpfastcache/phpfastcache-bundle) [![Total Downloads](http://img.shields.io/packagist/dt/phpfastcache/phpfastcache-bundle.svg)](https://packagist.org/packages/phpfastcache/phpfastcache-bundle) [![Dependency Status](https://www.versioneye.com/php/phpfastcache:phpfastcache-bundle/badge.svg)](https://www.versioneye.com/php/phpfastcache:phpfastcache-bundle) [![License](https://img.shields.io/packagist/l/phpfastcache/phpfastcache-bundle.svg)](https://packagist.org/packages/phpfastcache/phpfastcache-bundle)
2-
# Symfony 3 PhpFastCache Bundle
2+
# Symfony 4 PhpFastCache Bundle
33

44
#### :warning: Please note that the V3 is a major (BC breaking) update of the PhpFastCache Bundle !
55
> As of the V3 the bundle is **absolutely** not compatible with previous versions.u the smoothest migration possible.
6-
One of the biggest change is the Phpfastcache's dependency which is not set to the v7 which it not backward compatible at all.
7-
Also please note that the bundle is currently in development and under a massive code rewrite.
8-
:warning: The code of the v3 is NOT production or development ready ATM.
9-
6+
> One of the biggest change is the Phpfastcache's dependency which is not set to the v7 which it not backward compatible at all.
107
118
#### :thumbsup: Step 1: Include phpFastCache Bundle in your project with composer:
129

1310
```bash
1411
composer require phpfastcache/phpfastcache-bundle
1512
```
1613

17-
#### :construction: Step 2: Setup your config.yml to configure your cache(s) instance(s)
18-
14+
#### :construction: Step 2: Setup your `config/packages/phpfastcache.yaml` to configure your cache(s) instance(s)
1915

2016
```yml
2117
# PhpFastCache configuration
22-
php_fast_cache:
18+
phpfastcache:
2319
twig_driver: "filecache" # This option must be a valid declared driver, in our example: "filecache"
2420
twig_block_debug: false # This option will wrap CACHE/ENDCACHE blocks with block debug as HTML comment
2521
drivers:
@@ -28,23 +24,15 @@ php_fast_cache:
2824
parameters:
2925
path: "%kernel.cache_dir%/phpfastcache/"
3026
```
31-
* More examples in Docs/Example/app/config
32-
33-
#### :wrench: Step 3: Setup your AppKernel.php by adding the phpFastCache Bundle
34-
35-
```php
36-
$bundles[] = new Phpfastcache\Bundle\phpFastCacheBundle();
37-
```
38-
39-
* See the file Docs/Example/app/AppKernel.php for more information.
27+
* This step can be skipped using [Symfony recipes](https://symfony.com/doc/current/setup/flex.html).
4028
41-
#### :rocket: Step 4: Accelerate your app by making use of PhpFastCache service
29+
#### :rocket: Step 3: Accelerate your app by making use of PhpFastCache service
4230
4331
Caching data in your controller:
4432
```php
45-
public function indexAction(Request $request)
33+
public function indexAction(Request $request, Phpfastcache $phpfastcache)
4634
{
47-
$cache = $this->get('phpfastcache')->get('filecache');
35+
$cache = $phpfastcache->get('filecache');
4836
$item = $cache->getItem('myAppData');
4937

5038
if (!$item->isHit() || $item->get() === null) {

src/Resources/Docs/CREDITS.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,15 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
SOFTWARE.
2121

2222

23-
phpFastCache Bundle Bundle Project Manager: Georges.L (Geolim4)
23+
phpFastCache Bundle Project Manager: Georges.L (Geolim4)
2424

2525
phpFastCache Bundle Contributors: https://github.com/PHPSocialNetwork/phpfastcache-bundle/graphs/contributors
2626

2727
Specials thanks:
2828

29-
- PastisD for helping us at the beginning of the project
29+
- PastisD for its momentous contributions
3030
- Alexander (asm89) for providing the great Twig Extension slightly modified and integrated to the PhpFastCache bundle
3131

32-
3332
Software licenses:
3433

3534
PHP License, version 3.0:

src/Resources/Docs/example/Controller/DefaultController.php

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace AppBundle\Controller;
44

5+
use Phpfastcache\Bundle\Service\Phpfastcache;
56
use Symfony\Component\Routing\Annotation\Route;
67
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
78
use Symfony\Component\HttpFoundation\Request;
@@ -12,30 +13,30 @@ class DefaultController extends Controller
1213
/**
1314
* @Route("/", name="homepage")
1415
*/
15-
public function indexAction(Request $request)
16+
public function indexAction(Request $request, Phpfastcache $phpfastcache)
1617
{
1718
$pfc_test = null;
1819

19-
$cache = $this->get('phpfastcache')->get('filecache');
20-
$cache2 = $this->get('phpfastcache')->get('memcachecache');
21-
$cache3 = $this->get('phpfastcache')->get('ssdbcache');
22-
$cache4 = $this->get('phpfastcache')->get('sqlitecache');
23-
$cache5 = $this->get('phpfastcache')->get('rediscache');
24-
$cache6 = $this->get('phpfastcache')->get('mongodbcache');
25-
$cache7 = $this->get('phpfastcache')->get('couchbasecache');
26-
$cache8 = $this->get('phpfastcache')->get('leveldbcache');
20+
$cache = $phpfastcache->get('filecache');
21+
$cache2 = $phpfastcache->get('memcachecache');
22+
$cache3 = $phpfastcache->get('ssdbcache');
23+
$cache4 = $phpfastcache->get('sqlitecache');
24+
$cache5 = $phpfastcache->get('rediscache');
25+
$cache6 = $phpfastcache->get('mongodbcache');
26+
$cache7 = $phpfastcache->get('couchbasecache');
27+
$cache8 = $phpfastcache->get('leveldbcache');
2728

2829
/**
2930
* Xcache and APC cannot coexists
3031
*/
3132
try{
32-
$cache9 = $this->get('phpfastcache')->get('apccache');
33-
$cache10 = $this->get('phpfastcache')->get('apcucache');
33+
$cache9 = $phpfastcache->get('apccache');
34+
$cache10 = $phpfastcache->get('apcucache');
3435
}catch(PhpfastcacheDriverCheckException $e){
35-
$cache11 = $this->get('phpfastcache')->get('xcachecache');
36+
$cache11 = $phpfastcache->get('xcachecache');
3637
}
3738

38-
$cache12 = $this->get('phpfastcache')->get('devnullcache');
39+
$cache12 = $phpfastcache->get('devnullcache');
3940

4041

4142
$item = $cache->getItem('test');

src/Resources/Docs/example/Screenshoots/debugPanel.md

Lines changed: 0 additions & 7 deletions
This file was deleted.
Binary file not shown.

src/Resources/Docs/example/app/AppKernel.php

Lines changed: 0 additions & 54 deletions
This file was deleted.

src/Resources/Docs/migration/MigratingFromV2ToV3.md

Lines changed: 54 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,57 @@ phpfastcache:
2929
parameters:
3030
path: "%kernel.cache_dir%/phpfastcache/"
3131
```
32-
Notice the change from "php_fast_cache" to "phpfastcache".
32+
Notice the change from "php_fast_cache" to "phpfastcache".
33+
34+
### Service container
35+
36+
We used to call the container getter to retrieve the "phpfastcache" service.
37+
#### :clock1: Then:
38+
```php
39+
<?php
40+
41+
namespace AppBundle\Controller;
42+
43+
use Symfony\Component\Routing\Annotation\Route;
44+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
45+
use Symfony\Component\HttpFoundation\Request;
46+
47+
class DefaultController extends Controller
48+
{
49+
/**
50+
* @Route("/", name="homepage")
51+
*/
52+
public function indexAction(Request $request)
53+
{
54+
$cache = $this->get('phpfastcache')->get('filecache');
55+
// ...
56+
}
57+
}
58+
```
59+
60+
#### :alarm_clock: Now:
61+
This is no longer possible since the service is now private and can be retrieved via the dependency injection
62+
using the Symfony [autowire](https://symfony.com/doc/current/service_container/autowiring.html) feature.
63+
```php
64+
<?php
65+
66+
namespace AppBundle\Controller;
67+
68+
use Symfony\Component\Routing\Annotation\Route;
69+
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
70+
use Symfony\Component\HttpFoundation\Request;
71+
use Phpfastcache\Bundle\Service\Phpfastcache;
72+
73+
class DefaultController extends Controller
74+
{
75+
/**
76+
* @Route("/", name="homepage")
77+
*/
78+
public function indexAction(Request $request, Phpfastcache $phpfastcache)
79+
{
80+
$cache = $phpfastcache->get('filecache');
81+
// ...
82+
}
83+
}
84+
```
85+

0 commit comments

Comments
 (0)