static function fileExists($file) { $page = self::getFilePath($file); if (!file_exists($page)) { Utilities::log("Cannot find file for render {$page}"); return false; } return true; }
public function load($file) { $file = ROOT . '/lang/' . $file . '.' . self::LANG_FILE_EXT; if (!file_exists($file)) { Utilities::log("Cannot access lang file {$file}", Utilities::LOG_E); die; } $this->lang = parse_ini_file($file); if (!$this->lang) { Utilities::log("Cannot parse ini file {$file}", Utilities::LOG_E); die; } }
public static function getInstance() { if (DB::$INSTANCE == null) { $dsn = "mysql:host=" . Config::DB_HOST . ";dbname=" . Config::DB_NAME; try { DB::$INSTANCE = new PDO($dsn, Config::DB_USER, Config::DB_PASS, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC)); } catch (PDOException $e) { $str = "Cannot connect to database " . $e->getMessage(); Utilities::log($str, Utilities::LOG_E); die; } } return DB::$INSTANCE; }
public static function load() { self::$sid = self::getSid(); $data = Db::getUserBySid(self::$sid); self::$id = $data['id']; self::$rid = $data['rid']; self::$ip = $data['ip']; self::$token = Generator::token(); $newIp = self::getIp(); if (self::$ip != $newIp) { Utilities::log("Loaded existing user, different IP " . self::toString()); self::$ip = $newIp; } else { Utilities::log("Loaded existing user, same IP " . self::toString()); } DB::updateUserById(self::$id, self::$rid, $newIp, self::$sid, self::$token); }
public static function formatRid($rid, $format = Config::RID_DEFAULT_FORMAT) { if (substr_count($format, Config::RID_FORMAT_NUMBER) != Config::RID_LENGTH) { debug("Wrong count of number in format supplied for Generator::formatRid"); } if (substr_count($format, Config::RID_FORMAT_NUMBER) != strlen($rid)) { Utilities::log("Rid.length < Format.length in Generator.formantRid({$rid}, {$format})", Utilities::LOG_W); return $rid; } $ridIndex = 0; $output = ""; for ($i = 0; $i < strlen($format); $i++) { if ($format[$i] == "n") { $output .= $rid[$ridIndex++]; } else { $output .= $format[$i]; } } return $output; }
$action = Utilities::postOrNull('action'); $token = Utilities::postOrNull('token'); $rid = Utilities::postOrNull('rid'); $page = Utilities::postOrNull('page'); User::construct($rid, $token); if ($action == null) { Utilities::log("handler: Action is null " . User::toString(), Utilities::LOG_E); Ajax::sendError(); } switch ($action) { case Config::AJAX_ACTION_GENERATE_RID: $data = Ajax::generateRid(); break; case Config::AJAX_ACTION_GENERATE_NUMBER: $data = Ajax::generateNumber(); break; case Config::AJAX_ACTION_CHECK_RID: $data = Ajax::checkRid(); break; case Config::AJAX_ACTION_CHECK_USER: $data = Ajax::checkUser(); break; case Config::AJAX_ACTION_GET_PAGE: $data = Ajax::getPage($page); break; default: Utilities::log("Incorrect action {$action} " . User::toString(), Utilities::LOG_E); Ajax::sendError(); } DB::close(); exit($data);
public static function actRidFormat() { if (User::$rid == null) { Utilities::log("RID is null " . User::toString(), Utilities::LOG_E); self::sendError(2); } if (!Generator::checkRidFormat(User::$rid)) { Utilities::log("Incorrect RID format " . User::toString(), Utilities::LOG_E); self::sendError(0); } }
* F6 (Windows/Linux/Mac OS X) */ namespace Refactoring11\JetBrains; // 1. Move the current file into the Code directory. // 2. Move the Code directory and all its contents into the MoreCode directory. // 3. Move Class1, Class2 and Class3 into separate files. class Class1 { } class Class2 { } class Class3 { } // 4. Move the static method log() from the Utilities class to the Logger class. class Utilities { public static function log($message) { echo $message; } } class Logger { } // 5. Note that the calls to Utilities::log() have been updated. Utilities::log('Almost at the end of the exercise'); Utilities::log('At the end of the exercise');