| 1 |
<?php |
| 2 |
|
| 3 |
namespace Monei\Services; |
| 4 |
|
| 5 |
class BlockSupportService { |
| 6 |
private string $blocksPath; |
| 7 |
private string $namespacePrefix; |
| 8 |
|
| 9 |
public function __construct( string $blocksPath, string $namespacePrefix ) { |
| 10 |
$this->blocksPath = $blocksPath; |
| 11 |
$this->namespacePrefix = $namespacePrefix; |
| 12 |
} |
| 13 |
|
| 14 |
/** |
| 15 |
* Discover and return all block support classes. |
| 16 |
* |
| 17 |
* @return string[] List of fully qualified class names. |
| 18 |
*/ |
| 19 |
public function getBlockSupportClasses(): array { |
| 20 |
$blockSupportClasses = array(); |
| 21 |
|
| 22 |
foreach ( glob( $this->blocksPath . '/*BlocksSupport.php' ) as $file ) { |
| 23 |
$className = $this->namespacePrefix . pathinfo( $file, PATHINFO_FILENAME ); |
| 24 |
if ( class_exists( $className ) ) { |
| 25 |
$blockSupportClasses[] = $className; |
| 26 |
} |
| 27 |
} |
| 28 |
|
| 29 |
return $blockSupportClasses; |
| 30 |
} |
| 31 |
} |
| 32 |
|