Example #1
0
 /**
  * Compares the language versions.
  * @param tfProgram $prg
  */
 public function compare(tfProgram $prg)
 {
     if (!isset($this->args['-l'])) {
         return $this->main($prg);
     }
     $prg->loadLibrary('project');
     $prg->loadLibrary('parsers');
     $prg->loadLibrary('i18n');
     $prg->loadLibrary('tags');
     $project = new tfProject($this->args['#path']);
     tfProject::set($project);
     $project->versionCompare($this->args['-l']);
 }
Example #2
0
 /**
  * Registers the project in the global scope.
  * @param tfProject $project The project to register.
  */
 public static function set(tfProject $project)
 {
     self::$object = $project;
 }
Example #3
0
 /**
  * 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;
 }