public function AddRegexMatchesBasic(CodePattern $pattern, $text) { $text = preg_replace_callback($pattern->GetPatterns(), function ($match) use($pattern) { $classes = $pattern->GetClasses(); $handlers = $pattern->GetHandlers(); $output = ''; // reassemble components foreach ($pattern->GetComponents() as $name) { if (isset($match[$name])) { $region = $match[$name]; // check Handlers if (isset($handlers[$name])) { $handler_set = $handlers[$name]; if (!is_array($handler_set)) { $handler_set = [$handler_set]; } // probe Handlers foreach ($handler_set as $handler) { if (is_string($handler)) { $region_new = SyntaxHighlighter::Execute($region, [$handler => ['__probe' => true]]); } else { //$region_new = $this->AddRegexMatchesBasic($handler, $region); //$region_new = $this->ProcessPatterns([$handler], $region); $rm = new self(); $region_new = $rm->ProcessPatterns([$handler], $region); } // only use the first successful probe if ($region_new !== $region) { $region = $region_new; break; } } } if (isset($classes[$name])) { $region = $this->WrapCodeClass($region, $classes[$name]); } $output .= $region; } } if (isset($classes[NULL])) { $output = $this->WrapCodeClass($output, $classes[NULL]); } return $this->AddReplacedValue($output); }, $text); return $text; }
public function __construct($patterns, $class = NULL, $handlers = NULL) { if ($class === NULL && $handlers === NULL) { throw new \Exception(sprintf('ArgumentException %s::%s[class,handlers]', get_class(), __METHOD__)); } if ($class !== NULL && !is_string($class)) { throw new \Exception(sprintf('ArgumentException %s::%s[class]', get_class(), __METHOD__)); } parent::__construct($patterns, NULL, $class, $handlers); }
public function __construct($patterns, $classes = NULL, $handlers = NULL) { $components = ['start', 'value', 'end']; parent::__construct($patterns, $components, $classes, $handlers); }