Skip to content

Commit

Permalink
for composers
Browse files Browse the repository at this point in the history
  • Loading branch information
ytake committed Nov 25, 2016
1 parent 1bc0d1f commit 7f1a613
Show file tree
Hide file tree
Showing 32 changed files with 250 additions and 83 deletions.
25 changes: 25 additions & 0 deletions .php_cs
@@ -0,0 +1,25 @@
<?php

$finder = \Symfony\CS\Finder\DefaultFinder::create()
->in(['src'])->exclude(['src/config']);

return Symfony\CS\Config\Config::create()
->setUsingLinter(false)
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers([
'namespace_no_leading_whitespace',
'short_array_syntax',
'phpdoc_no_empty_return',
'phpdoc_inline_tag',
'phpdoc_no_access',
'phpdoc_scalar',
'phpdoc_var_without_name',
'self_accessor',
'single_blank_line_before_namespace',
'spaces_cast',
'no_empty_lines_after_phpdocs',
'short_echo_tag',
'phpdoc_order',
'whitespacy_lines',
])
->finder($finder);
5 changes: 5 additions & 0 deletions .sensiolabs.yml
@@ -0,0 +1,5 @@
global_exclude_dirs:
- vendor
- tests
exclude_patterns:
- src/Engines/SmartyTemplate.php
1 change: 1 addition & 0 deletions .travis.yml
Expand Up @@ -6,6 +6,7 @@ php:
- 7.0
- hhvm
services:
- redis-server
- memcached
before_script:
- composer self-update
Expand Down
4 changes: 0 additions & 4 deletions README.md
Expand Up @@ -79,9 +79,6 @@ publish to config directory

Of Course, Blade Template can also be used to Render Engine.

smartyテンプレート内にも*{{app_path()}}*等のヘルパーそのまま使用できます。
その場合、delimiterをbladeと同じものを指定しない様にしてください。

### configuration file (for Lumen)

