3 namespace Shaarli\Formatter
;
5 use Shaarli\Config\ConfigManager
;
8 * Class FormatterFactory
10 * Helper class used to instantiate the proper BookmarkFormatter.
12 * @package Shaarli\Formatter
14 class FormatterFactory
16 /** @var ConfigManager instance */
20 protected $isLoggedIn;
23 * FormatterFactory constructor.
25 * @param ConfigManager $conf
26 * @param bool $isLoggedIn
28 public function __construct(ConfigManager
$conf, bool $isLoggedIn)
31 $this->isLoggedIn
= $isLoggedIn;
35 * Instanciate a BookmarkFormatter depending on the configuration or provided formatter type.
37 * @param string|null $type force a specific type regardless of the configuration
39 * @return BookmarkFormatter instance.
41 public function getFormatter(string $type = null): BookmarkFormatter
43 $type = $type ? $type : $this->conf
->get('formatter', 'default');
44 $className = '\\Shaarli\\Formatter\\Bookmark' . ucfirst($type) . 'Formatter';
45 if (!class_exists($className)) {
46 $className = '\\Shaarli\\Formatter\\BookmarkDefaultFormatter';
49 return new $className($this->conf
, $this->isLoggedIn
);