Example #1
0
 /**
  * Get a JavaScript parser
  *
  * @param  array  $config Config array returned by the configurator
  * @return string         JavaScript parser
  */
 public function getParser(array $config = null)
 {
     $this->configOptimizer->reset();
     // Get the stylesheet used for rendering
     $this->xsl = (new XSLT())->getXSL($this->configurator->rendering);
     // Prepare the parser's config
     $this->config = isset($config) ? $config : $this->configurator->asConfig();
     ConfigHelper::filterVariants($this->config, 'JS');
     $this->config = $this->callbackGenerator->replaceCallbacks($this->config);
     // Get the parser's source and inject its config
     $src = $this->getHints() . $this->injectConfig($this->getSource());
     // Export the public API
     $src .= $this->getExports();
     // Minify the source
     $src = $this->getMinifier()->get($src);
     // Wrap the source in a function to protect the global scope
     $src = '(function(){' . $src . '})()';
     return $src;
 }
 /**
  * @testdox replaceCallbacks() tests
  * @dataProvider getReplaceCallbacksTests
  */
 public function testReplaceCallbacks($original, $expected)
 {
     $generator = new CallbackGenerator();
     $this->assertEquals($expected, $generator->replaceCallbacks($original));
 }