Copy the `vendor/ytake/laravel-smarty/src/config/ytake-laravel-smarty.php` file to your local config directory
Expand Down Expand Up @@ -170,7 +167,6 @@ Hello Laravel.Smarty
```

## Artisan
キャッシュクリア、コンパイルファイルの削除がコマンドラインから行えます。
smarty's cache clear, remove compile class from Artisan(cli)

### Template cache clear
Expand Down
32 changes: 26 additions & 6 deletions composer.json
Expand Up @@ -17,21 +17,29 @@
],
"license": "MIT",
"require": {
"php": ">=5.4.0",
"php": ">=5.5.9",
"illuminate/support": "~5.0",
"illuminate/view": "~5.0",
"illuminate/config": "~5.0",
"illuminate/console": "~5.0",
"illuminate/events": "~5.0",
"smarty/smarty": "~3.0"
"smarty/smarty": "~3.1.30"
},
"require-dev": {
"predis/predis": "~1.0",
"symfony/framework-bundle": "~2.0",
"symfony/console": "~2.0",
"phpunit/phpunit": "~4.0",
"symfony/framework-bundle": "~2.0|~3.0",
"symfony/console": "~2.0|~3.0",
"phpunit/phpunit": "~4.0|~5.0",
"mockery/mockery": "*",
"satooshi/php-coveralls": "*"
"satooshi/php-coveralls": "*",
"phpmd/phpmd": "@stable",
"squizlabs/php_codesniffer": "~2.7",
"friendsofphp/php-cs-fixer": "^1.11.6",
"phpmetrics/phpmetrics": "^1.10.0",
"sebastian/phpcpd": "*",
"phploc/phploc": "*",
"pdepend/pdepend" : "^2.2.4",
"sensiolabs/security-checker": "^4.0.0"
},
"suggest": {
"ext-memcached": "memcached Template Cache Driver",
Expand All @@ -47,5 +55,17 @@
"tests/SmartyTestCase.php"
]
},
"scripts": {
"md": "php ./vendor/bin/phpmd src text ./phpmd.xml",
"quality-assurance": [
"php ./vendor/bin/phpunit",
"php ./vendor/bin/phpcpd src/"
],
"pdepend": "php ./vendor/bin/pdepend --summary-xml=tests/build/summary.xml --jdepend-chart=tests/quality-assurance/jdepend.svg --overview-pyramid=tests/quality-assurance/pyramid.svg src/",
"loc": "php ./vendor/bin/phploc src/ --log-xml=tests/quality-assurance/phploc.xml",
"cs": "php ./vendor/bin/php-cs-fixer fix",
"phpcs": "./vendor/bin/phpcs src/ --report-full --report-source --standard=PSR2 --colors",
"sc": "security-checker security:check ./composer.lock"
},
"minimum-stability": "stable"
}
50 changes: 50 additions & 0 deletions phpmd.xml
@@ -0,0 +1,50 @@
<ruleset
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://pmd.sf.net/ruleset/1.0.0"
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0 http://pmd.sf.net/ruleset_xml_schema.xsd"
xsi:noNamespaceSchemaLocation="http://pmd.sf.net/ruleset_xml_schema.xsd">
<!--codesize-->
<rule ref="rulesets/codesize.xml/CyclomaticComplexity">
<properties>
<property name="reportLevel" value="20"/>
</properties>
</rule>
<rule ref="rulesets/codesize.xml/NPathComplexity">
<properties>
<property name="minimum" value="200"/>
</properties>
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveClassComplexity">
<properties>
<property name="maximum" value="100"/>
</properties>
</rule>
<rule ref="rulesets/codesize.xml/ExcessiveClassLength"/>
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength"/>
<rule ref="rulesets/codesize.xml/ExcessiveParameterList"/>
<rule ref="rulesets/codesize.xml/ExcessivePublicCount"/>
<rule ref="rulesets/codesize.xml/TooManyFields"/>
<rule ref="rulesets/codesize.xml/TooManyMethods"/>
<!--design-->
<rule ref="rulesets/design.xml/EvalExpression"/>
<rule ref="rulesets/design.xml/ExitExpression"/>
<rule ref="rulesets/design.xml/GotoStatement" />
<rule ref="rulesets/design.xml/NumberOfChildren"/>
<rule ref="rulesets/design.xml/DepthOfInheritance"/>
<!-- <rule ref="rulesets/design.xml/CouplingBetweenObjects" /> -->
<!--naming-->
<rule ref="rulesets/naming.xml/ConstantNamingConventions"/>
<rule ref="rulesets/naming.xml/BooleanGetMethodName"/>
<!--unusedcode-->
<rule ref="rulesets/unusedcode.xml/UnusedFormalParameter"/>
<rule ref="rulesets/unusedcode.xml/UnusedLocalVariable"/>
<rule ref="rulesets/unusedcode.xml/UnusedPrivateField"/>
<rule ref="rulesets/unusedcode.xml/UnusedPrivateMethod"/>
<!--controversial-->
<rule ref="rulesets/controversial.xml/CamelCaseClassName"/>
<rule ref="rulesets/controversial.xml/CamelCasePropertyName"/>
<rule ref="rulesets/controversial.xml/CamelCaseMethodName"/>
<!--cleancode-->
<rule ref="rulesets/cleancode.xml/BooleanArgumentFlag"/>
<!-- <rule ref="rulesets/cleancode.xml/ElseExpression" /> -->
</ruleset>
2 changes: 1 addition & 1 deletion phpunit.xml
Expand Up @@ -17,7 +17,7 @@
</testsuites>
<filter>
<whitelist>
<directory>./src</directory>
<directory suffix=".php">./src/</directory>
<exclude>
<directory>./src/config</directory>
<file>./src/SmartyServiceProvider.php</file>
Expand Down
18 changes: 10 additions & 8 deletions src/Cache/KeyValueStorage.php
Expand Up @@ -15,30 +15,32 @@
* Copyright (c) 2014-2016 Yuuki Takezawa
*
*/

namespace Ytake\LaravelSmarty\Cache;

/**
* Class KeyValueStorage
*
* @author yuuki.takezawa<yuuki.takezawa@comnect.jp.net>
* @author yuuki.takezawa<yuuki.takezawa@comnect.jp.net>
* @license http://opensource.org/licenses/MIT MIT
*/
abstract class KeyValueStorage extends \Smarty_CacheResource_KeyValueStore
{
/**
* @param array $keys
* @param $_keys
* @param $lookup
* @param array $map
* @param array $lookup
*
* @return array
*/
protected function eachKeys(array $keys, $_keys, $lookup)
protected function eachKeys(array $keys, array $map, array $lookup)
{
foreach ($keys as $k) {
$_k = sha1($k);
$_keys[] = $_k;
$lookup[$_k] = $k;
$hash = sha1($k);
$map[] = $hash;
$lookup[$hash] = $k;
}
return array($_keys, $lookup);

return [$map, $lookup];
}
}
29 changes: 15 additions & 14 deletions src/Cache/Memcached.php
Expand Up @@ -15,6 +15,7 @@
* Copyright (c) 2014-2016 Yuuki Takezawa
*
*/

namespace Ytake\LaravelSmarty\Cache;

use Memcached as MemcachedExtension;
Expand All @@ -39,9 +40,10 @@ public function __construct(MemcachedExtension $memcached, array $servers)
}

/**
* @param array $servers
* @param MemcachedExtension $memcached
* @param array $servers
*
* @return \Memcached
* @return MemcachedExtension
*/
protected function connection(MemcachedExtension $memcached, array $servers)
{
Expand All @@ -58,18 +60,17 @@ protected function connection(MemcachedExtension $memcached, array $servers)
* @param array $keys list of keys to fetch
*
* @return array list of values with the given keys used as indexes
* @return boolean true on success, false on failure
*/
protected function read(array $keys)
{
$_keys = $lookup = [];
list($_keys, $lookup) = $this->eachKeys($keys, $_keys, $lookup);
$_res = [];
$res = $this->memcached->getMulti($_keys);
foreach ($res as $k => $v) {
$_res[$lookup[$k]] = $v;
$map = $lookup = [];
list($map, $lookup) = $this->eachKeys($keys, $map, $lookup);
$result = [];
$memcachedResult = $this->memcached->getMulti($map);
foreach ($memcachedResult as $k => $v) {
$result[$lookup[$k]] = $v;
}
return $_res;
return $result;
}

/**
Expand All @@ -78,7 +79,7 @@ protected function read(array $keys)
* @param array $keys list of values to save
* @param int $expire expiration time
*
* @return boolean true on success, false on failure
* @return bool true on success, false on failure
*/
protected function write(array $keys, $expire = null)
{
Expand All @@ -94,7 +95,7 @@ protected function write(array $keys, $expire = null)
*
* @param array $keys list of keys to delete
*
* @return boolean true on success, false on failure
* @return bool true on success, false on failure
*/
protected function delete(array $keys)
{
Expand All @@ -108,10 +109,10 @@ protected function delete(array $keys)
/**
* Remove *all* values from cache
*
* @return boolean true on success, false on failure
* @return bool true on success, false on failure
*/
protected function purge()
{
$this->memcached->flush();
return $this->memcached->flush();
}
}
20 changes: 10 additions & 10 deletions src/Cache/Redis.php
Expand Up @@ -15,6 +15,7 @@
* Copyright (c) 2014-2016 Yuuki Takezawa
*
*/

namespace Ytake\LaravelSmarty\Cache;

use Predis\Client;
Expand Down Expand Up @@ -48,17 +49,16 @@ public function __construct(array $servers)
* @param array $keys list of keys to fetch
*
* @return array list of values with the given keys used as indexes
* @return boolean true on success, false on failure
*/
protected function read(array $keys)
{
$_keys = $lookup = [];
list($_keys, $lookup) = $this->eachKeys($keys, $_keys, $lookup);
$_res = [];
foreach ($_keys as $key) {
$_res[$lookup[$key]] = $this->redis->get($key);
$map = $lookup = [];
list($map, $lookup) = $this->eachKeys($keys, $map, $lookup);
$result = [];
foreach ($map as $key) {
$result[$lookup[$key]] = $this->redis->get($key);
}
return $_res;
return $result;
}

/**
Expand All @@ -67,7 +67,7 @@ protected function read(array $keys)
* @param array $keys list of values to save
* @param int $expire expiration time
*
* @return boolean true on success, false on failure
* @return bool true on success, false on failure
*/
protected function write(array $keys, $expire = 1)
{
Expand All @@ -83,7 +83,7 @@ protected function write(array $keys, $expire = 1)
*
* @param array $keys list of keys to delete
*
* @return boolean true on success, false on failure
* @return bool true on success, false on failure
*/
protected function delete(array $keys)
{
Expand All @@ -97,7 +97,7 @@ protected function delete(array $keys)
/**
* Remove *all* values from cache
*
* @return boolean true on success, false on failure
* @return bool true on success, false on failure
*/
protected function purge()
{
Expand Down
2 changes: 1 addition & 1 deletion src/Cache/Storage.php
Expand Up @@ -15,6 +15,7 @@
* Copyright (c) 2014-2016 Yuuki Takezawa
*
*/

namespace Ytake\LaravelSmarty\Cache;

use Ytake\LaravelSmarty\Smarty;
Expand Down Expand Up @@ -45,7 +46,6 @@ public function __construct(Smarty $smarty, ConfigContract $repository)
}

/**
* @return void
*/
public function cacheStorageManaged()
{
Expand Down

0 comments on commit 7f1a613

Please sign in to comment.