Skip to content

Commit

Permalink
Added new option to delete view cache files after render.
Browse files Browse the repository at this point in the history
  • Loading branch information
TerrePorter committed Feb 9, 2016
2 parents 9fa8c0a + 8e1ffc5 commit 6891118
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
27 changes: 20 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,27 @@ This version 1 is for Laravel 4.2, version 2 is for Laravel 5.

Version 3 is a complete rewrite, for Laravel 5.1

Version 3.2 is version update for Laravel 5.2
Version 3.2 is a version update for packagist, for Laravel 5.2.

Installation
=======================

Add to composer.json using

Add the package to composer.json:

"require": {
"laravel/framework": "5.2.*",
"wpb/string-blade-compiler": "3.2.0"
"laravel/framework": "5.1.*",
"wpb/string-blade-compiler": "VERSION"
},

On packagist.org at https://packagist.org/packages/wpb/string-blade-compiler

Or from the console using require: composer require "wpb/string-blade-compiler:3.2.*"
Or from the console using require: composer require "wpb/string-blade-compiler:VERSION"

To get versions 'composer show wpb/string-blade-compiler', such as 'dev-master, * 3.2.x-dev, 3.2.0, 3.0.x-dev, 3.0.0, 2.1.0, 2.0.x-dev, 2.0.0, 1.0.x-dev, 1.0.0'

In config\app.php, providers section:

Replace "Illuminate\View\ViewServiceProvider::class" with "Wpb\String_Blade_Compiler\ViewServiceProvider::class",
Replace 'Illuminate\View\ViewServiceProvider::class' with 'Wpb\String_Blade_Compiler\ViewServiceProvider::class',

There is no need to add a Facade to the aliases array as the service provider it is included automatically in the package's ServiceProvider.

Expand All @@ -46,6 +46,8 @@ Default cache time for the compiled string template is 300 seconds (5 mins), thi

Note: If using homestead or some other vm, the host handles the filemtime of the cache file. This means the vm may have a different time than the file. If the cache is not expiring as expected, check the times between the systems.

Note: See new option below to delete view cache after rendering (works for both stringblade and blade compilers).

Usage
=======================

Expand Down Expand Up @@ -129,6 +131,17 @@ Changing the tags

'escapeFlag', if true then the tags will be escaped, if false then they will not be escaped (same as setContentTagsEscaped function)

Deleting generated compiled cach view files (v3+),

Set the delete flag for the compiler being used, stringblade or blade
```
// set flag to delete compiled view cache files after rendering for stringblade compiler
View::getEngineFromStringKey('stringblade')->setDeleteViewCacheAfterRender(true);
// set flag to delete compiled view cache files after rendering for blade compiler
View::getEngineFromStringKey('blade')->setDeleteViewCacheAfterRender(true);
```

License
=======================

Expand Down
14 changes: 14 additions & 0 deletions src/Engines/CompilerEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

class CompilerEngine extends \Illuminate\View\Engines\CompilerEngine
{
/**
* Bool Flag to Enable/Disable removal of the generated view cache file.
*
* @var bool
*/
public $deleteViewCacheAfterRender = false;

/**
* Get the evaluated contents of the view.
Expand Down Expand Up @@ -44,4 +50,12 @@ public function get($path, array $data = [])
return $results;
}

/**
* Set the delete view cache after render flag.
*
* @param bool $delete
*/
public function setDeleteViewCacheAfterRender($delete = true) {
$this->deleteViewCacheAfterRender = $delete;
}
}
13 changes: 13 additions & 0 deletions src/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,19 @@ public function getEngineFromPath($path)
return $this->engines->resolve($engine);
}

/**
* Get the appropriate view engine for the given string key.
*
* @param string $stringkey
* @return \Illuminate\View\Engines\EngineInterface
*
* @throws \InvalidArgumentException
*/
public function getEngineFromStringKey($stringkey)
{
return $this->engines->resolve($stringkey);
}

/**
* Get the extension used by the view file.
*
Expand Down

0 comments on commit 6891118

Please sign in to comment.