1: <?php
2: namespace Pharborist;
3:
4: 5: 6:
7: class FormatterFactory {
8:
9: 10: 11:
12: protected static $defaultFormatter;
13:
14: 15: 16: 17: 18: 19: 20:
21: public static function getDefaultFormatter() {
22: if (!static::$defaultFormatter) {
23: static::$defaultFormatter = static::getDrupalFormatter();
24: }
25: return static::$defaultFormatter;
26: }
27:
28: 29: 30: 31: 32:
33: public static function setDefaultFormatter(Formatter $formatter) {
34: static::$defaultFormatter = $formatter;
35: }
36:
37: 38: 39: 40: 41: 42: 43:
44: public static function createFormatter($filename) {
45: $config = json_decode(file_get_contents($filename), TRUE);
46: return new Formatter($config['formatter']);
47: }
48:
49: public static function getDrupalFormatter() {
50: return static::createFormatter(dirname(__DIR__) . '/config/drupal.json');
51: }
52:
53: public static function getPsr2Formatter() {
54: return static::createFormatter(dirname(__DIR__) . '/config/psr2.json');
55: }
56:
57: 58: 59: 60: 61: 62:
63: public static function format(Node $node) {
64: static::getDefaultFormatter()->format($node);
65: }
66: }
67: