aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/formatter/FormatterFactory.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2019-05-25 15:46:47 +0200
committerArthurHoaro <arthur@hoa.ro>2020-01-17 18:42:11 +0100
commit336a28fa4a09b968ce4705900bf57693e672f0bf (patch)
treeb3773e674a59c441270a56441fbadfa619527940 /application/formatter/FormatterFactory.php
parent796c4c57d085ae4589b53dfe8369ae9ba30ffdaf (diff)
downloadShaarli-336a28fa4a09b968ce4705900bf57693e672f0bf.tar.gz
Shaarli-336a28fa4a09b968ce4705900bf57693e672f0bf.tar.zst
Shaarli-336a28fa4a09b968ce4705900bf57693e672f0bf.zip
Introduce Bookmark object and Service layer to retrieve them
See https://github.com/shaarli/Shaarli/issues/1307 for details
Diffstat (limited to 'application/formatter/FormatterFactory.php')
-rw-r--r--application/formatter/FormatterFactory.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/application/formatter/FormatterFactory.php b/application/formatter/FormatterFactory.php
new file mode 100644
index 00000000..0d2c0466
--- /dev/null
+++ b/application/formatter/FormatterFactory.php
@@ -0,0 +1,46 @@
1<?php
2
3namespace Shaarli\Formatter;
4
5use Shaarli\Config\ConfigManager;
6
7/**
8 * Class FormatterFactory
9 *
10 * Helper class used to instantiate the proper BookmarkFormatter.
11 *
12 * @package Shaarli\Formatter
13 */
14class FormatterFactory
15{
16 /** @var ConfigManager instance */
17 protected $conf;
18
19 /**
20 * FormatterFactory constructor.
21 *
22 * @param ConfigManager $conf
23 */
24 public function __construct(ConfigManager $conf)
25 {
26 $this->conf = $conf;
27 }
28
29 /**
30 * Instanciate a BookmarkFormatter depending on the configuration or provided formatter type.
31 *
32 * @param string|null $type force a specific type regardless of the configuration
33 *
34 * @return BookmarkFormatter instance.
35 */
36 public function getFormatter($type = null)
37 {
38 $type = $type ? $type : $this->conf->get('formatter', 'default');
39 $className = '\\Shaarli\\Formatter\\Bookmark'. ucfirst($type) .'Formatter';
40 if (!class_exists($className)) {
41 $className = '\\Shaarli\\Formatter\\BookmarkDefaultFormatter';
42 }
43
44 return new $className($this->conf);
45 }
46}