/** 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; }
/** * Run query supplied and return first (or $col_name) field from first row. */ public function fetchSingle($query, $col_name = null) { $query = static::validQueryArg($query); $stmt = $this->prepAndExecute($query); if (!$stmt) { $output = null; } elseif ($col_name === null) { $output = $stmt->fetch(PDO::FETCH_COLUMN); } else { $row = $stmt->fetch(PDO::FETCH_ASSOC); $output = \ArtfulRobot\Utils::arrayValue($col_name, $row); } $this->debug("! fetchSingle returning: {$output}"); return $output; }
function runModule() { $task = \ArtfulRobot\Utils::arrayValue('task', $this->request); if (!$task) { $this->response->error = get_class($this) . " Task '{$task}' invalid"; return; } // convert task into PSR-2 (camel case) // some_task_name -> someTaskName $method_name = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $task)))); if (!method_exists($this, $method_name)) { $this->response->error = get_class($this) . " Task '{$task}' unknown"; return; } if ($this->task_methods && !in_array($method_name, $this->task_methods)) { $this->response->error = get_class($this) . " '{$method_name}' Method not a Task"; return; } $this->{$method_name}(); }