Skip to content

Commit 3ce96e0

Browse files
committed
+ add phpfmt script & settings
1 parent 36801c3 commit 3ce96e0

File tree

6 files changed

+223
-1
lines changed

6 files changed

+223
-1
lines changed

.phpfmt.ini

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,44 @@ visibility_order = 1
5555
; yoda = 0
5656

5757
; 需要执行的代码修正命令
58-
passes = WrongConstructorName,ReplaceBooleanAndOr,EliminateDuplicatedEmptyLines,RTrim,RestoreComments,UpgradeToPreg,IndentTernaryConditions,StripSpaceWithinControlStructures,StripExtraCommaInList,PrettyPrintDocBlocks,SpaceBetweenMethods,NoSpaceAfterPHPDocBlocks,ShortArray,DoubleToSingleQuote,LeftAlignComment,IndentTernaryConditions,AlignDoubleSlashComments,RemoveUseLeadingSlash,MergeElseIf,ClassToSelf,ClassToStatic,Reindent,ReindentEqual,ReindentObjOps,ReindentComments,ReindentAndAlignObjOps,ReindentSwitchBlocks,ReindentColonBlocks,PSR1OpenTags,PSR1ClassNames,PSR1ClassConstants,PSR1BOMMark,PSR2AlignObjOp,PSR2EmptyFunction,PSR2CurlyOpenNextLine,PSR2LnAfterNamespace,PSR2KeywordsLowerCase,PSR2IndentWithSpace,PSR2SingleEmptyLineAndStripClosingTag,PSR2ModifierVisibilityStaticOrder,NormalizeLnAndLtrimLines
58+
passes = WrongConstructorName
59+
ReplaceBooleanAndOr
60+
EliminateDuplicatedEmptyLines
61+
RTrim
62+
RestoreComments
63+
UpgradeToPreg
64+
IndentTernaryConditions
65+
StripSpaceWithinControlStructures
66+
StripExtraCommaInList
67+
PrettyPrintDocBlocks
68+
SpaceBetweenMethods
69+
NoSpaceAfterPHPDocBlocks
70+
ShortArray
71+
DoubleToSingleQuote
72+
LeftAlignComment
73+
IndentTernaryConditions
74+
AlignDoubleSlashComments
75+
RemoveUseLeadingSlash
76+
MergeElseIf
77+
ClassToSelf
78+
ClassToStatic
79+
Reindent
80+
ReindentEqual
81+
ReindentObjOps
82+
ReindentComments
83+
ReindentAndAlignObjOps
84+
ReindentSwitchBlocks
85+
ReindentColonBlocks
86+
PSR1OpenTags
87+
PSR1ClassNames
88+
PSR1ClassConstants
89+
PSR1BOMMark
90+
PSR2AlignObjOp
91+
PSR2EmptyFunction
92+
PSR2CurlyOpenNextLine
93+
PSR2LnAfterNamespace
94+
PSR2KeywordsLowerCase
95+
PSR2IndentWithSpace
96+
PSR2SingleEmptyLineAndStripClosingTag
97+
PSR2ModifierVisibilityStaticOrder
98+
NormalizeLnAndLtrimLines

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2013 container-interop
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# PHPFMT-tool
2+
3+
## Installation
4+
5+
```
6+
wget --no-check-certificate https://github.com/zhouyl/phpfmt-tool/raw/master/phpfmt -O /usr/local/bin/phpfmt
7+
chmod +x /usr/local/bin/phpfmt
8+
```
9+
10+
## Usage
11+

composer.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "zhouyl/phpfmt-tool",
3+
"type": "library",
4+
"description": "PHPFMT Command Tool",
5+
"homepage": "https://github.com/zhouyl/phpfmt-tool",
6+
"license": "MIT",
7+
"authors": [
8+
{
9+
"name": "zhouyl",
10+
"email": "81438567@qq.com"
11+
}
12+
],
13+
"require": {
14+
"php": ">=5.6.0",
15+
"ext-pcntl": "*",
16+
"ext-sysvsem": "*",
17+
"ext-sysvshm": "*",
18+
"ext-sysvmsg": "*"
19+
}
20+
}

