Skip to content

Commit

Permalink
Merge pull request #14 from ytake/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
ytake committed Nov 22, 2014
2 parents eec0883 + 89d2519 commit 2de3bb4
Show file tree
Hide file tree
Showing 15 changed files with 202 additions and 165 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ php:
- 5.5
- 5.6
- hhvm
services:
- memcached

before_script:
- "sudo apt-get install php5-memcached"
- "phpenv config-add travis.php.ini"
- composer self-update
- composer install
- chmod -R 777 tests/storage

script:
- mkdir -p build/logs
- chmod -R 777 build/logs
- phpunit

after_script:
- php vendor/bin/coveralls -v

notifications:
emails:
- [email protected]
32 changes: 31 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,36 @@ $ php artisan ytake:smarty-optimize
| --extension (-e) | specified smarty file extension(default: *.tpl*) |
| --force | compiles template files found in views directory |

Template Caching
==================
**choose file, memcached, Redis**
(default file cache driver)

テンプレートキャッシュドライバにファイルキャッシュ、memcached, Redisが選択できます
デフォルトは通常のファイルキャッシュになっています
```php
// smarty cache driver "file", "memcached", "redis"
'cache_driver' => 'file',

// memcached servers
'memcached' => [
[
'host' => '127.0.0.1',
'port' => 11211,
'weight' => 100
],
],

// redis configure
'redis' => [
[
'host' => '127.0.0.1',
'port' => 6379,
'database' => 0,
],
],
```

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

Expand All @@ -102,7 +132,7 @@ app/config配下のapp.phpのproviders配列に以下のnamespaceを追加して
add providers
```php
'providers' => [
'Ytake\LaravelSmarty\SmartyServiceProvider'
'Ytake\LaravelSmarty\SmartyServiceProvider'
]
```

