*/ private array $templates = []; /** * Next id. * * @var int */ private int $next_id = 1; /** * {@inheritDoc} * * @param string $key Key. * @param string $channel Channel. * @param string $locale Locale. */ public function find_by_key( string $key, string $channel = 'email', string $locale = 'en_GB' ): ?NotificationTemplate { foreach ( $this->templates as $template ) { if ( $template->key() === $key && $template->channel() === $channel && $template->locale() === $locale ) { return $template; } } return null; } /** * {@inheritDoc} * * @param NotificationTemplate $template Template. */ public function save( NotificationTemplate $template ): void { if ( null === $template->id() ) { $template->assign_id( $this->next_id++ ); } foreach ( $this->templates as $i => $existing ) { if ( $existing->id() === $template->id() ) { $this->templates[ $i ] = $template; return; } } $this->templates[] = $template; } /** * {@inheritDoc} * * @return list */ public function all(): array { return $this->templates; } /** * {@inheritDoc} * * @param int $id Id. */ public function find_by_id( int $id ): ?NotificationTemplate { foreach ( $this->templates as $template ) { if ( $template->id() === $id ) { return $template; } } return null; } }