phpfmt

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#!/usr/bin/env bash
2+
3+
php=`which php`
4+
5+
fmtconf=$PWD/.phpfmt.ini
6+
dirconf=$PWD/.phpfmtdirs
7+
fmthome=$HOME/.phpfmt
8+
fmtphar=$fmthome/fmt.phar
9+
10+
# url prefix for phpfmt & configuration download
11+
downurl="--no-check-certificate https://raw.githubusercontent.com/zhouyl/phpfmt-tool/master"
12+
13+
# download file from the remote repository
14+
download() {
15+
target=$(basename $1)
16+
wget $downurl/$target -qO $1 &
17+
18+
echo -e "\033[0;34mwget $downurl/$target -qO $1\033[0m"
19+
20+
while [ true ]; do
21+
n=$(ps aux | grep wget | grep "$1" | wc -l)
22+
if [ $n = "0" ]; then
23+
echo -ne " Done!\n\n"
24+
break
25+
else
26+
echo -ne ">"
27+
sleep 1
28+
fi
29+
done
30+
}
31+
32+
if [ ! -d $fmthome ]; then
33+
mkdir -p $fmthome
34+
fi
35+
36+
if [ ! -f $fmtconf ]; then
37+
fmtconf=$fmthome/.phpfmt.ini
38+
echo "Use the global configuration file: $fmtconf"
39+
40+
if [ ! -f $fmtconf ]; then
41+
echo "Download the global configuration file: $fmtconf ..."
42+
download $fmtconf
43+
fi
44+
else
45+
echo "Use the custom configuration file: $fmtconf"
46+
fi
47+
48+
if [ ! -f $fmtphar ]; then
49+
echo "Download the phpfmt.phar: $fmtphar"
50+
download $fmtphar
51+
fi
52+
53+
# get the target directories
54+
if [ -f $dirconf ]; then
55+
dirs=$(cat $dirconf)
56+
fi
57+
58+
# check the php version
59+
ver=$($php -r "echo version_compare(PHP_VERSION, '5.6.0') >= 0 ? 'yes' : 'no';")
60+
if [ $ver != "yes" ]; then
61+
echo -e "\033[0;41mPlease use php 5.6.0 or above version! ($php)\033[0m"
62+
exit 0
63+
fi
64+
65+
# check php dependent extensions
66+
ext=$($php -r "echo extension_loaded('pcntl') && extension_loaded('sysvsem') && extension_loaded('sysvshm') && extension_loaded('sysvmsg') ? 'yes' : 'no';")
67+
if [ $ext != "yes" ]; then
68+
echo -e "\033[0;41mPlease recompile php and add configuration these parameters: --enable-sysvsem --enable-sysvshm --enable-sysvmsg --enable-pcntl\033[0m"
69+
exit 0
70+
fi
71+
72+
echo -e "\n\033[0;33m[Execute]\033[0m $php $fmtphar --config=$fmtconf $dirs $*\n"
73+
74+
$php $fmtphar --config=$fmtconf $dirs $*

phpfmt.sublime-settings

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"autoimport": true,
3+
"disable_auto_align": false,
4+
"enable_auto_align": true,
5+
"format_on_save": true,
6+
"indent_with_space": true,
7+
"passes":
8+
[
9+
"ReplaceBooleanAndOr",
10+
"EliminateDuplicatedEmptyLines",
11+
"RTrim",
12+
"RestoreComments",
13+
"UpgradeToPreg",
14+
"IndentTernaryConditions",
15+
"StripSpaceWithinControlStructures",
16+
"StripExtraCommaInList",
17+
"PrettyPrintDocBlocks",
18+
"SpaceBetweenMethods",
19+
"NoSpaceAfterPHPDocBlocks",
20+
"ShortArray",
21+
"DoubleToSingleQuote",
22+
"LeftAlignComment",
23+
"IndentTernaryConditions",
24+
"AlignDoubleSlashComments",
25+
"RemoveUseLeadingSlash",
26+
"MergeElseIf",
27+
"ClassToSelf",
28+
"ClassToStatic",
29+
"Reindent",
30+
"ReindentEqual",
31+
"ReindentObjOps",
32+
"ReindentComments",
33+
"ReindentAndAlignObjOps",
34+
"ReindentSwitchBlocks",
35+
"ReindentColonBlocks",
36+
"PSR1OpenTags",
37+
"PSR1ClassNames",
38+
"PSR1ClassConstants",
39+
"PSR1BOMMark",
40+
"PSR2AlignObjOp",
41+
"PSR2EmptyFunction",
42+
"PSR2CurlyOpenNextLine",
43+
"PSR2LnAfterNamespace",
44+
"PSR2KeywordsLowerCase",
45+
"PSR2IndentWithSpace",
46+
"PSR2SingleEmptyLineAndStripClosingTag",
47+
"PSR2ModifierVisibilityStaticOrder",
48+
"NormalizeLnAndLtrimLines"
49+
],
50+
"php_bin": "/usr/local/php7/bin/php",
51+
"psr1": true,
52+
"psr1_naming": false,
53+
"psr2": true,
54+
"smart_linebreak_after_curly": true,
55+
"version": 4,
56+
"yoda": false
57+
}

0 commit comments

Comments
 (0)