| 1 |
<?php |
| 2 |
namespace YayMail\TemplatePatterns; |
| 3 |
|
| 4 |
use YayMail\Abstracts\BasePattern; |
| 5 |
use YayMail\Abstracts\BaseSectionTemplate; |
| 6 |
use YayMail\Utils\SingletonTrait; |
| 7 |
|
| 8 |
/** |
| 9 |
* Class SectionTemplateService |
| 10 |
*/ |
| 11 |
class SectionTemplateService { |
| 12 |
|
| 13 |
use SingletonTrait; |
| 14 |
|
| 15 |
protected $sections = []; |
| 16 |
|
| 17 |
/** |
| 18 |
* @param BaseSectionTemplate $section_template_instance SectionTemplate object |
| 19 |
*/ |
| 20 |
public function register( BaseSectionTemplate $section_template_instance ) { |
| 21 |
if ( ! $section_template_instance instanceof BaseSectionTemplate ) { |
| 22 |
return; |
| 23 |
} |
| 24 |
|
| 25 |
$registered_sections = array_map( |
| 26 |
function( $item ) { |
| 27 |
return $item->get_type(); |
| 28 |
}, |
| 29 |
$this->sections |
| 30 |
); |
| 31 |
|
| 32 |
if ( in_array( $section_template_instance->get_type(), $registered_sections, true ) ) { |
| 33 |
return; |
| 34 |
} |
| 35 |
|
| 36 |
$this->sections[] = $section_template_instance; |
| 37 |
} |
| 38 |
|
| 39 |
public function get_list() { |
| 40 |
return $this->sections; |
| 41 |
} |
| 42 |
|
| 43 |
public function get_list_data() { |
| 44 |
return array_map( |
| 45 |
function( BaseSectionTemplate $item ) { |
| 46 |
return $item->get_raw_data(); |
| 47 |
}, |
| 48 |
$this->sections |
| 49 |
); |
| 50 |
} |
| 51 |
} |
| 52 |
|