googleanalytics
/
lib
/
analytics-admin
/
vendor
/
google
/
gax
/
src
/
ResourceTemplate
/
ResourceTemplateInterface.php
googleanalytics
/
lib
/
analytics-admin
/
vendor
/
google
/
gax
/
src
/
ResourceTemplate
Last commit date
AbsoluteResourceTemplate.php
3 years ago
Parser.php
3 years ago
RelativeResourceTemplate.php
3 years ago
ResourceTemplateInterface.php
3 years ago
Segment.php
3 years ago
ResourceTemplateInterface.php
92 lines
| 1 | <?php |
| 2 | /* |
| 3 | * Copyright 2018 Google LLC |
| 4 | * All rights reserved. |
| 5 | * |
| 6 | * Redistribution and use in source and binary forms, with or without |
| 7 | * modification, are permitted provided that the following conditions are |
| 8 | * met: |
| 9 | * |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above |
| 13 | * copyright notice, this list of conditions and the following disclaimer |
| 14 | * in the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * * Neither the name of Google Inc. nor the names of its |
| 17 | * contributors may be used to endorse or promote products derived from |
| 18 | * this software without specific prior written permission. |
| 19 | * |
| 20 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 21 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 22 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 23 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 24 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 25 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 26 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 27 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 28 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | */ |
| 32 | |
| 33 | namespace Google\ApiCore\ResourceTemplate; |
| 34 | |
| 35 | use Google\ApiCore\ValidationException; |
| 36 | |
| 37 | /** |
| 38 | * Represents a resource template that may or may not contain a leading slash, and if a leading |
| 39 | * slash is present may contain a trailing verb (":<verb>"). (Note that a trailing verb without a |
| 40 | * leading slash is not permitted). |
| 41 | * |
| 42 | * Examples: |
| 43 | * projects |
| 44 | * /projects |
| 45 | * foo/{bar=**}/fizz/* |
| 46 | * /foo/{bar=**}/fizz/*:action |
| 47 | * |
| 48 | * Templates use the syntax of the API platform; see |
| 49 | * https://github.com/googleapis/api-common-protos/blob/master/google/api/http.proto |
| 50 | * for details. A template consists of a sequence of literals, wildcards, and variable bindings, |
| 51 | * where each binding can have a sub-path. A string representation can be parsed into an |
| 52 | * instance of AbsoluteResourceTemplate, which can then be used to perform matching and instantiation. |
| 53 | * |
| 54 | * @internal |
| 55 | */ |
| 56 | interface ResourceTemplateInterface |
| 57 | { |
| 58 | /** |
| 59 | * @return string A string representation of the resource template |
| 60 | */ |
| 61 | public function __toString(); |
| 62 | |
| 63 | /** |
| 64 | * Renders a resource template using the provided bindings. |
| 65 | * |
| 66 | * @param array $bindings An array matching var names to binding strings. |
| 67 | * @return string A rendered representation of this resource template. |
| 68 | * @throws ValidationException If $bindings does not contain all required keys |
| 69 | * or if a sub-template can't be parsed. |
| 70 | */ |
| 71 | public function render(array $bindings); |
| 72 | |
| 73 | /** |
| 74 | * Check if $path matches a resource string. |
| 75 | * |
| 76 | * @param string $path A resource string. |
| 77 | * @return bool |
| 78 | */ |
| 79 | public function matches(string $path); |
| 80 | |
| 81 | /** |
| 82 | * Matches a given $path to a resource template, and returns an array of bindings between |
| 83 | * wildcards / variables in the template and values in the path. If $path does not match the |
| 84 | * template, then a ValidationException is thrown. |
| 85 | * |
| 86 | * @param string $path A resource string. |
| 87 | * @throws ValidationException if path can't be matched to the template. |
| 88 | * @return array Array matching var names to binding values. |
| 89 | */ |
| 90 | public function match(string $path); |
| 91 | } |
| 92 |