Ejemplo n.º 1
0
 /**
  * @param array $ctx_rules
  * @param array $formatting_rules
  * @param \Phpcf\ExecStat $Stat
  */
 public final function __construct(array $ctx_rules, array $formatting_rules, \Phpcf\ExecStat $Stat)
 {
     \Phpcf\Helper::loadExtension('tokenizer');
     $this->initControls($formatting_rules);
     $this->FSM = new Fsm($ctx_rules);
     $this->FSM->setExecStat($Stat);
     $this->Stat = $Stat;
     $this->Stat->setCallback([$this, 'printAllContextMessages']);
     $this->init();
 }
Ejemplo n.º 2
0
 private function initImplementation()
 {
     \Phpcf\Helper::loadExtension('tokenizer');
     $fsm_context_rules = (require __DIR__ . "/../styles/default/context-rules.php");
     $controls = (require __DIR__ . "/../styles/default/formatting-rules.php");
     $custom_style_dir = $this->Options->getCustomStyle();
     $custom_formatter_class = null;
     $use_pure = false;
     if (!empty($custom_style_dir)) {
         // check, which dir is given - relative, or absolute
         if (strpos($custom_style_dir, DIRECTORY_SEPARATOR) === false) {
             $custom_style_dir = __DIR__ . '/../styles/' . $custom_style_dir . '/';
         }
         if (!is_dir($custom_style_dir)) {
             throw new \RuntimeException("Given custom style dir '{$custom_style_dir}' is not a dir");
         }
         if (file_exists($file = $custom_style_dir . DIRECTORY_SEPARATOR . "context-rules.php")) {
             require $file;
         }
         if (file_exists($file = $custom_style_dir . DIRECTORY_SEPARATOR . "formatting-rules.php")) {
             require $file;
         }
         if (file_exists($file = $custom_style_dir . DIRECTORY_SEPARATOR . "phpcf-class.php")) {
             require_once $file;
             $class_name = ucfirst(pathinfo($custom_style_dir, PATHINFO_FILENAME));
             $custom_formatter_class = "\\Phpcf\\Impl\\PHPCF_{$class_name}";
             if (!class_exists($custom_formatter_class, false)) {
                 throw new \InvalidArgumentException("Custom formatter class '{$custom_formatter_class}' not found in '{$file}'");
             } else {
                 if (!in_array(ltrim(self::IMPL_CLASS, '\\'), class_parents($custom_formatter_class, true))) {
                     throw new \InvalidArgumentException("Class '{$custom_formatter_class}' must be instanceof '" . self::IMPL_CLASS . "'");
                 }
             }
             $use_pure = true;
         }
     }
     $use_pure = $this->Options->getPureBehaviour() || $use_pure;
     if (!$use_pure) {
         try {
             \Phpcf\Helper::loadExtension('phpcf');
             if (function_exists('phpcf_get_version')) {
                 $version = phpcf_get_version();
                 if ($version !== PHPCF_VERSION && !$this->Options->isQuiet()) {
                     $error_string = "Extension use disabled, version mismatch: '" . PHPCF_VERSION . "' != '{$version}'";
                     trigger_error($error_string, E_USER_NOTICE);
                     $use_pure = true;
                 }
             } else {
                 // old version
                 $use_pure = true;
             }
         } catch (\Exception $Error) {
             $use_pure = true;
         }
     }
     if ($use_pure) {
         $formatter_class = $custom_formatter_class ? $custom_formatter_class : self::IMPL_CLASS;
         $this->Implementation = new $formatter_class($fsm_context_rules, $controls, new ExecStat());
     } else {
         $this->Implementation = new \Phpcf\Impl\Extension($fsm_context_rules, $controls);
     }
     if ($this->Options->isCyrillicFilterEnabled()) {
         $this->Implementation->setStringFilter(new \Phpcf\Filter\StringAscii(new \Phpcf\Filter\StringAsciiMapCyr()));
     }
 }