Skip to content
This repository has been archived by the owner on Apr 18, 2024. It is now read-only.

Craft 4 upgrade #73

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

## [2.0.0] - 2023-XX-XX
- Prepare for Craft 4 compatibility
- ...

## [1.9.2] - 2022-03-26
- Fix issues with Supertable / exclude SuperTableBlockElement

Expand Down
15 changes: 13 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@
}
],
"require": {
"craftcms/cms": "^3.2.0",
"craftcms/cms": "^4.1.0",
"guzzlehttp/guzzle": "^6.5.5|^7.2.0"
},
"require-dev": {
"vimeo/psalm": "^4.4"
"vimeo/psalm": "^4.4",
"craftcms/rector": "dev-main",
"craftcms/phpstan": "dev-main"
},
"autoload": {
"psr-4": {
Expand All @@ -45,5 +47,14 @@
"hasCpSettings": false,
"hasCpSection": false,
"changelogUrl": "https://raw.githubusercontent.com/ostark/upper/master/CHANGELOG.md"
},
"minimum-stability": "dev",
"prefer-stable": true,
"config": {
"allow-plugins": {
"yiisoft/yii2-composer": true,
"craftcms/plugin-installer": true,
"composer/package-versions-deprecated": true
}
}
}
10 changes: 10 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
includes:
- vendor/craftcms/phpstan/phpstan.neon

parameters:
level: 0
paths:
- src
treatPhpDocTypesAsCertain: false
ignoreErrors:
- "#Unsafe usage of new static#"
5 changes: 3 additions & 2 deletions src/EventRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public static function registerFrontendEvents()
$request->getIsActionRequest() ||
!$request->getIsGet()
) {
/** @var \ostark\upper\behaviors\CacheControlBehavior|\ostark\upper\behaviors\TagHeaderBehavior|Response $response */
$response = \Craft::$app->getResponse();
$response->addCacheControlDirective('private');
$response->addCacheControlDirective('no-cache');
Expand Down Expand Up @@ -93,7 +94,7 @@ public static function registerFrontendEvents()
// Add the tags to the response header
Event::on(View::class, View::EVENT_AFTER_RENDER_PAGE_TEMPLATE, function (TemplateEvent $event) {

/** @var \yii\web\Response $response */
/** @var \yii\web\Response|\ostark\upper\behaviors\CacheControlBehavior|\ostark\upper\behaviors\TagHeaderBehavior $response */
$response = \Craft::$app->getResponse();
$plugin = Plugin::getInstance();
$tagCollection = $plugin->getTagCollection();
Expand Down Expand Up @@ -121,7 +122,7 @@ public static function registerFrontendEvents()

// Flag truncation
if (count($tags) > count($maxedTags)) {
$headers->set(Plugin::TRUNCATED_HEADER_NAME, count($tags) - count($maxedTags));
$headers->set(Plugin::TRUNCATED_HEADER_NAME, (string) (count($tags) - count($maxedTags)));
}

$response->setSharedMaxAge($maxAge);
Expand Down
10 changes: 4 additions & 6 deletions src/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class Plugin extends BasePlugin
const INFO_HEADER_NAME = 'X-UPPER-CACHE';
const TRUNCATED_HEADER_NAME = 'X-UPPER-CACHE-TRUNCATED';

public $schemaVersion = '1.0.1';
public string $schemaVersion = '1.0.1';


/**
Expand Down Expand Up @@ -108,11 +108,9 @@ public function getTagCollection(): TagCollection
// =========================================================================

/**
* Creates and returns the model used to store the plugin’s settings.
*
* @return \craft\base\Model|null
* Creates and returns the model used to store the plugin’s settings
*/
protected function createSettingsModel()
protected function createSettingsModel(): Settings
{
return new Settings();
}
Expand All @@ -122,7 +120,7 @@ protected function createSettingsModel()
* Is called after the plugin is installed.
* Copies example config to project's config folder
*/
protected function afterInstall()
protected function afterInstall(): void
{
$configSourceFile = __DIR__ . DIRECTORY_SEPARATOR . 'config.example.php';
$configTargetFile = \Craft::$app->getConfig()->configDir . DIRECTORY_SEPARATOR . $this->handle . '.php';
Expand Down
2 changes: 1 addition & 1 deletion src/TwigExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class TwigExtension extends AbstractExtension implements GlobalsInterface
*
* @return array An array of global variables
*/
public function getGlobals()
public function getGlobals(): array
{
return [
'upper' => [
Expand Down
17 changes: 17 additions & 0 deletions src/drivers/AbstractPurger.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ public function purgeUrlsByTag(string $tag)
return false;
}


/**
* @param array $urls
*
* @return bool
*/
public function purgeUrls(array $urls)
{
$joinedUrls = implode(',', $urls);
\Craft::warning("Method purgeUrls([$joinedUrls]') was called - not implemented by driver ", "upper");

return true;
}

/**
* Get cached urls by given tag
*
Expand Down Expand Up @@ -113,4 +127,7 @@ public function clearLocalCache()

}




}
2 changes: 1 addition & 1 deletion src/drivers/Cloudflare.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public function purgeAll()
* @return bool
* @throws \ostark\upper\exceptions\CloudflareApiException
*/
protected function sendRequest($method = 'DELETE', string $type, array $params = [])
protected function sendRequest($method = 'DELETE', string $type = 'purge_cache', array $params = [])
{
$client = $this->getClient();

Expand Down
2 changes: 1 addition & 1 deletion src/drivers/Fastly.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function purgeAll()
* @return bool
* @throws \ostark\upper\exceptions\FastlyApiException
*/
protected function sendRequest(string $method = 'PURGE', string $uri, array $headers = [])
protected function sendRequest(string $method = 'PURGE', string $uri = '', array $headers = [])
{
$client = new Client([
'base_uri' => self::API_ENDPOINT,
Expand Down
2 changes: 1 addition & 1 deletion src/drivers/Keycdn.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function purgeAll()
* @return bool
* @throws \ostark\upper\exceptions\KeycdnApiException
*/
protected function sendRequest($method = 'DELETE', string $type, array $params = [])
protected function sendRequest($method = 'DELETE', string $type = 'purgetag', array $params = [])
{
$token = base64_encode("{$this->apiKey}:");
$client = new Client([
Expand Down
4 changes: 2 additions & 2 deletions src/jobs/PurgeCacheJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class PurgeCacheJob extends BaseJob
/**
* @inheritdoc
*/
public function execute($queue)
public function execute($queue): void
{
if (!$this->tag) {
return false;
return;
}

// Get registered purger
Expand Down
2 changes: 1 addition & 1 deletion src/models/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class Settings extends Model
*
* @return array
*/
public function rules()
public function rules(): array
{
return [
[['driver', 'drivers','keyPrefix'], 'required'],
Expand Down