-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathTemplateFactory.php
More file actions
30 lines (25 loc) · 807 Bytes
/
Copy pathTemplateFactory.php
File metadata and controls
30 lines (25 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
namespace Tamtamchik\SimpleFlash;
use Tamtamchik\SimpleFlash\Exceptions\FlashTemplateNotFoundException;
/**
* Class TemplateFactory.
*/
class TemplateFactory
{
/**
* Return template from available list of templates.
*
* @param string $name - available templates see in Templates class.
*
* @return TemplateInterface
* @throws FlashTemplateNotFoundException
*/
public static function create(string $name = Templates::BASE): TemplateInterface
{
$class = __NAMESPACE__ . '\\Templates\\' . ucwords($name) . 'Template';
if (class_exists($class) && is_subclass_of($class, TemplateInterface::class)) {
return new $class();
}
throw new FlashTemplateNotFoundException("Template \"{$name}\" not found!");
}
}