Skip to content

Commit

Permalink
Removed domain parser
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Apr 5, 2024
1 parent 04aec2e commit d8e20d2
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 30 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/code-analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ on:
pull_request: null
push:
branches:
- develop
- v3
- 3.x
workflow_dispatch:
permissions:
contents: read
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<p align="center"><img width="150" src="https://raw.githubusercontent.com/putyourlightson/craft-cloudflare/v2/src/icon.svg"></p>
<p align="center"><img width="150" src="https://raw.githubusercontent.com/putyourlightson/craft-cloudflare/3.x/src/icon.svg"></p>

# Cloudflare Plugin for Craft CMS

Expand All @@ -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
```

Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
22 changes: 1 addition & 21 deletions src/helpers/UrlHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
namespace putyourlightson\cloudflare\helpers;

use Craft;
use Pdp;
use putyourlightson\cloudflare\Cloudflare;

class UrlHelper
Expand Down Expand Up @@ -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;
}
Expand All @@ -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();
}
}

0 comments on commit d8e20d2

Please sign in to comment.