From d8e20d2eaae3b0861f0f5d27d7bad70789735161 Mon Sep 17 00:00:00 2001 From: Ben Croker Date: Fri, 5 Apr 2024 13:23:58 -0600 Subject: [PATCH] Removed domain parser --- .github/workflows/code-analysis.yaml | 3 +-- CHANGELOG.md | 6 +++++- README.md | 6 +++--- composer.json | 5 ++--- src/helpers/UrlHelper.php | 22 +--------------------- 5 files changed, 12 insertions(+), 30 deletions(-) diff --git a/.github/workflows/code-analysis.yaml b/.github/workflows/code-analysis.yaml index 043d81d..2645412 100644 --- a/.github/workflows/code-analysis.yaml +++ b/.github/workflows/code-analysis.yaml @@ -4,8 +4,7 @@ on: pull_request: null push: branches: - - develop - - v3 + - 3.x workflow_dispatch: permissions: contents: read diff --git a/CHANGELOG.md b/CHANGELOG.md index 6c803bf..a7f0db8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,11 @@ # Release Notes for Cloudflare -## 3.0.0-beta.1 - 2024-02-20 +## 3.0.0-beta.1 - 2024-04-05 ### Added - Added compatibility with Craft 5.0.0. + +### Removed + +- Removed the domain parser. diff --git a/README.md b/README.md index 0c0426b..414dd3a 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Total Downloads](https://img.shields.io/packagist/dt/workingconcept/craft-cloudflare)](https://packagist.org/packages/workingconcept/craft-cloudflare) [![Total Downloads](https://img.shields.io/packagist/dt/putyourlightson/craft-cloudflare)](https://packagist.org/packages/putyourlightson/craft-cloudflare) -

+

# Cloudflare Plugin for Craft CMS @@ -18,13 +18,13 @@ This plugin is licensed for free under the MIT License. ## Requirements -This plugin requires [Craft CMS](https://craftcms.com/) 3.6.0 or later, or 4.0.0 or later. +This plugin requires [Craft CMS](https://craftcms.com/) 3.6.0 or later, or 4.0.0 or later, or 5.0.0 or later. ## Installation To install the plugin, search for “Cloudflare” in the Craft Plugin Store, or install manually using composer. -``` +```shell composer require putyourlightson/craft-cloudflare ``` diff --git a/composer.json b/composer.json index 7491c1f..121e8f9 100644 --- a/composer.json +++ b/composer.json @@ -6,8 +6,7 @@ "license": "mit", "require": { "php": "^8.2", - "craftcms/cms": "^5.0.0-beta.1", - "jeremykendall/php-domain-parser": "^6.0" + "craftcms/cms": "^5.0.0" }, "require-dev": { "craftcms/ecs": "dev-main", @@ -46,7 +45,7 @@ "developer": "PutYourLightsOn", "developerUrl": "https://putyourlightson.com/", "documentationUrl": "https://putyourlightson.com/plugins/cloudflare", - "changelogUrl": "https://raw.githubusercontent.com/putyourlightson/craft-cloudflare/v3/CHANGELOG.md", + "changelogUrl": "https://raw.githubusercontent.com/putyourlightson/craft-cloudflare/3.x/CHANGELOG.md", "class": "putyourlightson\\cloudflare\\Cloudflare" } } diff --git a/src/helpers/UrlHelper.php b/src/helpers/UrlHelper.php index cf46169..b1c67e6 100755 --- a/src/helpers/UrlHelper.php +++ b/src/helpers/UrlHelper.php @@ -7,7 +7,6 @@ namespace putyourlightson\cloudflare\helpers; use Craft; -use Pdp; use putyourlightson\cloudflare\Cloudflare; class UrlHelper @@ -68,7 +67,7 @@ public static function isPurgeableUrl(string $url, bool $includeZoneCheck): bool * uses it since it otherwise won't be cleared. */ if ($includeZoneCheck) { - if (!$urlDomain = self::getBaseDomainFromUrl($url)) { + if (!$urlDomain = parse_url($url, PHP_URL_HOST)) { // bail if we couldn't even get a base domain return false; } @@ -85,23 +84,4 @@ public static function isPurgeableUrl(string $url, bool $includeZoneCheck): bool return true; } - - /** - * Gets the domain name and TLD only (no subdomains or query parameters) - * from the given URL. - * - * @param string $url - * @return string|null `null` if the URL’s host can’t be parsed - */ - public static function getBaseDomainFromUrl(string $url): ?string - { - $cachePath = Craft::$app->getPath()->getTempPath() . DIRECTORY_SEPARATOR . 'pdp'; - - $host = parse_url($url, PHP_URL_HOST); - $manager = new Pdp\Manager(new Pdp\Cache($cachePath), new Pdp\CurlHttpClient()); - $manager->refreshRules(); - $rules = $manager->getRules(); - - return $rules->resolve($host)->getRegistrableDomain(); - } }