Esempio n. 1
0
File: PHP.php Progetto: jasny/Q
 /**
  * Execute a PHP file and return the output
  *
  * @param array  $data Data to transform
  * @return string
  */
 public function process($data)
 {
     if ($this->chainInput) {
         $data = $this->chainInput->process($data);
     }
     return var_give($data, true, $this->castObjectToString);
 }
Esempio n. 2
0
File: misc.php Progetto: jasny/Q
/**
 * Serialize a debug_backtrace
 *
 * @param array      $trace
 * @param int|arrray $unset_first  Unset the first x number of entry's or unset until using array('file'=>file, 'line'=>line)
 */
function serialize_trace($trace, $unset_first = 0)
{
    if (is_array($unset_first)) {
        $step = null;
        do {
            $step = array_shift($trace);
        } while ($step && (!isset($step['file']) || !isset($step['line']) || $step['file'] != $unset_first['file'] || $step['line'] != $unset_first['line']));
    } else {
        while ($unset_first--) {
            array_shift($trace);
        }
    }
    $messages = array();
    foreach ($trace as $count => $step) {
        if (!isset($step['file'])) {
            $step['file'] = 'unknown';
        }
        if (!isset($step['line'])) {
            $step['line'] = 'unknown';
        }
        $args = array();
        if (isset($step['args'])) {
            foreach ($step['args'] as $arg) {
                $args[] = str_replace("\n", chr(182), var_give($arg, true, true));
            }
        }
        $messages[$count] = "#{$count} {$step['file']} ({$step['line']}): " . (isset($step['class']) ? $step['class'] . $step['type'] : '') . "{$step['function']}(" . join(', ', $args) . ")";
    }
    return join("\n", $messages);
}
Esempio n. 3
0
File: DB.php Progetto: jasny/Q
 /**
  * Create code for default properties.
  *
  * @param string $type
  * @param string $key
  */
 protected static function generateCode_ApplyDefaultProperties($type, $type_key)
 {
     $code = '';
     $count = 0;
     $forceType = "forceType{$type}Properties";
     foreach (self::${$forceType} as $p => $t) {
         $p = '"' . addcslashes($p, '"$') . '"';
         if ($t == 'array') {
             $code .= 'if (isset($properties[' . $type_key . '][' . $p . ']) && is_scalar($properties[' . $type_key . '][' . $p . '])) $properties[' . $type_key . '][' . $p . '] = Q\\split_set(";", $properties[' . $type_key . '][' . $p . ']);' . "\n";
         } else {
             $code .= 'if (isset($properties[' . $type_key . '][' . $p . '])) settype($properties[' . $type_key . '][' . $p . '], "' . addcslashes($t, '"$') . '");' . "\n";
         }
     }
     foreach (self::${"default{$type}Properties"} as $option_key => $options) {
         $option_key = addcslashes($option_key, '"$');
         foreach ($options as $option => $values) {
             $values_quoted = array();
             $applysimple = true;
             $apply = "";
             $count = 0;
             $option = preg_replace('/(?<!\\\\)(\\\\{2})*+{?\\$table\\.([^}\\s\']+)}?/', '$1{$properties["#table"]["$2"]}', $option, -1, $count);
             foreach ($values as $key => $value) {
                 $count = 0;
                 if (is_string($value) && strpos($value, '$') !== false) {
                     $value = preg_replace(array('/(?<!\\\\)(\\\\{2})*+{?\\$table\\.([^}\\s\']+)}?/', '/(?<!\\\\)(\\\\{2})*+{?\\$([a..z][^}\\s\']*)}?/i', '/(?<!\\\\)(\\\\{2})*+{?\\$(\\d+)}?/'), array('$1{$properties["#table"]["$2"]}', '$1{$properties[' . $type_key . ']["$2"]}', '$1{\\$matches[$2]}'), $value, -1, $count);
                 }
                 $key = addcslashes($key, '"$');
                 $var_value = is_string($value) ? '"' . str_replace('"', '\'', $value) . '"' : var_give($value, true);
                 if (is_array($value)) {
                     $apply .= '$properties[' . $type_key . ']["' . $key . '"] = empty($properties[' . $type_key . ']["' . $key . '"]) ? ' . $var_value . ' : array_unique(array_merge($properties[' . $type_key . ']["' . $key . '"], $var_value));' . "\n";
                 } else {
                     $apply .= 'if (!isset($properties[' . $type_key . ']["' . $key . '"])) $properties[' . $type_key . ']["' . $key . '"] = ' . $var_value . ';' . "\n";
                 }
                 $applysimple = $applysimple && $count == 0 && $key[0] !== '+';
                 if ($applysimple && is_string($value) && strpos($value, '\\$') !== 0) {
                     $values[$key] = str_replace('\\$', '', $value);
                 }
             }
             if ($applysimple) {
                 $apply = "\$properties[{$type_key}] += " . var_give($values, true) . ';' . "\n";
             } else {
                 $apply = "{\n{$apply}}\n";
             }
             if ($option[0] == '/') {
                 $code .= 'if (isset($properties[' . $type_key . ']["' . $option_key . '"]) && preg_match("' . str_replace('"', '\'', $option) . '", $properties[' . $type_key . ']["' . $option_key . '"], $matches)) ' . $apply;
             } else {
                 $code .= 'if (isset($properties[' . $type_key . ']["' . $option_key . '"]) && (is_array($properties[' . $type_key . ']["' . $option_key . '"]) ? in_array("' . str_replace('"', '\'', $option) . '", $properties[' . $type_key . ']["' . $option_key . '"]) : $properties[' . $type_key . ']["' . $option_key . '"] === "' . str_replace('"', '\'', $option) . '")) ' . $apply;
             }
         }
     }
     return $code;
 }