From 51753e403fa69c0ce124ede27d300477e3e799ca Mon Sep 17 00:00:00 2001 From: VirtualTam Date: Mon, 3 Dec 2018 00:34:53 +0100 Subject: [PATCH] namespacing: move HTTP utilities along \Shaarli\Http\ classes Signed-off-by: VirtualTam --- application/{ => http}/HttpUtils.php | 2 +- application/http/Url.php | 2 +- application/{Url.php => http/UrlUtils.php} | 4 ++-- index.php | 4 ++-- tests/{ => http}/HttpUtils/ClientIpIdTest.php | 6 ++++-- tests/{ => http}/HttpUtils/GetHttpUrlTest.php | 10 ++++++---- .../{ => http}/HttpUtils/GetIpAdressFromProxyTest.php | 6 ++++-- tests/{ => http}/HttpUtils/IndexUrlTest.php | 6 ++++-- tests/{ => http}/HttpUtils/IsHttpsTest.php | 5 ++++- tests/{ => http}/HttpUtils/PageUrlTest.php | 6 ++++-- tests/{ => http}/HttpUtils/ServerUrlTest.php | 6 ++++-- tests/http/UrlTest.php | 2 +- tests/{Url => http/UrlUtils}/CleanupUrlTest.php | 6 ++++-- tests/{Url => http/UrlUtils}/GetUrlSchemeTest.php | 10 ++++++---- tests/{Url => http/UrlUtils}/UnparseUrlTest.php | 8 +++++--- .../{Url => http/UrlUtils}/WhitelistProtocolsTest.php | 8 ++++---- 16 files changed, 56 insertions(+), 35 deletions(-) rename application/{ => http}/HttpUtils.php (99%) rename application/{Url.php => http/UrlUtils.php} (95%) rename tests/{ => http}/HttpUtils/ClientIpIdTest.php (89%) rename tests/{ => http}/HttpUtils/GetHttpUrlTest.php (85%) rename tests/{ => http}/HttpUtils/GetIpAdressFromProxyTest.php (91%) rename tests/{ => http}/HttpUtils/IndexUrlTest.php (92%) rename tests/{ => http}/HttpUtils/IsHttpsTest.php (89%) rename tests/{ => http}/HttpUtils/PageUrlTest.php (93%) rename tests/{ => http}/HttpUtils/ServerUrlTest.php (97%) rename tests/{Url => http/UrlUtils}/CleanupUrlTest.php (96%) rename tests/{Url => http/UrlUtils}/GetUrlSchemeTest.php (76%) rename tests/{Url => http/UrlUtils}/UnparseUrlTest.php (76%) rename tests/{Url => http/UrlUtils}/WhitelistProtocolsTest.php (91%) diff --git a/application/HttpUtils.php b/application/http/HttpUtils.php similarity index 99% rename from application/HttpUtils.php rename to application/http/HttpUtils.php index 51af5d0d..2ea9195d 100644 --- a/application/HttpUtils.php +++ b/application/http/HttpUtils.php @@ -41,7 +41,7 @@ function get_http_response($url, $timeout = 30, $maxBytes = 4194304, $curlWriteF $cleanUrl = $urlObj->idnToAscii(); if (!filter_var($cleanUrl, FILTER_VALIDATE_URL) || !$urlObj->isHttp()) { - return array(array(0 => 'Invalid HTTP Url'), false); + return array(array(0 => 'Invalid HTTP UrlUtils'), false); } $userAgent = diff --git a/application/http/Url.php b/application/http/Url.php index 260231c6..90444a2f 100644 --- a/application/http/Url.php +++ b/application/http/Url.php @@ -206,7 +206,7 @@ class Url } /** - * Test if the Url is an HTTP one. + * Test if the UrlUtils is an HTTP one. * * @return true is HTTP, false otherwise. */ diff --git a/application/Url.php b/application/http/UrlUtils.php similarity index 95% rename from application/Url.php rename to application/http/UrlUtils.php index 81f72fb0..4bc84b82 100644 --- a/application/Url.php +++ b/application/http/UrlUtils.php @@ -28,7 +28,7 @@ function unparse_url($parsedUrl) /** * Removes undesired query parameters and fragments * - * @param string url Url to be cleaned + * @param string url UrlUtils to be cleaned * * @return string the string representation of this URL after cleanup */ @@ -41,7 +41,7 @@ function cleanup_url($url) /** * Get URL scheme. * - * @param string url Url for which the scheme is requested + * @param string url UrlUtils for which the scheme is requested * * @return mixed the URL scheme or false if none is provided. */ diff --git a/index.php b/index.php index 6d1ae3fc..66fe30f1 100644 --- a/index.php +++ b/index.php @@ -59,16 +59,16 @@ require_once __DIR__ . '/vendor/autoload.php'; require_once 'application/ApplicationUtils.php'; require_once 'application/config/ConfigPlugin.php'; require_once 'application/feed/Cache.php'; +require_once 'application/http/HttpUtils.php'; +require_once 'application/http/UrlUtils.php'; require_once 'application/FileUtils.php'; require_once 'application/History.php'; -require_once 'application/HttpUtils.php'; require_once 'application/LinkDB.php'; require_once 'application/LinkFilter.php'; require_once 'application/LinkUtils.php'; require_once 'application/NetscapeBookmarkUtils.php'; require_once 'application/PageBuilder.php'; require_once 'application/TimeZone.php'; -require_once 'application/Url.php'; require_once 'application/Utils.php'; require_once 'application/PluginManager.php'; require_once 'application/Router.php'; diff --git a/tests/HttpUtils/ClientIpIdTest.php b/tests/http/HttpUtils/ClientIpIdTest.php similarity index 89% rename from tests/HttpUtils/ClientIpIdTest.php rename to tests/http/HttpUtils/ClientIpIdTest.php index c15ac5cc..982e57e0 100644 --- a/tests/HttpUtils/ClientIpIdTest.php +++ b/tests/http/HttpUtils/ClientIpIdTest.php @@ -3,12 +3,14 @@ * HttpUtils' tests */ -require_once 'application/HttpUtils.php'; +namespace Shaarli\Http; + +require_once 'application/http/HttpUtils.php'; /** * Unitary tests for client_ip_id() */ -class ClientIpIdTest extends PHPUnit_Framework_TestCase +class ClientIpIdTest extends \PHPUnit\Framework\TestCase { /** * Get a remote client ID based on its IP diff --git a/tests/HttpUtils/GetHttpUrlTest.php b/tests/http/HttpUtils/GetHttpUrlTest.php similarity index 85% rename from tests/HttpUtils/GetHttpUrlTest.php rename to tests/http/HttpUtils/GetHttpUrlTest.php index ea53de5f..3dc5bc9b 100644 --- a/tests/HttpUtils/GetHttpUrlTest.php +++ b/tests/http/HttpUtils/GetHttpUrlTest.php @@ -3,12 +3,14 @@ * HttpUtils' tests */ -require_once 'application/HttpUtils.php'; +namespace Shaarli\Http; + +require_once 'application/http/HttpUtils.php'; /** * Unitary tests for get_http_response() */ -class GetHttpUrlTest extends PHPUnit_Framework_TestCase +class GetHttpUrlTest extends \PHPUnit\Framework\TestCase { /** * Get an invalid local URL @@ -17,12 +19,12 @@ class GetHttpUrlTest extends PHPUnit_Framework_TestCase { // Local list($headers, $content) = get_http_response('/non/existent', 1); - $this->assertEquals('Invalid HTTP Url', $headers[0]); + $this->assertEquals('Invalid HTTP UrlUtils', $headers[0]); $this->assertFalse($content); // Non HTTP list($headers, $content) = get_http_response('ftp://save.tld/mysave', 1); - $this->assertEquals('Invalid HTTP Url', $headers[0]); + $this->assertEquals('Invalid HTTP UrlUtils', $headers[0]); $this->assertFalse($content); } diff --git a/tests/HttpUtils/GetIpAdressFromProxyTest.php b/tests/http/HttpUtils/GetIpAdressFromProxyTest.php similarity index 91% rename from tests/HttpUtils/GetIpAdressFromProxyTest.php rename to tests/http/HttpUtils/GetIpAdressFromProxyTest.php index 7af5bd9d..fe3a639e 100644 --- a/tests/HttpUtils/GetIpAdressFromProxyTest.php +++ b/tests/http/HttpUtils/GetIpAdressFromProxyTest.php @@ -1,11 +1,13 @@