Example #1
0
 public function run()
 {
     if (!$this->run) {
         CommandHelper::runHelp();
         return;
     }
     $debug = new DebugHelper();
     if ($this->debug) {
         $debug->write(sprintf('Start %s', ucfirst($this->run)));
     }
     $command = sprintf('run%s', ucfirst($this->run));
     $this->{$command}();
     if ($this->debug) {
         $debug->write(sprintf('End %s', ucfirst($this->run)));
     }
 }
Example #2
0
    /**
     * Summary of prepare
     * @param string $statement 
     * @param array $driver_options 
     * @return PDOStatement
     */
    public function prepare($statement, $driver_options = array())
    {
        global $enableQueryLog;
        if ($enableQueryLog) {
            try {
                if ($this->queryLogStatement === null) {
                    $this->queryLogStatement = parent::prepare(<<<SQL
\t\t\t\t\t\t\tINSERT INTO applicationlog (source, message, stack, request, request_ts) 
\t\t\t\t\t\t\tVALUES (:source, :message, :stack, :request, :rqts);
SQL
);
                }
                $this->queryLogStatement->execute(array(":source" => "QueryLog", ":message" => $statement, ":stack" => DebugHelper::getBacktrace(), ":request" => $_SERVER["REQUEST_URI"], ":rqts" => $_SERVER["REQUEST_TIME_FLOAT"]));
            } catch (Exception $ex) {
                trigger_error("Error logging query. Disabling for this request. " . $ex->getMessage(), E_USER_NOTICE);
                $enableQueryLog = false;
            }
        }
        return parent::prepare($statement, $driver_options);
    }
Example #3
0
 /**
  * Returns an escaped string suitable for use within a javascript string
  *
  * for e.g.:
  *     let foo = "foo <?= $e->js('bar "bar" bar') ?>";
  *
  * will become:
  *     let foo = "foo bar \"bar\" bar";
  */
 public function js($string)
 {
     if ($string === '' || $string === false || $string === null) {
         return "";
     }
     // this also applies __toString()
     $string = (string) $string;
     if (is_string($string)) {
         $encoded = substr($this->jsonEncode($string), 1, -1);
         // json_encode only escapes double-quotes. escape singles by hand instead
         // of JSON_HEX_APOS in case old handsets don't like \u0027 (still need to
         // verify)
         return strtr($encoded, ["'" => "\\'"]);
     }
     throw new \InvalidArgumentException("String or number required. Found: " . \DebugHelper::getType($string));
 }