Proyectos de Subversion Moodle

Rev

Rev 1 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 1 Rev 1441
Línea 16... Línea 16...
16
class TraceMiddleware
16
class TraceMiddleware
17
{
17
{
18
    private $prevOutput;
18
    private $prevOutput;
19
    private $prevInput;
19
    private $prevInput;
20
    private $config;
20
    private $config;
21
 
-
 
22
    /** @var Service */
21
    /** @var Service */
23
    private $service;
22
    private $service;
Línea 24... Línea 23...
24
 
23
 
25
    private static $authHeaders = [
24
    private static $authHeaders = [
Línea 60... Línea 59...
60
     * - auth_headers: (array) A mapping of header names known to contain
59
     * - auth_headers: (array) A mapping of header names known to contain
61
     *   sensitive data to what the scrubbed value should be. The value of any
60
     *   sensitive data to what the scrubbed value should be. The value of any
62
     *   headers contained in this array will be replaced with the if
61
     *   headers contained in this array will be replaced with the if
63
     *   "scrub_auth" is set to true.
62
     *   "scrub_auth" is set to true.
64
     */
63
     */
65
    public function __construct(array $config = [], Service $service = null)
64
    public function __construct(array $config = [], ?Service $service = null)
66
    {
65
    {
67
        $this->config = $config + [
66
        $this->config = $config + [
68
            'logfn'        => function ($value) { echo $value; },
67
            'logfn'        => function ($value) { echo $value; },
69
            'stream_size'  => 524288,
68
            'stream_size'  => 524288,
70
            'scrub_auth'   => true,
69
            'scrub_auth'   => true,
Línea 83... Línea 82...
83
        $this->prevOutput = $this->prevInput = [];
82
        $this->prevOutput = $this->prevInput = [];
Línea 84... Línea 83...
84
 
83
 
85
        return function (callable $next) use ($step, $name) {
84
        return function (callable $next) use ($step, $name) {
86
            return function (
85
            return function (
87
                CommandInterface $command,
86
                CommandInterface $command,
88
                RequestInterface $request = null
87
                $request = null
89
            ) use ($next, $step, $name) {
88
            ) use ($next, $step, $name) {
90
                $this->createHttpDebug($command);
89
                $this->createHttpDebug($command);
91
                $start = microtime(true);
90
                $start = microtime(true);
92
                $this->stepInput([
91
                $this->stepInput([
Línea 162... Línea 161...
162
            'name'     => $cmd->getName(),
161
            'name'     => $cmd->getName(),
163
            'params'   => $this->getRedactedArray($cmd)
162
            'params'   => $this->getRedactedArray($cmd)
164
        ];
163
        ];
165
    }
164
    }
Línea 166... Línea 165...
166
 
165
 
167
    private function requestArray(RequestInterface $request = null)
166
    private function requestArray($request = null)
168
    {
167
    {
-
 
168
        return !$request instanceof RequestInterface
-
 
169
            ? []
169
        return !$request ? [] : array_filter([
170
            : array_filter([
170
            'instance' => spl_object_hash($request),
171
                'instance' => spl_object_hash($request),
171
            'method'   => $request->getMethod(),
172
                'method'   => $request->getMethod(),
172
            'headers'  => $this->redactHeaders($request->getHeaders()),
173
                'headers'  => $this->redactHeaders($request->getHeaders()),
173
            'body'     => $this->streamStr($request->getBody()),
174
                'body'     => $this->streamStr($request->getBody()),
174
            'scheme'   => $request->getUri()->getScheme(),
175
                'scheme'   => $request->getUri()->getScheme(),
175
            'port'     => $request->getUri()->getPort(),
176
                'port'     => $request->getUri()->getPort(),
176
            'path'     => $request->getUri()->getPath(),
177
                'path'     => $request->getUri()->getPath(),
177
            'query'    => $request->getUri()->getQuery(),
178
                'query'    => $request->getUri()->getQuery(),
178
        ]);
179
        ]);
Línea 179... Línea 180...
179
    }
180
    }
180
 
181
 
181
    private function responseArray(ResponseInterface $response = null)
182
    private function responseArray(?ResponseInterface $response = null)
182
    {
183
    {
183
        return !$response ? [] : [
184
        return !$response ? [] : [
184
            'instance'   => spl_object_hash($response),
185
            'instance'   => spl_object_hash($response),