public function finalize(array $options = array()) { $return = array(); $options += array('addHTML5Rules' => \true, 'optimizeConfig' => \true, 'returnJS' => isset($this->javascript), 'returnParser' => \true, 'returnRenderer' => \true); if ($options['addHTML5Rules']) { $this->addHTML5Rules($options); } if ($options['returnRenderer']) { $renderer = $this->rendering->getRenderer(); if (isset($options['finalizeRenderer'])) { \call_user_func($options['finalizeRenderer'], $renderer); } $return['renderer'] = $renderer; } if ($options['returnJS'] || $options['returnParser']) { $config = $this->asConfig(); if ($options['returnJS']) { $return['js'] = $this->javascript->getParser(ConfigHelper::filterConfig($config, 'JS')); } if ($options['returnParser']) { $config = ConfigHelper::filterConfig($config, 'PHP'); if ($options['optimizeConfig']) { ConfigHelper::optimizeArray($config); } $parser = new Parser($config); if (isset($options['finalizeParser'])) { \call_user_func($options['finalizeParser'], $parser); } $return['parser'] = $parser; } } return $return; }
/** * Finalize this configuration and return all the relevant objects * * Options: (also see addHTMLRules() options) * * - addHTML5Rules: whether to call addHTML5Rules() * - finalizeParser: callback executed after the parser is created (gets the parser as arg) * - finalizeRenderer: same with the renderer * - optimizeConfig: whether to optimize the parser's config using references * - returnParser: whether to return an instance of Parser in the "parser" key * - returnRenderer: whether to return an instance of Renderer in the "renderer" key * * @param array $options * @return array One "parser" element and one "renderer" element unless specified otherwise */ public function finalize(array $options = []) { $return = []; // Add default options $options += ['addHTML5Rules' => true, 'optimizeConfig' => true, 'returnJS' => isset($this->javascript), 'returnParser' => true, 'returnRenderer' => true]; // Add the HTML5 rules if applicable if ($options['addHTML5Rules']) { $this->addHTML5Rules($options); } // Create a renderer as needed if ($options['returnRenderer']) { // Create a renderer $renderer = $this->getRenderer(); // Execute the renderer callback if applicable if (isset($options['finalizeRenderer'])) { $options['finalizeRenderer']($renderer); } $return['renderer'] = $renderer; } if ($options['returnJS'] || $options['returnParser']) { $config = $this->asConfig(); if ($options['returnJS']) { // Copy the config before replacing variants with their JS value $jsConfig = $config; ConfigHelper::filterVariants($jsConfig, 'JS'); $return['js'] = $this->javascript->getParser($jsConfig); } if ($options['returnParser']) { // Remove JS-specific data from the config ConfigHelper::filterVariants($config); if ($options['optimizeConfig']) { ConfigHelper::optimizeArray($config); } // Create a parser $parser = new Parser($config); // Execute the parser callback if applicable if (isset($options['finalizeParser'])) { $options['finalizeParser']($parser); } $return['parser'] = $parser; } } return $return; }