Exemple #1
0
 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;
     }
 }
Exemple #2
0
 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");
 }
Exemple #3
0
/**
 * 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;
}
Exemple #4
0
function mongo_ok($response)
{
    invariant(isset($response['ok']));
}
Exemple #5
0
 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);
}
Exemple #7
0
 public static function getNames()
 {
     $names = self::hacklib_get_names();
     invariant(self::$nonOverlappingValues, 'Enum has overlapping values');
     return $names;
 }
Exemple #8
0
 private static function dbTypeToUri($dbType)
 {
     switch ($dbType) {
         case self::DB_STUDENTS:
             return $GLOBALS['dburistudent'];
         case self::DB_INTERNSHIPS:
             return $GLOBALS['dburi'];
         default:
             invariant(false);
     }
 }
Exemple #9
0
 public function __construct(array $geocodeJSON)
 {
     invariant(!is_null($geocodeJSON));
     $this->data = $geocodeJSON;
 }
Exemple #10
0
 public function run()
 {
     invariant(isset($this->data));
     return self::insert($this->data);
 }
Exemple #11
0
 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}'");
     }
 }