/** * @param int $flags The model flags * @return int The default calc order ID whose file formats use that signature */ public static function getDefaultOrderIDFromFlags($flags = 0) { return self::isValidFlags($flags) ? self::$models[$flags]['orderID'] : -1; } /** * @param string $sig The signature * @return string The minimum compatibility flags for that signaure */ public static function getMinFlagsFromSignature($sig = '') { return self::isValidSignature($sig) ? self::$models[$sig]['flags'] : 0; } public static function isValidFlags($flags = 0) { return $flags !== 0 && isset(self::$models[$flags]); } public static function isValidName($name = '') { return $name !== '' && isset(self::$models[$name]); } public static function isValidSignature($sig = '') { return $sig !== '' && isset(self::$models[$sig]); } } TIModels::initTIModelsArray();
/** * @param string $sig The signature (magic bytes) * @return TIModel * @throws \Exception */ public static function createFromSignature($sig = '') { if (TIModels::isValidSignature($sig)) { $instance = new self(); $instance->sig = $sig; $instance->orderID = TIModels::getDefaultOrderIDFromSignature($sig); $instance->flags = TIModels::getMinFlagsFromSignature($sig); $instance->name = TIModels::getDefaultNameFromSignature($sig); return $instance; } else { throw new \Exception("Invalid version signature"); } }