/** * Return a locomotive * * @since Version 3.9.1 * @return \Railpage\Locos\Locomotive * * @param int|bool $id * @param string|bool $class * @param string|bool $number */ public static function CreateLocomotive($id = false, $class = false, $number = false) { $Redis = AppCore::getRedis(); $Registry = Registry::getInstance(); if (!filter_var($id, FILTER_VALIDATE_INT)) { $id = Utility\LocomotiveUtility::getLocoId($class, $number); } if ($id = filter_var($id, FILTER_VALIDATE_INT)) { $regkey = sprintf(Locomotive::REGISTRY_KEY, $id); try { $Loco = $Registry->get($regkey); } catch (Exception $e) { $cachekey = sprintf(Locomotive::CACHE_KEY, $id); if (!self::USE_REDIS || !($Loco = $Redis->fetch($cachekey))) { $Loco = new Locomotive($id); if (self::USE_REDIS) { $Redis->save($cachekey, $Loco); } } $Registry->set($regkey, $Loco); } return $Loco; } return false; }
/** * Constructor * @since Version 3.2 * @param int $id * @param int|string $classIdOrSlug * @param string $number */ public function __construct($id = NULL, $classIdOrSlug = NULL, $number = NULL) { parent::__construct(); $timer = Debug::getTimer(); /** * Record this in the debug log */ Debug::RecordInstance(NULL, $id); $this->bootstrap(); if (filter_var($id, FILTER_VALIDATE_INT)) { $this->id = filter_var($id, FILTER_VALIDATE_INT); } else { $this->id = Utility\LocomotiveUtility::getLocoId($classIdOrSlug, $number); } // Load the loco object if (filter_var($this->id, FILTER_VALIDATE_INT)) { $this->fetch(); } $this->id = intval($this->id); Debug::logEvent(sprintf("%s(%d)", __METHOD__, $this->id), $timer); }