Skip to content

Commit 3ac9d2d

Browse files
author
Flavius12
committed
Update phartools.php
1 parent 90b591c commit 3ac9d2d

1 file changed

Lines changed: 48 additions & 21 deletions

File tree

phartools.php

Lines changed: 48 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
* PharTools (v1.0) by EvolSoft
55
* Developer: EvolSoft (Flavius12)
66
* Website: http://www.evolsoft.tk
7-
* Date: 23/04/2015 08:15 PM (UTC)
7+
* Date: 23/04/2015 02:25 PM (UTC)
88
* Copyright & License: (C) 2015 EvolSoft
99
* Licensed under MIT (https://github.com/EvolSoft/PharTools/blob/master/LICENSE)
1010
*/
11+
12+
error_reporting(E_NOTICE); //Comment this line to enable error reporting
1113

1214
echo "EvolSoft PharTools v1.0\n";
1315
if(version_compare(phpversion(), "5.3.0", "<")){
@@ -32,27 +34,39 @@
3234
$metadata = null;
3335
$compression = null;
3436
for($i = 0; $i < count($params) - 1; $i++){
35-
//Check Compression
36-
if($params[$i] == "-c" && substr($params[$i + 1], 0, 1) != "-"){
37-
if(strtolower($params[$i + 1]) == "gzip" || strtolower($params[$i + 1]) == "gz"){
38-
$compression = Phar::GZ;
39-
}elseif(strtolower($params[$i + 1]) == "bzip2" || strtolower($params[$i + 1]) == "bz2"){
40-
$compression = Phar::BZ2;
37+
if($params[$i] == "-c"){ //Check Compression
38+
if(substr($params[$i + 1], 0, 1) != "-"){
39+
if(strtolower($params[$i + 1]) == "gzip" || strtolower($params[$i + 1]) == "gz"){
40+
$compression = Phar::GZ;
41+
}elseif(strtolower($params[$i + 1]) == "bzip2" || strtolower($params[$i + 1]) == "bz2"){
42+
$compression = Phar::BZ2;
43+
}else{
44+
$compression = null;
45+
}
4146
}else{
42-
$compression = null;
47+
echo "Invalid compression specified!\n";
4348
}
44-
}
45-
//Check Metadata
46-
if($params[$i] == "-m" && substr($params[$i + 1], 0, 1) != "-"){
47-
$metadata = stringToMetadata($params[$i + 1]);
48-
}
49-
//Check Stub
50-
if($params[$i] == "-s" && substr($params[$i + 1], 0, 1) != "-"){
51-
$stub = $params[$i + 1];
52-
}
53-
//Check Regex
54-
if($params[$i] == "-r" && substr($params[$i + 1], 0, 1) != "-"){
55-
$regex = $params[$i + 1];
49+
50+
}elseif($params[$i] == "-m"){ //Check Metadata
51+
if(substr($params[$i + 1], 0, 1) != "-"){
52+
$metadata = stringToMetadata($params[$i + 1]);
53+
}else{
54+
echo "Invalid metadata specified!\n";
55+
}
56+
}elseif($params[$i] == "-s"){ //Check Stub
57+
if(substr($params[$i + 1], 0, 1) != "-"){
58+
$stub = $params[$i + 1];
59+
}else{
60+
echo "Invalid stub specified!\n";
61+
}
62+
}elseif($params[$i] == "-r"){ //Check Regex
63+
if(substr($params[$i + 1], 0, 1) != "-"){
64+
$regex = $params[$i + 1];
65+
}else{
66+
echo "Invalid regular expression specified!\n";
67+
}
68+
}elseif(substr($params[$i], 0, 1) == "-"){ //Check if is a option
69+
echo "\"" . $params[$i] . "\" option not recognized\n";
5670
}
5771
}
5872
if(file_exists($argv[2])){
@@ -93,7 +107,12 @@
93107
if(is_dir($argv[2])){
94108
//Check regex
95109
if($regex != null){
96-
$phar->buildFromDirectory(getcwd() . "/" . $argv[2], $regex);
110+
if(isRegexValid($regex)){
111+
$phar->buildFromDirectory(getcwd() . "/" . $argv[2], $regex);
112+
}else{
113+
echo "\nInvalid regular expression specified!";
114+
$phar->buildFromDirectory(getcwd() . "/" . $argv[2]);
115+
}
97116
}else{
98117
$phar->buildFromDirectory(getcwd() . "/" . $argv[2]);
99118
}
@@ -232,4 +251,12 @@ function stringToMetadata($string){
232251
}
233252
return $data;
234253
}
254+
255+
function isRegexValid($exp){
256+
if(@preg_match($exp, "") === false) {
257+
return false;
258+
}else{
259+
return true;
260+
}
261+
}
235262
?>

0 commit comments

Comments
 (0)