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 * FormatterFactory constructor.
22 * @param ConfigManager $conf
24 public function __construct(ConfigManager
$conf)
30 * Instanciate a BookmarkFormatter depending on the configuration or provided formatter type.
32 * @param string|null $type force a specific type regardless of the configuration
34 * @return BookmarkFormatter instance.
36 public function getFormatter($type = null)
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';
44 return new $className($this->conf
);