Skip to content
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
2 changes: 1 addition & 1 deletion src/Asset/FrontendAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace HeimrichHannot\EncoreBundle\Asset;

class FrontendAsset
class FrontendAsset implements FrontendAssetInterface
{
/**
* @var array
Expand Down
25 changes: 25 additions & 0 deletions src/Asset/FrontendAssetInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace HeimrichHannot\EncoreBundle\Asset;

interface FrontendAssetInterface
{
/**
* Add an active entrypoint.
*/
public function addActiveEntrypoint(string $entrypoint);

/**
* Return a list of all active entrypoints.
*
* @return array
*/
public function getActiveEntrypoints();

/**
* Check if an entrypoint is set as active entrypoint.
*
* @return bool
*/
public function isActiveEntrypoint(string $entrypoint);
}
2 changes: 1 addition & 1 deletion src/Asset/GlobalContaoAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use HeimrichHannot\EncoreBundle\Collection\ExtensionCollection;
use HeimrichHannot\EncoreContracts\EncoreEntry;

class GlobalContaoAsset
class GlobalContaoAsset implements GlobalContaoAssetInterface
{
private array $bundleConfig;
private ExtensionCollection $extensionCollection;
Expand Down
18 changes: 18 additions & 0 deletions src/Asset/GlobalContaoAssetInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace HeimrichHannot\EncoreBundle\Asset;

interface GlobalContaoAssetInterface
{
public function cleanGlobalArrayFromConfiguration(): void;

public function cleanFromGlobalArray(string $key, array $entries): void;

public function cleanJsAssets(array $entries): void;

public function cleanJqueryAssets(array $entries): void;

public function cleanCssAssets(array $entries): void;

public function removeJqueryAsset(): void;
}
12 changes: 6 additions & 6 deletions src/Asset/PageEntrypoints.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use HeimrichHannot\UtilsBundle\Model\ModelUtil;
use Symfony\Component\DependencyInjection\ContainerInterface;

class PageEntrypoints
class PageEntrypoints implements PageEntrypointsInterface
{
protected $jsEntries = [];
protected $cssEntries = [];
Expand All @@ -26,15 +26,15 @@ class PageEntrypoints

protected $initialized = false;

private ContainerInterface $container;
private FrontendAsset $frontendAsset;
private EntryCollection $entryCollection;
private ModelUtil $modelUtil;
private ContainerInterface $container;
private FrontendAssetInterface $frontendAsset;
private EntryCollection $entryCollection;
private ModelUtil $modelUtil;

/**
* PageEntrypoints constructor.
*/
public function __construct(ContainerInterface $container, FrontendAsset $frontendAsset, EntryCollection $entryCollection, ModelUtil $modelUtil)
public function __construct(ContainerInterface $container, FrontendAssetInterface $frontendAsset, EntryCollection $entryCollection, ModelUtil $modelUtil)
{
$this->container = $container;
$this->frontendAsset = $frontendAsset;
Expand Down
48 changes: 48 additions & 0 deletions src/Asset/PageEntrypointsInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

namespace HeimrichHannot\EncoreBundle\Asset;

use Contao\LayoutModel;
use Contao\PageModel;
use Exception;

interface PageEntrypointsInterface
{
public function generatePageEntrypoints(PageModel $page, LayoutModel $layout, ?string $encoreField = null): bool;

/**
* Collect all entries for the current page.
*
* @return array
*/
public function collectPageEntries(LayoutModel $layout, PageModel $currentPage, ?string $encoreField = null);

/**
* @throws Exception
*/
public function getJsEntries(): array;

/**
* @throws Exception
*/
public function getCssEntries(): array;

/**
* @throws Exception
*/
public function getJsHeadEntries(): array;

/**
* Return all active entrypoints.
*
* @throws Exception
*/
public function getActiveEntries(): array;

/**
* Return a fresh instance of PageEntryPoint.
*
* @return \HeimrichHannot\EncoreBundle\Asset\PageEntrypoints
*/
public function createInstance();
}
6 changes: 3 additions & 3 deletions src/Asset/TemplateAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Twig\Environment;
use Twig\Error\RuntimeError;

class TemplateAsset
class TemplateAsset implements TemplateAssetInterface
{
/**
* @var Environment
Expand All @@ -25,7 +25,7 @@ class TemplateAsset
*/
private $layout;
/**
* @var PageEntrypoints
* @var PageEntrypointsInterface
*/
private $pageEntrypoints;
/**
Expand Down Expand Up @@ -53,7 +53,7 @@ class TemplateAsset
*/
private $webDir;

public function __construct(array $bundleConfig, string $webDir, Environment $twig, PageEntrypoints $pageEntrypoints)
public function __construct(array $bundleConfig, string $webDir, Environment $twig, PageEntrypointsInterface $pageEntrypoints)
{
$this->twig = $twig;
$this->pageEntrypoints = $pageEntrypoints;
Expand Down
45 changes: 45 additions & 0 deletions src/Asset/TemplateAssetInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace HeimrichHannot\EncoreBundle\Asset;

use Contao\LayoutModel;
use Contao\PageModel;

interface TemplateAssetInterface
{
public function createInstance(PageModel $pageModel, LayoutModel $layoutModel, ?string $entriesField = null): \HeimrichHannot\EncoreBundle\Asset\TemplateAsset;

public function initialize(PageModel $pageModel, LayoutModel $layoutModel, ?string $entriesField = null);

/**
* Return the javascript that should be included in the header region.
*
* @throws \Exception
*/
public function headScriptTags(): string;

/**
* Return the javascript tags that should be included in the footer region.
*
* @throws \Exception
*/
public function scriptTags(): string;

/**
* Return the css link tags that should be included in the header region.
*
* @return string
* @throws \Exception
*
*/
public function linkTags();

/**
* Return a link tag with inline css.
*
* @return bool|string
* @throws \Exception
*
*/
public function inlineCssLinkTag();
}
10 changes: 5 additions & 5 deletions src/EventListener/Contao/ReplaceDynamicScriptTagsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\LayoutModel;
use Contao\PageModel;
use HeimrichHannot\EncoreBundle\Asset\GlobalContaoAsset;
use HeimrichHannot\EncoreBundle\Asset\TemplateAsset;
use HeimrichHannot\EncoreBundle\Asset\GlobalContaoAssetInterface;
use HeimrichHannot\EncoreBundle\Asset\TemplateAssetInterface;
use HeimrichHannot\EncoreBundle\Helper\ConfigurationHelper;
use HeimrichHannot\EncoreBundle\Helper\EntryHelper;
use HeimrichHannot\UtilsBundle\Util\Utils;
Expand All @@ -28,21 +28,21 @@ class ReplaceDynamicScriptTagsListener
*/
protected $bundleConfig;
/**
* @var TemplateAsset
* @var TemplateAssetInterface
*/
protected $templateAsset;
/**
* @var ConfigurationHelper
*/
protected $configurationHelper;
private GlobalContaoAsset $globalContaoAsset;
private GlobalContaoAssetInterface $globalContaoAsset;
private ContaoFramework $contaoFramework;
private Utils $utils;

/**
* ReplaceDynamicScriptTagsListener constructor.
*/
public function __construct(array $bundleConfig, ContaoFramework $contaoFramework, Utils $utils, TemplateAsset $templateAsset, ConfigurationHelper $configurationHelper, GlobalContaoAsset $globalContaoAsset)
public function __construct(array $bundleConfig, ContaoFramework $contaoFramework, Utils $utils, TemplateAssetInterface $templateAsset, ConfigurationHelper $configurationHelper, GlobalContaoAssetInterface $globalContaoAsset)
{
$this->bundleConfig = $bundleConfig;
$this->templateAsset = $templateAsset;
Expand Down