Beispiel #1
0
 /**
  * Parse the request
  * @return self
  * @api
  */
 public function distribute()
 {
     try {
         Container::get('request')->parse();
     } catch (\Exception $e) {
         $this->error($e->getMessage(), Response::STATUS_BAD_REQUEST);
     }
     if (!Container::get('request')->isMethod('get') && !Container::get('request')->isMethod('post') && !Container::get('request')->isMethod('head')) {
         $this->error(sprintf('Request method "%s" is not allowed!', Container::get('request')->getMethod()), Response::STATUS_METHOD_NOT_ALLOWED);
     }
     // analyze request headers
     foreach (Container::get('request')->getHeaders() as $name => $value) {
         switch ($name) {
             case 'Time-Zone':
                 if (in_array($value, timezone_identifiers_list())) {
                     date_default_timezone_set($value);
                 } else {
                     $this->warning(sprintf('The "%s" timezone defined is not valid!', $value));
                 }
                 break;
             default:
                 break;
         }
     }
     // user files
     $type = Container::get('request')->getData('source_type', 'data_input');
     $this->setSourceType($type);
     if ($this->getSourceType() == 'file') {
         $files = Container::get('request')->getFiles();
         if (!empty($files)) {
             foreach ($files as $name => $path) {
                 $this->addSource(file_get_contents($path), $name);
             }
         }
     }
     // any test to launch
     $test = Container::get('request')->getData('test');
     if (!empty($test)) {
         $method = 'testAction_' . $test;
         if (method_exists($this, $method)) {
             call_user_func(array($this, $method));
         } else {
             $this->warning(sprintf('Test method "%s" not found!', $test));
         }
     }
     // end here if no 'source' or 'sources' post data
     $source = Container::get('request')->getData('source');
     $sources = Container::get('request')->getData('sources');
     $_sources = $this->getSources();
     if (empty($source) && empty($sources) && empty($_sources)) {
         $this->warning('No source to parse!')->serve();
     } else {
         if (!empty($sources)) {
             $this->setSources(array_merge($_sources, $sources));
         }
         if (!empty($source)) {
             $this->addSource($source);
         }
     }
     // debug mode on?
     $this->setDebug(Container::get('request')->getData('debug', false));
     // load the MDE parser
     if (!class_exists('\\MarkdownExtended\\MarkdownExtended')) {
         $this->error('Class "\\MarkdownExtended\\MarkdownExtended" not found!');
     }
     Container::set('mde_parser', \MarkdownExtended\MarkdownExtended::create());
     return $this;
 }
 public function getMarkdownParser()
 {
     if (empty($this->markdown_parser)) {
         // creating the Markdown parser
         $emd_config = $this->registry->getConfig('markdown', array(), 'docbook');
         $emd_config_strs = $this->registry->getConfig('markdown_i18n', array(), 'docbook');
         if (!empty($emd_config_strs) && is_array($emd_config_strs) && count($emd_config_strs) == 1 && isset($emd_config_strs['markdown_i18n'])) {
             $emd_config_strs = $emd_config_strs['markdown_i18n'];
         }
         if (empty($emd_config)) {
             $emd_config = array();
         }
         $translator = I18n::getInstance();
         foreach ($emd_config_strs as $_str) {
             $emd_config[$_str] = $translator->translate($_str);
         }
         $this->setMarkdownParser(MarkdownExtended::create($emd_config));
     }
     return $this->markdown_parser;
 }