-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from puleeno/ft/init-asset-manager
Ft/init asset manager
- Loading branch information
Showing
49 changed files
with
1,480 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
<?php | ||
|
||
namespace App\Constracts; | ||
|
||
final class AssetTypeEnum | ||
{ | ||
private static $inited = false; | ||
|
||
protected static AssetTypeEnum $CSS; | ||
protected static AssetTypeEnum $JS; | ||
protected static AssetTypeEnum $ICON; | ||
protected static AssetTypeEnum $FONT; | ||
protected static AssetTypeEnum $STYLE; | ||
protected static AssetTypeEnum $INIT_SCRIPT; | ||
protected static AssetTypeEnum $EXECUTE_SCRIPT; | ||
|
||
protected $type; | ||
|
||
protected function __construct($type) | ||
{ | ||
$this->type = $type; | ||
} | ||
|
||
public static function init() | ||
{ | ||
if (static::$inited === false) { | ||
self::$CSS = new self('css'); | ||
self::$JS = new self('js'); | ||
self::$ICON = new self('icon'); | ||
self::$FONT = new self('font'); | ||
self::$STYLE = new self('style'); | ||
|
||
// phpcs:ignoreFile | ||
self::$INIT_SCRIPT = new self('init_script'); | ||
// phpcs:ignoreFile | ||
self::$EXECUTE_SCRIPT = new self('execute_script'); | ||
|
||
// Make inited flag is true | ||
static::$inited = true; | ||
} | ||
} | ||
|
||
public static function CSS(): AssetTypeEnum | ||
{ | ||
return static::$CSS; | ||
} | ||
|
||
public static function JS(): AssetTypeEnum | ||
{ | ||
return static::$JS; | ||
} | ||
|
||
public static function ICON(): AssetTypeEnum | ||
{ | ||
return static::$ICON; | ||
} | ||
|
||
public static function FONT(): AssetTypeEnum | ||
{ | ||
return static::$FONT; | ||
} | ||
|
||
public static function STYLE(): AssetTypeEnum | ||
{ | ||
return static::$STYLE; | ||
} | ||
|
||
public static function INIT_SCRIPT(): AssetTypeEnum | ||
{ | ||
return static::$INIT_SCRIPT; | ||
} | ||
|
||
public static function EXECUTE_SCRIPT(): AssetTypeEnum | ||
{ | ||
return static::$EXECUTE_SCRIPT; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getType() | ||
{ | ||
return $this->type; | ||
} | ||
|
||
public function __toString() | ||
{ | ||
return $this->getType(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace App\Constracts\Assets; | ||
|
||
use App\Constracts\AssetTypeEnum; | ||
use App\Core\Assets\AssetOptions; | ||
|
||
interface AssetConstract | ||
{ | ||
public function setDeps($deps): AssetConstract; | ||
|
||
public function setOptions(AssetOptions $options): AssetConstract; | ||
|
||
public function setVersion($version): AssetConstract; | ||
|
||
public function setPriority(int $priority): AssetConstract; | ||
|
||
public function setAssetType(AssetTypeEnum $assetType): AssetConstract; | ||
|
||
public function isValid(): bool; | ||
|
||
public function getId(); | ||
|
||
public function getAssetType(): AssetTypeEnum; | ||
|
||
public function isEnqueue(): bool; | ||
|
||
public function enqueue(); | ||
|
||
public function printHtml(); | ||
|
||
public function getOptions(): ?AssetOptionsConstract; | ||
|
||
public function getOption($name, $defaultValue = null, $classObject = null); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace App\Constracts\Assets; | ||
|
||
use App\Core\Assets\AssetUrl; | ||
|
||
interface AssetExternalConstract extends AssetConstract | ||
{ | ||
public function setUrl(AssetUrl $url): self; | ||
|
||
public function getUrl(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace App\Constracts\Assets; | ||
|
||
interface AssetHtmlConstract | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace App\Constracts\Assets; | ||
|
||
interface AssetIconConstract | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace App\Constracts\Assets; | ||
|
||
interface AssetOptionsConstract | ||
{ | ||
public static function parseOptionFromArray($options): AssetOptionsConstract; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
namespace App\Constracts\Assets; | ||
|
||
interface AssetScriptConstract | ||
{ | ||
public function isFooterScript(): bool; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace App\Constracts; | ||
|
||
interface IconTypeConstract | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
namespace App\Constracts; | ||
|
||
use Psr\Http\Server\MiddlewareInterface; | ||
|
||
interface MiddlewareConstract extends MiddlewareInterface | ||
{ | ||
public function getPriority(): int; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
<?php | ||
|
||
namespace App\Core; | ||
|
||
use App\Constracts\Assets\AssetConstract; | ||
use App\Constracts\Assets\AssetOptionsConstract; | ||
use App\Constracts\AssetTypeEnum; | ||
use App\Traits\AssetBaseTrait; | ||
|
||
abstract class Asset implements AssetConstract | ||
{ | ||
use AssetBaseTrait; | ||
|
||
protected $id; | ||
|
||
protected AssetTypeEnum $assetType; | ||
protected AssetOptionsConstract $options; | ||
|
||
protected $deps = []; | ||
protected $version = null; | ||
protected $priority = 10; | ||
protected $isEnqueue = false; | ||
protected $isRendered = false; | ||
|
||
public function __construct($id) | ||
{ | ||
$this->id = $id; | ||
} | ||
|
||
public function isValid(): bool | ||
{ | ||
return !empty($this->id); | ||
} | ||
|
||
public function setAssetType(AssetTypeEnum $assetType): AssetConstract | ||
{ | ||
$this->assetType = $assetType; | ||
|
||
return $this; | ||
} | ||
|
||
public function getAssetType(): AssetTypeEnum | ||
{ | ||
return $this->assetType; | ||
} | ||
|
||
public function setDeps($deps): AssetConstract | ||
{ | ||
if (is_array($deps)) { | ||
$this->deps = $deps; | ||
} | ||
return $this; | ||
} | ||
|
||
public function setOptions(AssetOptionsConstract $assetOptions): AssetConstract | ||
{ | ||
$this->options = $assetOptions; | ||
|
||
return $this; | ||
} | ||
|
||
public function setPriority(int $priority): AssetConstract | ||
{ | ||
$this->priority = $priority; | ||
|
||
return $this; | ||
} | ||
|
||
public function setVersion($version): AssetConstract | ||
{ | ||
$this->version = $version; | ||
|
||
return $this; | ||
} | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function enqueue(): self | ||
{ | ||
$this->isEnqueue = true; | ||
|
||
return $this; | ||
} | ||
|
||
public function isEnqueue(): bool | ||
{ | ||
return $this->isEnqueue; | ||
} | ||
} |
Oops, something went wrong.