Skip to content

Commit

Permalink
Migrate AssetEngine + Event namespaces to PHP 8
Browse files Browse the repository at this point in the history
  • Loading branch information
allejo committed Dec 29, 2023
1 parent d2c1b4f commit 5e2c86b
Show file tree
Hide file tree
Showing 40 changed files with 228 additions and 305 deletions.
3 changes: 2 additions & 1 deletion bin/stakx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ require __DIR__ . '/../vendor/autoload.php';

use allejo\stakx\Console\Application;

$application = new Application('stakx', '@package_version@');

try
{
$application = new Application('stakx', '@package_version@');
$application->run();
}
catch (\Exception $e)
Expand Down
40 changes: 11 additions & 29 deletions src/AssetEngine/AssetEngineInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,33 @@
*/
interface AssetEngineInterface
{
const CONTAINER_TAG = 'stakx.asset_engine';
public const CONTAINER_TAG = 'stakx.asset_engine';

/**
* A unique-ish name used to identify this asset engine.
*
* This name will be used as an identity throughout stakx's internals and
* for naming related cache folders.
*
* @return string
*/
public function getName();
public function getName(): string;

/**
* The section name in a site's `_config.yml` where this engine can be
* configured.
*
* @return string
*/
public function getConfigurationNamespace();
public function getConfigurationNamespace(): string;

/**
* The default configuration for this engine.
*
* @return array
*/
public function getDefaultConfiguration();
public function getDefaultConfiguration(): array;

/**
* The dedicated folder this asset engine will work in.
*
* @since 0.2.0
*
* @return string
*/
public function getFolder();
public function getFolder(): string;

/**
* The extension this asset engine will be dedicated to.
Expand All @@ -60,17 +52,15 @@ public function getFolder();
*
* @return string[]
*/
public function getExtensions();
public function getExtensions(): array;

/**
* @param string $content
* @param array $options
*
* @since 0.2.0
*
* @return string
*/
public function parse($content, array $options = []);
public function parse(string $content, array $options = []): string;

/**
* Set custom options used internally by this AssetEngine.
Expand All @@ -81,10 +71,8 @@ public function parse($content, array $options = []);
* @param array $options
*
* @since 0.2.0
*
* @return void
*/
public function setOptions(array $options);
public function setOptions(array $options): void;

/**
* Set the PageManager for this AssetEngine so it can be available if it's
Expand All @@ -93,10 +81,8 @@ public function setOptions(array $options);
* @param PageManager $pageManager
*
* @since 0.2.0
*
* @return void
*/
public function setPageManager(PageManager $pageManager);
public function setPageManager(PageManager $pageManager): void;

/**
* Perform loading cache operations before this engine's parsing functionality
Expand All @@ -110,10 +96,8 @@ public function setPageManager(PageManager $pageManager);
* @param WritableFolder $cacheDir
*
* @since 0.2.0
*
* @return void
*/
public function loadCache(WritableFolder $cacheDir);
public function loadCache(WritableFolder $cacheDir): void;

/**
* Perform any saving of caches after the parsing functionality has been
Expand All @@ -125,8 +109,6 @@ public function loadCache(WritableFolder $cacheDir);
* @param WritableFolder $cacheDir
*
* @since 0.2.0
*
* @return void
*/
public function saveCache(WritableFolder $cacheDir);
public function saveCache(WritableFolder $cacheDir): void;
}
27 changes: 19 additions & 8 deletions src/AssetEngine/AssetEngineManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,24 @@

class AssetEngineManager
{
private $enginesByExtension = [];
private $foldersToWatch = [];
private $engines;
/** @var array<string, AssetEngineInterface> Extensions are stored as keys and engines as corresponding values */
private array $enginesByExtension = [];

public function addAssetEngines(/* iterable */ $assetEngines)
/** @var array<string, AssetEngineInterface> Folder paths are stored as keys and engines as corresponding values */
private array $foldersToWatch = [];

/** @var AssetEngineInterface[] All registered engines */
private array $engines;

public function addAssetEngines(iterable $assetEngines): void
{
foreach ($assetEngines as $assetEngine)
{
$this->addAssetEngine($assetEngine);
}
}

public function addAssetEngine(AssetEngineInterface $assetEngine)
public function addAssetEngine(AssetEngineInterface $assetEngine): void
{
$extensions = $assetEngine->getExtensions();

Expand All @@ -37,7 +42,10 @@ public function addAssetEngine(AssetEngineInterface $assetEngine)
$this->foldersToWatch[$assetEngine->getFolder()] = $e;
}

public function getEngines()
/**
* @return AssetEngineInterface[]
*/
public function getEngines(): array
{
return $this->engines;
}
Expand All @@ -49,10 +57,13 @@ public function getEngineByExtension($extension)
return $this->enginesByExtension[$extension];
}

throw new UnsupportedAssetEngineException($extension, "There is no support to handle the '${extension}' asset type.");
throw new UnsupportedAssetEngineException($extension, "There is no support to handle the '{$extension}' asset type.");
}

public function getFoldersToWatch()
/**
* @return AssetEngineInterface[]
*/
public function getFoldersToWatch(): array
{
return $this->foldersToWatch;
}
Expand Down
Loading

0 comments on commit 5e2c86b

Please sign in to comment.