From 3d94a6d9b74be03b58049dd24ff59145f24b36a1 Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Sat, 9 Oct 2021 19:46:58 +0200 Subject: Splits into two separate Traits for Themes and Plugins --- src/PluginUsesWordPressScripts.php | 35 +++++++++++++++++++++++++++++++++++ src/ThemeUsesWordPressScripts.php | 28 ++++++++++++++++++++++++++++ src/UsesWordPressScripts.php | 20 +++++++------------- 3 files changed, 70 insertions(+), 13 deletions(-) create mode 100644 src/PluginUsesWordPressScripts.php create mode 100644 src/ThemeUsesWordPressScripts.php diff --git a/src/PluginUsesWordPressScripts.php b/src/PluginUsesWordPressScripts.php new file mode 100644 index 0000000..3a60828 --- /dev/null +++ b/src/PluginUsesWordPressScripts.php @@ -0,0 +1,35 @@ +pluginDir) . "{$this->buildDir}/$asset"; + } + + /** + * @param string $asset + * + * @return array + */ + public function assetsMeta(string $asset): array + { + return include plugin_dir_path($this->pluginDir) . "{$this->buildDir}/$asset.asset.php"; + } +} diff --git a/src/ThemeUsesWordPressScripts.php b/src/ThemeUsesWordPressScripts.php new file mode 100644 index 0000000..21cc501 --- /dev/null +++ b/src/ThemeUsesWordPressScripts.php @@ -0,0 +1,28 @@ +buildDir}/$asset"; + } + + /** + * @param string $asset + * + * @return array + */ + public function assetsMeta(string $asset): array + { + return include get_stylesheet_directory() . "/{$this->buildDir}/$asset.asset.php"; + } +} diff --git a/src/UsesWordPressScripts.php b/src/UsesWordPressScripts.php index e93a01e..c565575 100644 --- a/src/UsesWordPressScripts.php +++ b/src/UsesWordPressScripts.php @@ -7,7 +7,7 @@ trait UsesWordPressScripts /** * @var string */ - protected $buildDir = 'build'; + protected string $buildDir = 'build'; /** * @param string $handle @@ -15,7 +15,7 @@ trait UsesWordPressScripts * @param array $deps * @param bool $inFooter */ - public function enqueueScript($handle, $asset, $deps = [], $inFooter = false) + public function enqueueScript(string $handle, string $asset, array $deps = [], bool $inFooter = false) { $assetBaseName = pathinfo($asset, PATHINFO_FILENAME); $meta = $this->assetsMeta($assetBaseName); @@ -35,7 +35,7 @@ trait UsesWordPressScripts * @param array $deps * @param string $media */ - public function enqueueStyle($handle, $asset, $deps = [], $media = 'all') + public function enqueueStyle(string $handle, string $asset, array $deps = [], string $media = 'all') { $assetBaseName = pathinfo($asset, PATHINFO_FILENAME); $meta = $this->assetsMeta($assetBaseName); @@ -52,20 +52,14 @@ trait UsesWordPressScripts /** * @param string $asset * - * @return string + * @return string Url to asset in $buildDir */ - public function assetsUrl($asset) - { - return get_stylesheet_directory_uri() . "/{$this->buildDir}/$asset"; - } + abstract public function assetsUrl(string $asset): string; /** * @param string $asset * - * @return mixed + * @return array Data from $asset.asset.php in $buildDir */ - public function assetsMeta($asset) - { - return include get_stylesheet_directory() . "/{$this->buildDir}/$asset.asset.php"; - } + abstract public function assetsMeta(string $asset): array; } -- cgit v1.2.3