Overview

Namespaces

  • Pharborist
    • Constants
    • ControlStructures
    • Exceptions
    • Functions
    • Generators
    • Namespaces
    • Objects
    • Operators
    • Types
    • Variables

Classes

  • Pharborist\Variables\CompoundVariableNode
  • Pharborist\Variables\GlobalStatementNode
  • Pharborist\Variables\ReferenceVariableNode
  • Pharborist\Variables\StaticVariableNode
  • Pharborist\Variables\StaticVariableStatementNode
  • Pharborist\Variables\VariableNode
  • Pharborist\Variables\VariableVariableNode

Interfaces

  • Pharborist\Variables\VariableExpressionNode
  • Overview
  • Namespace
  • Class
 1: <?php
 2: namespace Pharborist;
 3: 
 4: /**
 5:  * Formatter factory.
 6:  */
 7: class FormatterFactory {
 8: 
 9:   /**
10:    * @var Formatter
11:    */
12:   protected static $defaultFormatter;
13: 
14:   /**
15:    * Get the default formatter.
16:    *
17:    * The default formatter is used by node builders.
18:    *
19:    * @return Formatter
20:    */
21:   public static function getDefaultFormatter() {
22:     if (!static::$defaultFormatter) {
23:       static::$defaultFormatter = static::getDrupalFormatter();
24:     }
25:     return static::$defaultFormatter;
26:   }
27: 
28:   /**
29:    * Set the default formatter.
30:    *
31:    * @param Formatter $formatter
32:    */
33:   public static function setDefaultFormatter(Formatter $formatter) {
34:     static::$defaultFormatter = $formatter;
35:   }
36: 
37:   /**
38:    * Create formatter using the specified config file.
39:    *
40:    * @param string $filename
41:    *
42:    * @return Formatter
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:    * Format a node using the default formatter.
59:    *
60:    * @param Node $node
61:    *   Node to format.
62:    */
63:   public static function format(Node $node) {
64:     static::getDefaultFormatter()->format($node);
65:   }
66: }
67: 
Pharborist API documentation generated by ApiGen