Proyectos de Subversion Moodle

Rev

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

Rev 1 Rev 1441
Línea 28... Línea 28...
28
    private $waiters = null;
28
    private $waiters = null;
Línea 29... Línea 29...
29
 
29
 
30
    /** @var boolean */
30
    /** @var boolean */
Línea -... Línea 31...
-
 
31
    private $modifiedModel = false;
-
 
32
 
-
 
33
    /** @var string */
31
    private $modifiedModel = false;
34
    private $protocol;
32
 
35
 
33
    /**
36
    /**
34
     * @param array    $definition
37
     * @param array    $definition
35
     * @param callable $provider
38
     * @param callable $provider
Línea 67... Línea 70...
67
        }
70
        }
68
        $this->apiVersion = $this->getApiVersion();
71
        $this->apiVersion = $this->getApiVersion();
69
        if (isset($definition['clientContextParams'])) {
72
        if (isset($definition['clientContextParams'])) {
70
           $this->clientContextParams = $definition['clientContextParams'];
73
           $this->clientContextParams = $definition['clientContextParams'];
71
        }
74
        }
-
 
75
 
-
 
76
        $this->protocol = $this->selectProtocol($definition);
72
    }
77
    }
Línea 73... Línea 78...
73
 
78
 
74
    /**
79
    /**
75
     * Creates a request serializer for the provided API object.
80
     * Creates a request serializer for the provided API object.
Línea 112... Línea 117...
112
     * @param string $protocol Protocol to parse (e.g., query, json, etc.)
117
     * @param string $protocol Protocol to parse (e.g., query, json, etc.)
113
     *
118
     *
114
     * @return callable
119
     * @return callable
115
     * @throws \UnexpectedValueException
120
     * @throws \UnexpectedValueException
116
     */
121
     */
117
    public static function createErrorParser($protocol, Service $api = null)
122
    public static function createErrorParser($protocol, ?Service $api = null)
118
    {
123
    {
119
        static $mapping = [
124
        static $mapping = [
120
            'json'      => ErrorParser\JsonRpcErrorParser::class,
125
            'json'      => ErrorParser\JsonRpcErrorParser::class,
121
            'query'     => ErrorParser\XmlErrorParser::class,
126
            'query'     => ErrorParser\XmlErrorParser::class,
122
            'rest-json' => ErrorParser\RestJsonErrorParser::class,
127
            'rest-json' => ErrorParser\RestJsonErrorParser::class,
Línea 217... Línea 222...
217
     *
222
     *
218
     * @return string
223
     * @return string
219
     */
224
     */
220
    public function getServiceName()
225
    public function getServiceName()
221
    {
226
    {
222
        return $this->definition['metadata']['serviceIdentifier'];
227
        return $this->definition['metadata']['serviceIdentifier'] ?? null;
223
    }
228
    }
Línea 224... Línea 229...
224
 
229
 
225
    /**
230
    /**
226
     * Get the default signature version of the service.
231
     * Get the default signature version of the service.
Línea 239... Línea 244...
239
     *
244
     *
240
     * @return string
245
     * @return string
241
     */
246
     */
242
    public function getProtocol()
247
    public function getProtocol()
243
    {
248
    {
244
        return $this->definition['metadata']['protocol'];
249
        return $this->protocol;
245
    }
250
    }
Línea 246... Línea 251...
246
 
251
 
247
    /**
252
    /**
248
     * Get the uid string used by the service
253
     * Get the uid string used by the service
Línea 282... Línea 287...
282
            }
287
            }
283
            $this->operations[$name] = new Operation(
288
            $this->operations[$name] = new Operation(
284
                $this->definition['operations'][$name],
289
                $this->definition['operations'][$name],
285
                $this->shapeMap
290
                $this->shapeMap
286
            );
291
            );
287
        } else if ($this->modifiedModel) {
292
        } elseif ($this->modifiedModel) {
288
            $this->operations[$name] = new Operation(
293
            $this->operations[$name] = new Operation(
289
                $this->definition['operations'][$name],
294
                $this->definition['operations'][$name],
290
                $this->shapeMap
295
                $this->shapeMap
291
            );
296
            );
292
        }
297
        }
Línea 515... Línea 520...
515
     * @internal
520
     * @internal
516
     */
521
     */
517
    public function setDefinition($definition)
522
    public function setDefinition($definition)
518
    {
523
    {
519
        $this->definition = $definition;
524
        $this->definition = $definition;
-
 
525
        $this->shapeMap = new ShapeMap($definition['shapes']);
520
        $this->modifiedModel = true;
526
        $this->modifiedModel = true;
521
    }
527
    }
Línea 522... Línea 528...
522
 
528
 
523
    /**
529
    /**
Línea 530... Línea 536...
530
     */
536
     */
531
    public function isModifiedModel()
537
    public function isModifiedModel()
532
    {
538
    {
533
        return $this->modifiedModel;
539
        return $this->modifiedModel;
534
    }
540
    }
-
 
541
 
-
 
542
    /**
-
 
543
     * Accepts a list of protocols derived from the service model.
-
 
544
     * Returns the highest priority compatible auth scheme if the `protocols` trait is present.
-
 
545
     * Otherwise, returns the value of the `protocol` field, if set, or null.
-
 
546
     *
-
 
547
     * @param array $definition
-
 
548
     *
-
 
549
     * @return string|null
-
 
550
     */
-
 
551
    private function selectProtocol(array $definition): string | null
-
 
552
    {
-
 
553
        $modeledProtocols = $definition['metadata']['protocols'] ?? null;
-
 
554
        if (!empty($modeledProtocols)) {
-
 
555
            foreach(SupportedProtocols::cases() as $protocol) {
-
 
556
                if (in_array($protocol->value, $modeledProtocols)) {
-
 
557
                    return $protocol->value;
-
 
558
                }
-
 
559
            }
-
 
560
        }
-
 
561
 
-
 
562
        return $definition['metadata']['protocol'] ?? null;
-
 
563
    }
535
}
564
}