1<?php
2/*
3 * Copyright 2010 Google Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 *     http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18namespace Google;
19
20use Google\Http\Batch;
21use TypeError;
22
23class Service
24{
25  public $batchPath;
26  public $rootUrl;
27  public $version;
28  public $servicePath;
29  public $availableScopes;
30  public $resource;
31  private $client;
32
33  public function __construct($clientOrConfig = [])
34  {
35    if ($clientOrConfig instanceof Client) {
36      $this->client = $clientOrConfig;
37    } elseif (is_array($clientOrConfig)) {
38      $this->client = new Client($clientOrConfig ?: []);
39    } else {
40      $errorMessage = 'constructor must be array or instance of Google\Client';
41      if (class_exists('TypeError')) {
42        throw new TypeError($errorMessage);
43      }
44      trigger_error($errorMessage, E_USER_ERROR);
45    }
46  }
47
48  /**
49   * Return the associated Google\Client class.
50   * @return \Google\Client
51   */
52  public function getClient()
53  {
54    return $this->client;
55  }
56
57  /**
58   * Create a new HTTP Batch handler for this service
59   *
60   * @return Batch
61   */
62  public function createBatch()
63  {
64    return new Batch(
65        $this->client,
66        false,
67        $this->rootUrl,
68        $this->batchPath
69    );
70  }
71}
72