Exemple #1
0
 /** Generate a token we've not used before
  */
 public static function newToken()
 {
     $spent_tokens = \ArtfulRobot\Utils::arrayReference('\\ArtfulRobot\\Onceler::spent_tokens', $_SESSION, array());
     while (array_key_exists($new = md5(++self::$count . 'NaCl' . time()), $spent_tokens)) {
         self::$count++;
     }
     return $new;
 }
Exemple #2
0
 /**
  * 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}();
 }