Expand Down
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
"smarty/smarty": "3.*@stable"
},
"require-dev": {
"predis/predis": "0.*",
"predis/predis": "0.*",
"symfony/framework-bundle": "2.*",
"symfony/console": "2.*",
"phpunit/phpunit": "4.*",
"mockery/mockery": "0.*",
"satooshi/php-coveralls": "dev-master"
},
"suggest": {
"ext-memcached": "memcached Template Cache Driver",
"predis/predis": "Redis Template Cache Driver"
},
"suggest": {
"ext-memcached": "memcached Template Cache Driver",
"predis/predis": "Redis Template Cache Driver"
},
"autoload": {
"psr-4": {
"Ytake\\LaravelSmarty\\": "src/Smarty"
Expand Down
6 changes: 3 additions & 3 deletions src/Smarty/Cache/Memcached.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public function __construct(MemcachedExtendion $memcached, array $servers)
* @param array $servers
* @return \Memcached
*/
public function connection(MemcachedExtendion $memcached, array $servers)
protected function connection(MemcachedExtendion $memcached, array $servers)
{
foreach ($servers as $server) {
$memcached->addServer($server['host'], $server['port'], $server['weight']);
$memcached->addServer($server['host'], $server['port'], $server['weight']);
}
return $memcached;
return $memcached;
}


Expand Down
26 changes: 13 additions & 13 deletions src/Smarty/Cache/Redis.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
class Redis extends \Smarty_CacheResource_KeyValueStore
{

/** @var Client */
/** @var Client */
protected $redis;

/**
* @param array $servers
*/
/**
* @param array $servers
*/
public function __construct(array $servers)
{
if(count($servers) === 1) {
$this->redis = new Client($servers[0]);
} else {
$this->redis = new Client($servers);
}
if(count($servers) === 1) {
$this->redis = new Client($servers[0]);
} else {
$this->redis = new Client($servers);
}
}

/**
Expand All @@ -42,9 +42,9 @@ protected function read(array $keys)
$lookup[$_k] = $k;
}
$_res = [];
foreach($_keys as $key) {
$_res[$lookup[$key]] = $this->redis->get($key);
}
foreach($_keys as $key) {
$_res[$lookup[$key]] = $this->redis->get($key);
}
return $_res;
}

Expand All @@ -58,7 +58,7 @@ protected function write(array $keys, $expire = null)
{
foreach ($keys as $k => $v) {
$k = sha1($k);
$this->redis->setex($k, $expire, $v);
$this->redis->setex($k, $expire, $v);
}
return true;
}
Expand Down
34 changes: 17 additions & 17 deletions src/Smarty/Cache/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,30 @@ public function __construct(Smarty $smarty, Repository $repository)
*/
protected function cacheStorageManaged()
{
$driver = $this->repository->get('laravel-smarty::cache_driver', 'file');
if($driver !== 'file') {
$storage = $driver . "Storage";
$this->smarty->registerCacheResource($driver, $this->$storage());
}
$this->smarty->caching_type = $driver;
$driver = $this->repository->get('laravel-smarty::cache_driver', 'file');
if($driver !== 'file') {
$storage = $driver . "Storage";
$this->smarty->registerCacheResource($driver, $this->$storage());
}
$this->smarty->caching_type = $driver;
}

/**
* @return Redis
*/
protected function redisStorage()
/**
* @return Redis
*/
protected function redisStorage()
{
return new Redis($this->repository->get('laravel-smarty::redis'));
return new Redis($this->repository->get('laravel-smarty::redis'));
}

/**
* @return Memcached
*/
protected function memcachedStorage()
/**
* @return Memcached
*/
protected function memcachedStorage()
{
return new Memcached(
new \Memcached(),
$this->repository->get('laravel-smarty::memcached')
new \Memcached(),
$this->repository->get('laravel-smarty::memcached')
);
}
}
34 changes: 17 additions & 17 deletions src/Smarty/Console/CacheClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,24 @@ public function __construct(Smarty $smarty)
$this->smarty = $smarty;
}

/**
* The console command name.
* @var string
*/
protected $name = 'ytake:smarty-clear-cache';
/**
* The console command name.
* @var string
*/
protected $name = 'ytake:smarty-clear-cache';

/**
* The console command description.
* @var string
*/
protected $description = 'Flush the smarty cache';
/**
* The console command description.
* @var string
*/
protected $description = 'Flush the smarty cache';

/**
* Execute the console command.
* @return void
*/
public function fire()
{
/**
* Execute the console command.
* @return void
*/
public function fire()
{
// clear all cache
if(is_null($this->option('file'))) {
$this->smarty->clearAllCache($this->option('time'));
Expand All @@ -56,7 +56,7 @@ public function fire()
}
$this->info('specified file was cache cleared!');
return;
}
}

/**
* Get the console command options.
Expand Down
34 changes: 17 additions & 17 deletions src/Smarty/Console/CompiledClearCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,30 @@ public function __construct(Smarty $smarty)
$this->smarty = $smarty;
}

/**
* The console command name.
* @var string
*/
protected $name = 'ytake:smarty-clear-compiled';
/**
* The console command name.
* @var string
*/
protected $name = 'ytake:smarty-clear-compiled';

/**
* The console command description.
* @var string
*/
protected $description = 'Remove the compiled smarty file';
/**
* The console command description.
* @var string
*/
protected $description = 'Remove the compiled smarty file';

/**
* Execute the console command.
* @return void
*/
public function fire()
{
/**
* Execute the console command.
* @return void
*/
public function fire()
{
if($this->smarty->clearCompiledTemplate($this->option('file'), $this->option('compile_id'))) {
$this->info('done.');
return;
}
return;
}
}

/**
* Get the console command options.
Expand Down
34 changes: 17 additions & 17 deletions src/Smarty/Console/CompiledCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ public function __construct(Smarty $smarty, Repository $config)
$this->config = $config;
}

/**
* The console command name.
* @var string
*/
protected $name = 'ytake:smarty-optimize';
/**
* The console command name.
* @var string
*/
protected $name = 'ytake:smarty-optimize';

/**
* The console command description.
* @var string
*/
protected $description = 'compiles all known templates';
/**
* The console command description.
* @var string
*/
protected $description = 'compiles all known templates';

/**
* Execute the console command.
* @return void
*/
public function fire()
{
/**
* Execute the console command.
* @return void
*/
public function fire()
{
$configureFileExtension = $this->config->get('laravel-smarty::extension', 'tpl');
$fileExtension = (is_null($this->option('extension'))) ? $configureFileExtension : $this->option('extension');
ob_start();
Expand All @@ -59,7 +59,7 @@ public function fire()
$this->info("{$compileFiles} template files recompiled");
$this->comment(str_replace("<br>", "\n", trim($contents)));
return;
}
}

/**
* Get the console command options.
Expand Down
Loading

0 comments on commit 2de3bb4

Please sign in to comment.