Exemple #1
0
 /** has token been used before?
  *
  * @var &array $source Source array
  * @var string $key    key to find token in source array, e.g. oncelerToken
  * @return bool|null true (not seen before), false (seen before), null (no token)
  */
 public static function check(&$source, $key)
 {
     if (!$key) {
         throw new Exception("\\ArtfulRobot\\Onceler::check - no key given");
     }
     if (!is_array($source)) {
         throw new Exception("\\ArtfulRobot\\Onceler::check - source is not an array");
     }
     $token = \ArtfulRobot\Utils::arrayValue($key, $source);
     // no token - return null;
     if (!$token) {
         \ArtfulRobot\Debug::log("!! Warning: \\ArtfulRobot\\Onceler::check - no token at key {$key} returning null");
         return null;
     }
     $spent_tokens =& \ArtfulRobot\Utils::arrayReference('\\ArtfulRobot\\Onceler::spent_tokens', $_SESSION, array());
     if (array_key_exists($token, $spent_tokens)) {
         \ArtfulRobot\Debug::log("!! \\ArtfulRobot\\Onceler: recognised spent token, resetting source token.");
         $source[$key] = false;
         return false;
     }
     //error_log("!! setting new token $token");
     // new token
     $spent_tokens[$token] = true;
     return true;
 }
Exemple #2
0
 public function debug($msg = null)
 {
     if ($msg === null) {
         $msg = "TOP " . get_class($this) . " myData:";
     }
     /**
      *
      */
     \ArtfulRobot\Debug::log($msg, $this->myData);
 }