Skip to content

Commit

Permalink
[TASK] Minor cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminkott committed May 19, 2023
1 parent 8225019 commit 499463e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 34 deletions.
28 changes: 2 additions & 26 deletions Classes/Service/CacheService.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,13 @@
use T3G\AgencyPack\Blog\Domain\Model\Post;
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;

/**
* Class CacheService
*/
class CacheService
{
/**
* @param Post $post
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException
* @throws \TYPO3\CMS\Core\Context\Exception\AspectNotFoundException
*/
public function addTagsForPost(Post $post): void
{
$this->addTagToPage('tx_blog_post_' . $post->getUid());
Expand All @@ -42,48 +37,29 @@ public function addTagsForPost(Post $post): void
}
}

/**
* @param string $tag
*/
public function addTagToPage(string $tag): void
{
$this->addTagsToPage([$tag]);
}

/**
* @param array $tags
*/
public function addTagsToPage(array $tags): void
{
$this->getTypoScriptFrontendController()->addCacheTags($tags);
}

/**
* @param string $tag
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
public function flushCacheByTag(string $tag): void
{
$this->flushCacheByTags([$tag]);
}

/**
* @param array $tags
* @throws \InvalidArgumentException
* @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException
*/
public function flushCacheByTags(array $tags): void
{
GeneralUtility::makeInstance(CacheManager::class)
->getCache('pages')
->flushByTags($tags);
}

/**
* @return mixed|\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
*/
protected function getTypoScriptFrontendController()
protected function getTypoScriptFrontendController(): TypoScriptFrontendController
{
return $GLOBALS['TSFE'];
}
Expand Down
6 changes: 2 additions & 4 deletions Classes/ViewHelpers/Link/ArchiveViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;

class ArchiveViewHelper extends AbstractTagBasedViewHelper
Expand Down Expand Up @@ -67,10 +68,7 @@ public function render(): string
return (string)$result;
}

/**
* @return mixed|\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
*/
protected function getTypoScriptFrontendController()
protected function getTypoScriptFrontendController(): TypoScriptFrontendController
{
return $GLOBALS['TSFE'];
}
Expand Down
6 changes: 2 additions & 4 deletions Classes/ViewHelpers/Link/TagViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use T3G\AgencyPack\Blog\Domain\Model\Tag;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\Mvc\Web\Routing\UriBuilder;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;

class TagViewHelper extends AbstractTagBasedViewHelper
Expand Down Expand Up @@ -64,10 +65,7 @@ public function render(): string
return (string)$result;
}

/**
* @return mixed|\TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController
*/
protected function getTypoScriptFrontendController()
protected function getTypoScriptFrontendController(): TypoScriptFrontendController
{
return $GLOBALS['TSFE'];
}
Expand Down

0 comments on commit 499463e

Please sign in to comment.