Inspekt\Inspekt::walkArray PHP Method

walkArray() protected static method

This should be considered a "protected" method, and not be called outside of the class
protected static walkArray ( array | ArrayObjec\ArrayObject $input, string $method, string | null $classname = null ) : array
$input array | ArrayObjec\ArrayObject
$method string
$classname string | null
return array
    protected static function walkArray($input, $method, $classname = null)
    {
        if (!isset($classname)) {
            $classname = __CLASS__;
        }
        if (!self::isArrayOrArrayObject($input)) {
            throw new Exception('$input must be an array or ArrayObject');
        }
        if (!is_callable(array($classname, $method))) {
            throw new Exception('Inspektor ' . $classname . '::' . $method . ' is invalid');
        }
        foreach ($input as $key => $val) {
            if (is_array($val)) {
                $input[$key] = self::walkArray($val, $method, $classname);
            } else {
                $val = call_user_func(array($classname, $method), $val);
                $input[$key] = $val;
            }
        }
        return $input;
    }

Usage Example

Beispiel #1
0
 /**
  * Escapes the value given with pg_escape_bytea
  *
  * @param mixed $value
  * @param resource $conn the postgresql connection. If none is given, it will use the last link opened,
  *        per behavior of pg_escape_bytea
  * @return mixed
  *
  * @link http://php.net/manual/en/function.pg-escape-bytea.php
  */
 public static function escPgSQLBytea($value, $conn = null)
 {
     if (Inspekt::isArrayOrArrayObject($value)) {
         return Inspekt::walkArray($value, 'escPgSQL');
     } else {
         //might also check is_resource if pg_connection_status is too much
         if (isset($conn) && pg_connection_status($conn) === PGSQL_CONNECTION_OK) {
             return pg_escape_bytea($conn, $value);
         } else {
             return pg_escape_bytea($value);
         }
     }
 }