public function __construct($id = null) { if ($id === null) { $this->fact = mt_rand(0, count(self::$facts) - 1); } else { invariant((is_numeric_and_not_octal($id) || $id === self::TEST_FACT) && $id >= 0 && $id < count(self::$facts), 'Hey that is counterfactual'); $this->fact = $id; } }
public static function routeTree($route, $callName) { $route = strtolower($route); $callName = strtolower($callName); invariant(isset(self::$callMap[$callName]), "'{$callName}' is not a registered callName."); $routePath = self::routeStringToArray($route); $lastIndex = count($routePath) - 1; $curNode =& self::$routeTree; foreach ($routePath as $index => $branch) { // If is last in $routePath, place the $callName. if ($index == $lastIndex) { $curNode[$branch] = $callName; break; } // If the branch exists: // If the branch is a leaf, replace with node. // If the branch is a node, continue. if (!isset($curNode[$branch]) or !is_array($curNode[$branch])) { $curNode[$branch] = []; } $curNode =& $curNode[$branch]; } self::route("{$route}/index", "backtoindex"); }
/** * Pass a function that will be called if any invariant fails. The callback * will be called with all the invariant parameters after the condition. */ function invariant_callback_register($callback) { invariant(!InvariantCallback::$cb, 'Callback already registered: %s', InvariantCallback::$cb); InvariantCallback::$cb = $callback; }
function mongo_ok($response) { invariant(isset($response['ok'])); }
public static function setApplicationQuestionIds(MongoId $jobId, array $questionIds) { invariant(isset(self::$collection)); $update = (new DBUpdateQuery(self::$collection))->toQuery('_id', $jobId)->toUpdate('application', $questionIds); $update->run(); }
function TRUE($truthy, $errorMessage = '') { invariant($truthy, $errorMessage); }
public static function getNames() { $names = self::hacklib_get_names(); invariant(self::$nonOverlappingValues, 'Enum has overlapping values'); return $names; }
private static function dbTypeToUri($dbType) { switch ($dbType) { case self::DB_STUDENTS: return $GLOBALS['dburistudent']; case self::DB_INTERNSHIPS: return $GLOBALS['dburi']; default: invariant(false); } }
public function __construct(array $geocodeJSON) { invariant(!is_null($geocodeJSON)); $this->data = $geocodeJSON; }
public function run() { invariant(isset($this->data)); return self::insert($this->data); }
private static function schemaProcessType($val, $type) { switch ($type) { case 'nullString': case 'emptyString': case 'string': return (string) $val; case 'nullDate': case 'date': return new MongoDate($val); case 'nullId': case 'id': case 'notSetId': return new MongoId($val); case 'bool': return boolval($val); case 'arrayOfStrings': $newVal = []; foreach ($val as $item) { $newVal[] = (string) $item; } return $newVal; case 'arrayOfIds': $newVal = []; foreach ($val as $item) { $newVal[] = new MongoId($item); } return $newVal; default: invariant(false, "Schema::schemaProcessType() received invalid type '{$type}'"); } }