Skip to content

Commit e5845a1

Browse files
authored
Create README.md
1 parent c44d0f0 commit e5845a1

File tree

1 file changed

+207
-0
lines changed

1 file changed

+207
-0
lines changed

README.md

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
phpCompressor
2+
==========
3+
4+
5+
phpCompressor - The main task of compressing PHP code, it is also possible to use as a simple PHP obfuscator.
6+
The compressor compresses the code by removing spaces, line breaks code comment,
7+
abbreviations of names of local variables in functions, abbreviations of names of property classes (variables),
8+
abbreviations of names of class methods.
9+
10+
Reduction settings
11+
=====
12+
* Reduction of local variable names in functions
13+
* Reduction of names of properties of classes (variables)
14+
* Reduction of the names of class methods
15+
* To remove spaces, comments and line breaks
16+
17+
The principle of abbreviating names
18+
=====
19+
Aliases are used to abbreviate names, which are formed depending on the frequency of use of the name.
20+
21+
For example: the name 'data' is used 98 times in the code, 'options' - 70 times, 'values' - 68 times, etc.on fading...
22+
The result will be
23+
24+
* 'data' => 'a'
25+
* 'options' => 'b'
26+
* 'values' => 'c'
27+
* '...' => 'd...aa'
28+
* 'rare_name' => 'ab'
29+
* .....
30+
31+
32+
33+
Installation
34+
=====
35+
36+
To install, use the composer [composer](https://getcomposer.org):
37+
38+
php composer.phar require genasyst/php-compressor
39+
40+
41+
Example of use
42+
=====
43+
44+
```php
45+
<?php
46+
47+
$compressor = new \Genasyst\phpCompressor\Compressor();
48+
49+
$code = 'echo $data;..... ';
50+
/* Setting the code with the opening tag <?php first */
51+
$compressor->setContentByCode('<?php '.$code);
52+
53+
/ * Install code from php file */
54+
$file_path = __DIR__ .'/ExampleTestEcho.php';
55+
$compressor->setContentByFile($file_path);
56+
57+
58+
/**
59+
* SETTINGS
60+
*
61+
* Set reduction of local variables
62+
*/
63+
$compressor->compressLocalVariablesName();
64+
65+
/**
66+
* Set the reduction of class properties
67+
*/
68+
$compressor->compressObjectsVariablesName();
69+
70+
/**
71+
* Setting abbreviations for method names
72+
*/
73+
$compressor->compressObjectsMethodsName();
74+
75+
76+
/**
77+
* WITH THE EXCEPTION OF COMPRESSION NAMES
78+
*
79+
*
80+
* Set the exception of the names of local variables
81+
*
82+
$compressor->setExcludeNames(
83+
\Genasyst\phpCompressor\Compressor::COMPRESS_TYPE_LOCAL_VARIABLES,
84+
['not_compress_local' => 'not_compress_local']
85+
);
86+
87+
/**
88+
* Set the exception of the names of object properties
89+
*/
90+
$compressor->setExcludeNames(
91+
\Genasyst\phpCompressor\Compressor::COMPRESS_TYPE_OBJECT_VARIABLES,
92+
['not_compressed_name' => 'not_compressed_name']
93+
);
94+
95+
/**
96+
* Set the exception of the names of the methods on the object
97+
*/
98+
$compressor->setExcludeNames(
99+
\Genasyst\phpCompressor\Compressor::COMPRESS_TYPE_OBJECT_METHODS,
100+
['thisMethodNameNotCompressed' => 'thisMethodNameNotCompressed']
101+
);
102+
103+
104+
/* Set the code of a piece */
105+
$code = <<<CODE
106+
function test1(\$long_name1, \$not_compress_local = ' ++') {
107+
\$long_name1 = strtolower(\$long_name1);
108+
if(strlen(\$long_name1) > 10) {
109+
return strtoupper(\$long_name1);
110+
}
111+
return ucfirst(\$long_name1).\$not_compress_local;
112+
}
113+
class My {
114+
115+
protected \$long_variable = '';
116+
117+
protected \$super_long_variable = '';
118+
119+
protected \$not_compressed_name = '';
120+
121+
public function __construct(\$long_variable, \$super_long_variable, \$not_compressed_name)
122+
{
123+
\$this->long_variable = \$long_variable;
124+
\$this->super_long_variable = \$super_long_variable;
125+
\$this->not_compressed_name = \$not_compressed_name;
126+
}
127+
128+
public function getSuperLongVariable()
129+
{
130+
return \$this->super_long_variable;
131+
}
132+
133+
public function getLongVariable()
134+
{
135+
return \$this->long_variable;
136+
}
137+
138+
public function thisMethodNameNotCompressed()
139+
{
140+
return \$this->not_compressed_name;
141+
}
142+
}
143+
144+
\$my = new My('lONg','SuperLongUpper','NOT_compressed');
145+
146+
echo test1(\$my->getLongVariable());//Long ++
147+
echo test1(\$my->getSuperLongVariable());//SUPERLONGUPPER ++
148+
echo test1(\$my->thisMethodNameNotCompressed());//NOT_COMPRESSED ++
149+
CODE;
150+
$compressor->parseBlock($code);
151+
152+
153+
/**
154+
* Start compression
155+
*/
156+
$compressor->compress();
157+
158+
159+
/**
160+
* Get back the compressed code
161+
*/
162+
$code = $compressor->getContent();
163+
echo $code;
164+
/**
165+
* RESULT
166+
* function test1($a, $not_compress_local = ' ++')
167+
* {
168+
* $a = strtolower($a);
169+
* if (strlen($a) > 10) {
170+
* return strtoupper($a);
171+
* }
172+
* return ucfirst($a) . $not_compress_local;
173+
* }
174+
* class My
175+
* {
176+
* protected $b = '';
177+
* protected $a = '';
178+
* protected $not_compressed_name = '';
179+
* public function __construct($c, $b, $a)
180+
* {
181+
* $this->b = $c;
182+
* $this->a = $b;
183+
* $this->not_compressed_name = $a;
184+
* }
185+
* function b()
186+
* {
187+
* return $this->a;
188+
* }
189+
* function a()
190+
* {
191+
* return $this->b;
192+
* }
193+
* public function thisMethodNameNotCompressed()
194+
* {
195+
* return $this->not_compressed_name;
196+
* }
197+
* }
198+
* $a = new My('lONg', 'SuperLongUpper', 'NOT_compressed');
199+
* echo test1($a->a()); //Long ++
200+
* echo test1($a->b());//SUPERLONGUPPER ++
201+
* echo test1($a->thisMethodNameNotCompressed());//NOT_COMPRESSED ++
202+
*/
203+
204+
```
205+
206+
207+

0 commit comments

Comments
 (0)