You are here

public function Transformer::addRules in Facebook Instant Articles 3.x

Same name and namespace in other branches
  1. 8.2 src/Transformer.php \Drupal\fb_instant_articles\Transformer::addRules()

Adds rules from an array of rule information.

Parameters

array $rules: An array of transformer rule arrays. This is a PHP array representation of the JSON list of Rules information expected by parent::loadRules().

Throws

\ReflectionException In case the class specified by one of the given $rules cannot be found.

See also

Transformer::__construct()

\Facebook\InstantArticles\Transformer\Transformer::loadRules()

1 call to Transformer::addRules()
Transformer::__construct in src/Transformer.php
Transformer constructor.

File

src/Transformer.php, line 64

Class

Transformer
Encapsulates Drupal-specific logic when using the Transformer class.

Namespace

Drupal\fb_instant_articles

Code

public function addRules(array $rules) {
  foreach ($rules as $rule) {
    $class = $rule['class'];
    try {
      $factory_method = new \ReflectionMethod($class, 'createFrom');
    } catch (\ReflectionException $e) {
      $factory_method = new \ReflectionMethod('Facebook\\InstantArticles\\Transformer\\Rules\\' . $class, 'createFrom');
    }
    $this
      ->addRule($factory_method
      ->invoke(NULL, $rule));
  }
}