| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- namespace cx_newsletter;
- trait activity_simple_template {
- protected function set(string $name, mixed $content) : self {
- $this->site_params[$name] = $content;
- return $this;
- }
- public function get(string $name) : mixed {
- if (!array_key_exists($name, $this->site_params)) {
- return null;
- }
- return $this->site_params[$name];
- }
- protected function get_site_template_name() : ?string {
- return null;
- }
- protected function get_site_params() : array {
- $this->set('toast_place', $this->render_toast());
- return $this->site_params;
- }
- public function render() : \cx_appengine\string_builder {
- $template = match ($this->is_failed()) {
- true => $this->get_error_template(),
- false => $this->get_site_template()
- };
- $options = match ($this->is_failed()) {
- true => $this->get_error_site_params(),
- false => $this->get_site_params()
- };
- return $template->render($options);
- }
- protected function get_site_template() : \cx_appengine\template {
- $name = $this->get_site_template_name();
- if ($name === null) {
- $content = new \cx_appengine\string_builder();
- $content->push('Activity class must overwrite get_site_template ');
- $content->push('function or get_site_template_name() function.');
- throw new \Exception($content->get());
- }
- return (
- $this
- ->get_templates()
- ->prepare($name)
- );
- }
- protected function construct_simple_template() : self {
- $this->site_params = [];
- return $this;
- }
- private array $site_params;
- }
|