-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
582 additions
and
6 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,18 @@ | ||
<?php | ||
|
||
/** | ||
* @package Tagged | ||
* @license http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DecodeLabs\Tagged; | ||
|
||
use DecodeLabs\Collections\AttributeContainer; | ||
|
||
interface Asset extends AttributeContainer | ||
{ | ||
public function getPriority(): int; | ||
public function render(): Element; | ||
} |
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,69 @@ | ||
<?php | ||
|
||
/** | ||
* @package Tagged | ||
* @license http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DecodeLabs\Tagged\Asset; | ||
|
||
use DecodeLabs\Coercion; | ||
use DecodeLabs\Tagged\AssetTrait; | ||
use DecodeLabs\Tagged\Element; | ||
|
||
class RemoteScript implements Script | ||
{ | ||
use AssetTrait; | ||
|
||
protected string $source; | ||
|
||
/** | ||
* Init with script | ||
* | ||
* @param array<string, mixed> $attributes | ||
*/ | ||
public function __construct( | ||
int $priority, | ||
string $source, | ||
array $attributes = [] | ||
) { | ||
$this->priority = $priority; | ||
$this->source = $source; | ||
|
||
if (!isset($attributes['type'])) { | ||
$attributes['type'] = 'text/javascript'; | ||
} | ||
|
||
$this->setAttributes($attributes); | ||
} | ||
|
||
/** | ||
* Set type | ||
*/ | ||
public function setType( | ||
string $type | ||
): void { | ||
$this->setAttribute('type', $type); | ||
} | ||
|
||
/** | ||
* Get type | ||
*/ | ||
public function getType(): string | ||
{ | ||
return Coercion::toString( | ||
$this->getAttribute('type') ?? 'text/javascript' | ||
); | ||
} | ||
|
||
/** | ||
* Render | ||
*/ | ||
public function render(): Element | ||
{ | ||
unset($this->attributes['src']); | ||
return new Element('script', $this->source, $this->attributes); | ||
} | ||
} |
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,105 @@ | ||
<?php | ||
|
||
/** | ||
* @package Tagged | ||
* @license http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DecodeLabs\Tagged\Asset; | ||
|
||
use DecodeLabs\Coercion; | ||
use DecodeLabs\Tagged\Asset; | ||
use DecodeLabs\Tagged\AssetTrait; | ||
use DecodeLabs\Tagged\Element; | ||
|
||
class Link implements Asset | ||
{ | ||
use AssetTrait; | ||
|
||
/** | ||
* Init with URL | ||
* | ||
* @param array<string, mixed> $attributes | ||
*/ | ||
public function __construct( | ||
int $priority, | ||
string $href, | ||
array $attributes = [] | ||
) { | ||
$this->priority = $priority; | ||
$attributes['href'] = $href; | ||
|
||
if (!isset($attributes['rel'])) { | ||
$attributes['rel'] = 'stylesheet'; | ||
} | ||
|
||
$this->setAttributes($attributes); | ||
} | ||
|
||
/** | ||
* Set URL | ||
*/ | ||
public function setHref( | ||
string $href | ||
): void { | ||
$this->setAttribute('href', $href); | ||
} | ||
|
||
/** | ||
* Get URL | ||
*/ | ||
public function getHref(): string | ||
{ | ||
return Coercion::toString( | ||
$this->getAttribute('href') | ||
); | ||
} | ||
|
||
/** | ||
* Set rel | ||
*/ | ||
public function setRel( | ||
string $rel | ||
): void { | ||
$this->setAttribute('rel', $rel); | ||
} | ||
|
||
/** | ||
* Get rel | ||
*/ | ||
public function getRel(): string | ||
{ | ||
return Coercion::toString( | ||
$this->getAttribute('rel') ?? 'stylesheet' | ||
); | ||
} | ||
|
||
/** | ||
* Set type | ||
*/ | ||
public function setType( | ||
string $type | ||
): void { | ||
$this->setAttribute('type', $type); | ||
} | ||
|
||
/** | ||
* Get type | ||
*/ | ||
public function getType(): ?string | ||
{ | ||
return Coercion::toStringOrNull( | ||
$this->getAttribute('type') | ||
); | ||
} | ||
|
||
/** | ||
* Render | ||
*/ | ||
public function render(): Element | ||
{ | ||
return new Element('link', null, $this->attributes); | ||
} | ||
} |
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,120 @@ | ||
<?php | ||
|
||
/** | ||
* @package Tagged | ||
* @license http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DecodeLabs\Tagged\Asset; | ||
|
||
use DecodeLabs\Coercion; | ||
use DecodeLabs\Tagged\AssetTrait; | ||
use DecodeLabs\Tagged\Element; | ||
|
||
class RemoteScript implements Script | ||
{ | ||
use AssetTrait; | ||
|
||
/** | ||
* Init with URL | ||
* | ||
* @param array<string, mixed> $attributes | ||
*/ | ||
public function __construct( | ||
int $priority, | ||
string $src, | ||
array $attributes = [] | ||
) { | ||
$this->priority = $priority; | ||
$attributes['src'] = $src; | ||
|
||
if (!isset($attributes['type'])) { | ||
$attributes['type'] = 'text/javascript'; | ||
} | ||
|
||
$this->setAttributes($attributes); | ||
} | ||
|
||
/** | ||
* Set URL | ||
*/ | ||
public function setSrc( | ||
string $src | ||
): void { | ||
$this->setAttribute('src', $src); | ||
} | ||
|
||
/** | ||
* Get URL | ||
*/ | ||
public function getSrc(): string | ||
{ | ||
return Coercion::toString( | ||
$this->getAttribute('src') | ||
); | ||
} | ||
|
||
/** | ||
* Set async | ||
*/ | ||
public function setAsync( | ||
bool $async | ||
): void { | ||
$this->setAttribute('async', $async); | ||
} | ||
|
||
/** | ||
* Is async | ||
*/ | ||
public function isAsync(): bool | ||
{ | ||
return Coercion::toBool($this->getAttribute('async') ?? false); | ||
} | ||
|
||
/** | ||
* Set deferred | ||
*/ | ||
public function setDeferred( | ||
bool $deferred | ||
): void { | ||
$this->setAttribute('defer', $deferred); | ||
} | ||
|
||
/** | ||
* Is deferred | ||
*/ | ||
public function isDeferred(): bool | ||
{ | ||
return Coercion::toBool($this->getAttribute('defer') ?? false); | ||
} | ||
|
||
/** | ||
* Set type | ||
*/ | ||
public function setType( | ||
string $type | ||
): void { | ||
$this->setAttribute('type', $type); | ||
} | ||
|
||
/** | ||
* Get type | ||
*/ | ||
public function getType(): string | ||
{ | ||
return Coercion::toString( | ||
$this->getAttribute('type') ?? 'text/javascript' | ||
); | ||
} | ||
|
||
|
||
/** | ||
* Render | ||
*/ | ||
public function render(): Element | ||
{ | ||
return new Element('script', null, $this->attributes); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
/** | ||
* @package Tagged | ||
* @license http://opensource.org/licenses/MIT | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DecodeLabs\Tagged\Asset; | ||
|
||
use DecodeLabs\Tagged\Asset; | ||
|
||
interface Script extends Asset | ||
{ | ||
} |
Oops, something went wrong.