Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
stelin committed Mar 21, 2018
2 parents 310dc48 + 9c4d386 commit c6c4c63
Show file tree
Hide file tree
Showing 40 changed files with 606 additions and 256 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ temp/
.phpintel/
.DS_Store
/.php_cs.cache
test/runtime
61 changes: 28 additions & 33 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,34 @@
<?php
$header = <<<EOF
This file is part of PHP CS Fixer.
(c) Fabien Potencier <[email protected]>
Dariusz Rumiński <[email protected]>
This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.

$header = <<<'EOF'
This file is part of Swoft.
@link https://swoft.org
@document https://doc.swoft.org
@contact [email protected]
@license https://github.com/swoft-cloud/swoft/blob/master/LICENSE
EOF;

return PhpCsFixer\Config::create()
// ->setRiskyAllowed(true)
// ->setRules(array(
// '@Symfony' => true,
// '@Symfony:risky' => true,
// 'array_syntax' => array('syntax' => 'long'),
// 'combine_consecutive_unsets' => true,
// // one should use PHPUnit methods to set up expected exception instead of annotations
// 'general_phpdoc_annotation_remove' => array('expectedException', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp'),
// 'header_comment' => array('header' => $header),
// 'heredoc_to_nowdoc' => true,
// 'no_extra_consecutive_blank_lines' => array('break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'),
// 'no_unreachable_default_argument_value' => true,
// 'no_useless_else' => true,
// 'no_useless_return' => true,
// 'ordered_class_elements' => true,
// 'ordered_imports' => true,
// 'php_unit_strict' => true,
// 'phpdoc_add_missing_param_annotation' => true,
// 'phpdoc_order' => true,
// 'psr4' => true,
// 'strict_comparison' => true,
// 'strict_param' => true,
// ))
->setRiskyAllowed(true)
->setRules([
'header_comment' => [
'commentType' => 'PHPDoc',
'header' => $header,
'separate' => 'none'
],
'array_syntax' => [
'syntax' => 'short'
],
'single_quote' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->in('src')
->in('test')
->exclude('public')
->exclude('resources')
->exclude('config')
->exclude('runtime')
->exclude('vendor')
->in(__DIR__)
)
;
?>
->setUsingCache(false);
8 changes: 5 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,12 @@
},
"require-dev": {
"eaglewu/swoole-ide-helper": "dev-master",
"phpunit/phpunit": "^5.7"
"phpunit/phpunit": "^5.7",
"friendsofphp/php-cs-fixer": "^2.10"
},
"autoload-dev": {
"psr-4": {
"Swoft\\Test\\": "test"
"SwoftTest\\": "test/Cases"
}
},
"repositories": {
Expand All @@ -45,6 +46,7 @@
}
},
"scripts": {
"test": "./vendor/bin/phpunit -c phpunit.xml"
"test": "./vendor/bin/phpunit -c phpunit.xml",
"cs-fix": "./vendor/bin/php-cs-fixer fix $1"
}
}
27 changes: 27 additions & 0 deletions src/Helper/DirHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,4 +272,31 @@ public static function directoryIterator(

return new \RecursiveIteratorIterator($filterIterator);
}

/**
* @param string $path
* @return bool
*/
public static function deleteDirectory($path): bool
{
try {
$directoryIterator = new \DirectoryIterator($path);
foreach ($directoryIterator as $fileInfo) {
if ($fileInfo->valid() && $fileInfo->isExecutable()) {
if ($fileInfo->isDot()) {
continue;
} elseif ($fileInfo->isDir()) {
if (self::deleteDirectory($fileInfo->getPathname())) {
rmdir($fileInfo->getPathname());
}
} elseif ($fileInfo->isFile()) {
unlink($fileInfo->getPathname());
}
}
}
} catch (\Throwable $e) {
return false;
}
return true;
}
}
14 changes: 14 additions & 0 deletions src/Helper/Functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,20 @@ function bean($name)
}
}

if (! function_exists('alias')) {
/**
* Get alias
*
* @param string $alias
* @return string
* @throws \InvalidArgumentException
*/
function alias($alias): string
{
return \Swoft\App::getAlias($alias);
}
}

if (! function_exists('request')) {
/**
* Get the current Request object from RequestContext
Expand Down
Loading

0 comments on commit c6c4c63

Please sign in to comment.