-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update phpstan/phpstan requirement from ^1.11 to ^1.12 (#5)
- Loading branch information
1 parent
72d50d4
commit fb3677c
Showing
21 changed files
with
337 additions
and
114 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,85 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Codex\Foundation\Assets; | ||
|
||
use Codex\Contracts\Enqueueable; | ||
use Codex\Contracts\HasAdminScripts; | ||
use Codex\Contracts\HasPublicScripts; | ||
use Codex\Contracts\Hookable; | ||
use Codex\Foundation\Hooks\Hook; | ||
|
||
use function is_iterable; | ||
|
||
class Assets implements Hookable | ||
{ | ||
private Hook $hook; | ||
|
||
private Enqueue $enqueue; | ||
|
||
public function __construct(Enqueue $enqueue) | ||
{ | ||
$this->enqueue = $enqueue; | ||
} | ||
|
||
public function hook(Hook $hook): void | ||
{ | ||
$this->hook = $hook; | ||
} | ||
|
||
/** @param HasAdminScripts|HasPublicScripts $instance */ | ||
public function enqueue($instance): void | ||
{ | ||
if ($instance instanceof HasAdminScripts) { | ||
$this->hook->addAction( | ||
'admin_enqueue_scripts', | ||
function (string $admin) use ($instance): void { | ||
$assets = $instance->getAdminScripts($admin); | ||
|
||
if (! is_iterable($assets)) { | ||
return; | ||
} | ||
|
||
$this->enqueueScripts($assets); | ||
}, | ||
12, | ||
); | ||
|
||
return; | ||
} | ||
|
||
$this->hook->addAction( | ||
'wp_enqueue_scripts', | ||
function () use ($instance): void { | ||
$assets = $instance->getPublicScripts(); | ||
|
||
if (! is_iterable($assets)) { | ||
return; | ||
} | ||
|
||
$this->enqueueScripts($assets); | ||
}, | ||
12, | ||
); | ||
} | ||
|
||
/** @param iterable<Enqueueable> $assets */ | ||
private function enqueueScripts(iterable $assets): void | ||
{ | ||
foreach ($assets as $asset) { | ||
if ($asset instanceof Script) { | ||
$this->enqueue->addScripts($asset); | ||
} | ||
|
||
if (! ($asset instanceof Style)) { | ||
continue; | ||
} | ||
|
||
$this->enqueue->addStyles($asset); | ||
} | ||
|
||
$this->enqueue->scripts(); | ||
$this->enqueue->styles(); | ||
} | ||
} |
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,42 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Codex\Foundation; | ||
|
||
use InvalidArgumentException; | ||
use RecursiveDirectoryIterator; | ||
use SplFileInfo; | ||
|
||
use function is_dir; | ||
|
||
class Blocks | ||
{ | ||
private string $blocksPath; | ||
|
||
/** @param string $blocksPath The path where all the blocks are located. */ | ||
public function __construct(string $blocksPath) | ||
{ | ||
$this->blocksPath = $blocksPath; | ||
|
||
if (! is_dir($this->blocksPath)) { | ||
throw new InvalidArgumentException('The blocks path is not a directory.'); | ||
} | ||
} | ||
|
||
public function register(): void | ||
{ | ||
$blocks = new RecursiveDirectoryIterator( | ||
$this->blocksPath, | ||
RecursiveDirectoryIterator::SKIP_DOTS, | ||
); | ||
|
||
foreach ($blocks as $block) { | ||
if (! ($block instanceof SplFileInfo) || ! $block->isDir()) { | ||
continue; | ||
} | ||
|
||
register_block_type($block->getRealPath()); | ||
} | ||
} | ||
} |
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
Oops, something went wrong.