@@ -50,7 +50,7 @@ public static function isRelative(string $url): bool
5050 }
5151
5252 /**
53- * @param $str
53+ * @param string $str
5454 *
5555 * @return bool
5656 */
@@ -62,7 +62,33 @@ public static function isUrl(string $str): bool
6262 }
6363
6464 /**
65- * @param $url
65+ * @param string $str
66+ *
67+ * @return bool
68+ */
69+ public static function isGitUrl (string $ str ): bool
70+ {
71+ if (strpos ($ str , 'git@ ' ) === 0 ) {
72+ $ str = 'ssh:// ' . $ str ;
73+ }
74+
75+ $ rule = '/^(http|https|ssh):\/\/(.+@)*([\w\.]+)(:[\d]+)?\/*(.*)/i ' ;
76+
77+ return preg_match ($ rule , $ str ) === 1 ;
78+ }
79+
80+ /**
81+ * @param string $url
82+ *
83+ * @return bool
84+ */
85+ public static function simpleCheck (string $ url ): bool
86+ {
87+ return preg_match ('/^(\w+://)(.+@)*([\w\.]+)(:[\d]+)?/*(.*)/ ' , $ url ) === 1 ;
88+ }
89+
90+ /**
91+ * @param string $url
6692 *
6793 * @return bool
6894 */
@@ -91,7 +117,7 @@ public static function build(string $baseUrl, $data = null): string
91117 }
92118
93119 /**
94- * @param $url
120+ * @param string $url
95121 *
96122 * @return bool
97123 */
@@ -111,9 +137,8 @@ public static function canAccessed(string $url): bool
111137 return $ statusCode === 200 ;
112138 }
113139 } elseif (function_exists ('get_headers ' )) {
114- $ headers = get_headers ($ url , 1 );
115-
116- return strpos ($ headers [0 ], 200 ) > 0 ;
140+ $ headers = get_headers ($ url , true );
141+ return strpos ($ headers [0 ], '200 ' ) > 0 ;
117142 } else {
118143 $ opts = [
119144 'http ' => ['timeout ' => 5 ,]
@@ -202,11 +227,11 @@ public static function parseUrl(string $url): array
202227 * $url2 = urldecode($url);
203228 * echo $url1.PHP_EOL.$url2.PHP_EOL;
204229 *
205- * @param $url
230+ * @param string $url
206231 *
207- * @return mixed| string
232+ * @return string
208233 */
209- public static function encode (string $ url )
234+ public static function encode (string $ url ): string
210235 {
211236 if (!$ url = trim ($ url )) {
212237 return $ url ;
@@ -216,9 +241,8 @@ public static function encode(string $url)
216241 $ url = urldecode ($ url );
217242
218243 $ encodeUrl = urlencode ($ url );
219- $ encodeUrl = str_replace (self ::$ entities , self ::$ replacements , $ encodeUrl );
220244
221- return $ encodeUrl ;
245+ return str_replace ( self :: $ entities , self :: $ replacements , $ encodeUrl) ;
222246 }
223247
224248 /**
@@ -231,9 +255,9 @@ public static function encode(string $url)
231255 *
232256 * @param string $url
233257 *
234- * @return mixed| string
258+ * @return string
235259 */
236- public static function encode2 (string $ url )
260+ public static function encode2 (string $ url ): string
237261 {
238262 if (!$ url = trim ($ url )) {
239263 return $ url ;
@@ -244,8 +268,6 @@ public static function encode2(string $url)
244268
245269 $ encodeUrl = rawurlencode (mb_convert_encoding ($ url , 'utf-8 ' ));
246270 // $url = rawurlencode($url);
247- $ encodeUrl = str_replace (self ::$ entities , self ::$ replacements , $ encodeUrl );
248-
249- return $ encodeUrl ;
271+ return str_replace (self ::$ entities , self ::$ replacements , $ encodeUrl );
250272 }
251273}
0 commit comments