public static function get() { if (is_null(tfParsers::$instance)) { tfParsers::$instance = new tfParsers(); } return tfParsers::$instance; }
/** * Generates the output document. * * @staticvar standardOutput $lastOutput The last output used. */ public function generate() { static $lastOutput = NULL; $prog = tfProgram::get(); $reparse = false; if ($lastOutput != $this->output) { $lastOutput = $this->output; $reparse = true; } $this->fs->safeMkDir('output/' . $this->output, TF_READ | TF_WRITE | TF_EXEC); $this->fs->cleanUpDirectory('output/' . $this->output); $this->copyMedia(); $this->outputObj = $out = $this->prog->fs->loadObject('outputs/' . $this->output . '.php', $this->output); if ($reparse) { $parsers = tfParsers::get(); $refs = array(); $refTitles = array(); foreach ($this->pages as &$page) { $refs[$page['Id']] = $this->outputObj->toAddress($page['Id']); $refTitles[$page['Id']] = ($this->config['showNumbers'] ? $page['FullNumber'] . '. ' : '') . (!isset($page['Tags']['ShortTitle']) ? $page['Tags']['Title'] : $page['Tags']['ShortTitle']); } $parsers->getParser()->predef_urls = $refs; $parsers->getParser()->predef_titles = $refTitles; } foreach ($this->pages as &$page) { if (!tfTags::validateTags($page['Tags'])) { throw new Exception('Tag validation error in "' . $page['Id'] . '": ' . PHP_EOL . tfTags::getError()); } } $out->init($this, 'output/' . $this->output . '/'); foreach ($this->pages as &$page) { if (!$this->parsed) { $page['Markdown'] = $page['Content']; } $parsers->getParser()->fn_id_prefix = str_replace('.', '_', $page['Id']) . ':'; $parsers->getParser()->page_id = $page['Id']; $page['Content'] = $parsers->parse($page['Markdown']); $out->generate($page); $prog->console->stderr->write('.'); } $prog->console->stderr->write(PHP_EOL); $this->parsed = true; $out->close(); }
private function __construct() { $program = tfProgram::get(); $this->parsers = tfParsers::get(); $this->fs = $program->fs; }
/** * Validates the tag list and returns the result. * * @param Array &$tags The list of tags * @return Boolean */ public static function validateTags(array &$tags) { // Process the "FeatureInformation" tag. // This tag has to be reparsed every time the method is invoked (because of parsing markdown) if (isset($tags['FeatureInformation'])) { $parser = tfParsers::get(); try { $tags['FeatureInformationFrame'] = $parser->parse(self::$_project->getTemplate($tags['FeatureInformation'])); } catch (SystemException $exception) { self::$_error = 'The feature information identifier: "' . $tags['FeatureInformation'] . '" is not defined.'; return false; } } if (isset($tags['%%Validated'])) { return true; } self::_buildTagList(); if (!isset($tags['Title'])) { self::$_error = 'The required tag "Title" is not defined.'; return false; } if (!isset($tags['ShortTitle'])) { $tags['ShortTitle'] = $tags['Title']; } // Validate the tags. foreach ($tags as $tag => &$value) { if (!isset(self::$_tags[$tag])) { if (!self::$_allowUnknown) { self::$_error = 'The tag "' . $tag . '" cannot be recognized as a valid TypeFriendly tag.'; return false; } } if (!self::_validate($value, self::$_tags[$tag])) { self::$_error = '"' . $tag . '": invalid value.'; return false; } } if (isset($tags['Extends']) && isset($tags['EExtends'])) { self::$_error = 'Tags "Extends" and "EExtends" cannot be used together.'; return false; } if ((isset($tags['Extends']) || isset($tags['EExtends'])) && (isset($tags['MultiExtends']) || isset($tags['EMultiExtends']))) { self::$_error = 'Tags "Extends" and "MultiExtends" cannot be used together.'; return false; } // Process the "Construct" tag if (isset($tags['Construct'])) { $translate = tfTranslate::get(); $construct = strtolower(trim($tags['Construct'])); if (!in_array($construct, self::$_constructs)) { $tags['ConstructType'] = 'unknown'; } else { $tags['ConstructType'] = str_replace(' ', '_', $construct); $tags['Construct'] = $translate->_('constructs', $tags['ConstructType']); } // Using the information from "Construct", we can perform some extra checks. $extends = false; $reference = false; $throws = false; $implementedBy = false; $mixins = false; $traits = false; switch ($tags['ConstructType']) { case 'function': case 'method': case 'static_method': case 'abstract_method': case 'accessor_method': case 'final_method': case 'final_static method': case 'final_accessor_method': case 'optional_method': case 'magic_method': case 'constructor': case 'destructor': case 'macro': case 'operator': $reference = true; $throws = true; break; case 'mixin': case 'trait': $implementedBy = true; break; case 'class': case 'abstract_class': case 'exception_class': case 'internal_class': case 'structure': $extends = true; case 'final_class': $mixins = true; $traits = true; break; case 'interface': $extends = true; $implementedBy = true; break; } if (!$reference && isset($tags['Reference'])) { self::$_error = 'Tag "Reference" is not allowed with the specified construct.'; return false; } if (!$throws && (isset($tags['Throws']) || isset($tags['EThrows']))) { self::$_error = 'Tags "Throws" and "EThrows" are not allowed with the specified construct.'; return false; } if (!$implementedBy && (isset($tags['ImplementedBy']) || isset($tags['EImplementedBy']))) { self::$_error = 'Tags "ImplementedBy" and "EImplementedBy" are not allowed with the specified construct.'; return false; } if (!$mixins && (isset($tags['Mixins']) || isset($tags['EMixins']))) { self::$_error = 'Tags "Mixins" and "EMixins" are not allowed with the specified construct.'; return false; } if (!$traits && (isset($tags['Traits']) || isset($tags['ETraits']))) { self::$_error = 'Tags "Traits" and "ETraits" are not allowed with the specified construct.'; return false; } if ($tags['ConstructType'] != 'internal_class' && (isset($tags['PartOf']) || isset($tags['EPartOf']))) { self::$_error = 'Tags "PartOf" and "EPartOf" are not allowed with the specified construct.'; return false; } if (!$extends && (isset($tags['Extends']) || isset($tags['EExtends']) || isset($tags['Implements']) || isset($tags['Implements']) || isset($tags['ExtendedBy']) || isset($tags['EExtendedBy']) || isset($tags['MultiExtends']) || isset($tags['EMultiExtends']))) { self::$_error = 'The tags that describe the OOP inheritance are not allowed with the specified construct.'; return false; } } $tags['%%Validated'] = true; return true; }