Flitch\Version::getVersion PHP Method

getVersion() public static method

If $part is null, the entire version is returned. If it is a string, the version part is returned. If a part is given and $fromBeginning is set to true, the version is returned from the beginning to the named part.
public static getVersion ( string $part = null, boolean $fromBeginning = false ) : string
$part string
$fromBeginning boolean
return string
    public static function getVersion($part = null, $fromBeginning = false)
    {
        if ($part === null) {
            return self::VERSION;
        } elseif (!preg_match('(^(?P<major>\\d+)\\.(?P<minor>\\d+)\\.(?P<mini>\\d+)(?P<suffix>.*)?$)', self::VERSION, $matches)) {
            throw new Exception\RuntimeException('Unable to parse application version');
        } elseif (!isset($matches[$part])) {
            throw new Exception\RuntimeException('Named part "' . $part . '" does not exist in version');
        } elseif ($fromBeginning === false) {
            return $matches[$part];
        } else {
            $version = '';
            for ($i = 1; $i <= self::$reverseMap[$part]; $i++) {
                $version .= ($i > 1 && $i < 4 ? '.' : '') . $matches[$i];
            }
            return $version;
        }
    }

Usage Example

Esempio n. 1
0
 /**
  * Run Flitch.
  *
  * @param  array $arguments
  * @return void
  */
 public function run(array $arguments)
 {
     echo "Flitch " . Version::getVersion() . " by Ben Scholzen 'DASPRiD'\n\n";
     $parser = new ArgumentParser($arguments, array(array('code' => 's', 'name' => 'standard', 'has_arg' => true), array('code' => 'c', 'name' => 'checkstyle', 'has_arg' => true), array('code' => 'q', 'name' => 'quiet', 'has_arg' => false), array('code' => 'h', 'name' => 'help', 'has_arg' => false), array('code' => 'v', 'name' => 'version', 'has_arg' => false)));
     if ($parser->getError() !== null) {
         echo $parser->getError() . "\n";
         return;
     }
     $method = 'analyzeFiles';
     foreach ($parser->getOptions() as $option) {
         switch ($option['code']) {
             case 's':
                 $this->standard = $option['argument'];
                 break;
             case 'c':
                 $this->checkstyleReportFilename = $option['argument'];
                 break;
             case 'q':
                 $this->quiet = true;
                 break;
             case 'h':
                 $method = 'printHelp';
                 break;
             case 'v':
                 return;
         }
     }
     foreach ($parser->getNonOptions() as $nonOption) {
         $this->paths[] = $nonOption;
     }
     $this->{$method}();
 }
Version