PluginProbe
Media Cloud Sync / 1.2.2
Media Cloud Sync v1.2.2
1.4.2 1.4.1 1.4.0 1.3.12 1.3.11 1.3.10 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.2.0 1.2.10 1.2.11 1.2.12 1.2.13 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 All 36 releases
media-cloud-sync / includes / sdk / google / google / gax / src / PageStreamingDescriptor.php

PageStreamingDescriptor.php in Media Cloud Sync 1.2.2, at includes/sdk/google/google/gax/src/PageStreamingDescriptor.php

152 lines 6.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /*
4 * Copyright 2016 Google LLC
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions are
9 * met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following disclaimer
15 * in the documentation and/or other materials provided with the
16 * distribution.
17 * * Neither the name of Google Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 */
33 namespace Dudlewebs\WPMCS\Google\ApiCore;
34
35 use InvalidArgumentException;
36 /**
37 * Holds the description information used for page streaming.
38 */
39 class PageStreamingDescriptor
40 {
41 private $descriptor;
42 /**
43 * @param array $descriptor {
44 * Required.
45 * @type string $requestPageTokenGetMethod the get method for the page token in the request object.
46 * @type string $requestPageTokenSetMethod the set method for the page token in the request object.
47 * @type string $responsePageTokenGetMethod the get method for the page token in the response object.
48 * @type string resourcesGetMethod the get method for the resources in the response object.
49 *
50 * Optional.
51 * @type string $requestPageSizeGetMethod the get method for the page size in the request object.
52 * }
53 */
54 public function __construct(array $descriptor)
55 {
56 self::validate($descriptor);
57 $this->descriptor = $descriptor;
58 }
59 /**
60 * @param array $fields {
61 * Required.
62 *
63 * @type string $requestPageTokenField the page token field in the request object.
64 * @type string $responsePageTokenField the page token field in the response object.
65 * @type string $resourceField the resource field in the response object.
66 *
67 * Optional.
68 * @type string $requestPageSizeField the page size field in the request object.
69 * }
70 * @return PageStreamingDescriptor
71 */
72 public static function createFromFields(array $fields)
73 {
74 $requestPageToken = $fields['requestPageTokenField'];
75 $responsePageToken = $fields['responsePageTokenField'];
76 $resources = $fields['resourceField'];
77 $descriptor = ['requestPageTokenGetMethod' => PageStreamingDescriptor::getMethod($requestPageToken), 'requestPageTokenSetMethod' => PageStreamingDescriptor::setMethod($requestPageToken), 'responsePageTokenGetMethod' => PageStreamingDescriptor::getMethod($responsePageToken), 'resourcesGetMethod' => PageStreamingDescriptor::getMethod($resources)];
78 if (isset($fields['requestPageSizeField'])) {
79 $requestPageSize = $fields['requestPageSizeField'];
80 $descriptor['requestPageSizeGetMethod'] = PageStreamingDescriptor::getMethod($requestPageSize);
81 $descriptor['requestPageSizeSetMethod'] = PageStreamingDescriptor::setMethod($requestPageSize);
82 }
83 return new PageStreamingDescriptor($descriptor);
84 }
85 private static function getMethod(string $field)
86 {
87 return 'get' . ucfirst($field);
88 }
89 private static function setMethod(string $field)
90 {
91 return 'set' . ucfirst($field);
92 }
93 /**
94 * @return string The page token get method on the request object
95 */
96 public function getRequestPageTokenGetMethod()
97 {
98 return $this->descriptor['requestPageTokenGetMethod'];
99 }
100 /**
101 * @return string The page size get method on the request object
102 */
103 public function getRequestPageSizeGetMethod()
104 {
105 return $this->descriptor['requestPageSizeGetMethod'];
106 }
107 /**
108 * @return bool True if the request object has a page size field
109 */
110 public function requestHasPageSizeField()
111 {
112 return array_key_exists('requestPageSizeGetMethod', $this->descriptor);
113 }
114 /**
115 * @return string The page token get method on the response object
116 */
117 public function getResponsePageTokenGetMethod()
118 {
119 return $this->descriptor['responsePageTokenGetMethod'];
120 }
121 /**
122 * @return string The resources get method on the response object
123 */
124 public function getResourcesGetMethod()
125 {
126 return $this->descriptor['resourcesGetMethod'];
127 }
128 /**
129 * @return string The page token set method on the request object
130 */
131 public function getRequestPageTokenSetMethod()
132 {
133 return $this->descriptor['requestPageTokenSetMethod'];
134 }
135 /**
136 * @return string The page size set method on the request object
137 */
138 public function getRequestPageSizeSetMethod()
139 {
140 return $this->descriptor['requestPageSizeSetMethod'];
141 }
142 private static function validate(array $descriptor)
143 {
144 $requiredFields = ['requestPageTokenGetMethod', 'requestPageTokenSetMethod', 'responsePageTokenGetMethod', 'resourcesGetMethod'];
145 foreach ($requiredFields as $field) {
146 if (empty($descriptor[$field])) {
147 throw new InvalidArgumentException("{$field} is required for PageStreamingDescriptor");
148 }
149 }
150 }
151 }
152