| 1 |
<?php |
| 2 |
|
| 3 |
namespace YayMail\TemplatePatterns; |
| 4 |
|
| 5 |
use YayMail\TemplatePatterns\SectionTemplateService; |
| 6 |
use YayMail\Utils\Helpers; |
| 7 |
use YayMail\Utils\SingletonTrait; |
| 8 |
|
| 9 |
/** |
| 10 |
* @method static SectionTemplatesLoader get_instance() |
| 11 |
*/ |
| 12 |
class SectionTemplatesLoader { |
| 13 |
|
| 14 |
use SingletonTrait; |
| 15 |
|
| 16 |
/** |
| 17 |
* @var SectionTemplateService |
| 18 |
*/ |
| 19 |
public $service; |
| 20 |
|
| 21 |
private function __construct() { |
| 22 |
|
| 23 |
$this->service = SectionTemplateService::get_instance(); |
| 24 |
|
| 25 |
$dir = new \DirectoryIterator( Helpers::get_plugin_path() . '/src/TemplatePatterns/SectionTemplates' ); |
| 26 |
foreach ( $dir as $fileinfo ) { |
| 27 |
if ( ! $fileinfo->isDot() ) { |
| 28 |
$file_name = $fileinfo->getFilename(); |
| 29 |
$class_name = basename( $file_name, '.php' ); |
| 30 |
$class = 'YayMail\\TemplatePatterns\\SectionTemplates\\' . $class_name; |
| 31 |
if ( __CLASS__ === $class ) { |
| 32 |
continue; |
| 33 |
} |
| 34 |
if ( class_exists( $class ) ) { |
| 35 |
$this->service->register( $class::get_instance() ); |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
do_action( 'yaymail_register_template_sections', $this->service ); |
| 41 |
} |
| 42 |
} |
| 43 |
|