This repository has been archived by the owner on Jul 27, 2023. It is now read-only.
/
AbstractComponent.php
72 lines (63 loc) · 1.65 KB
/
AbstractComponent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/*
* This file is part of the 2amigos/yii2-google-places-library project.
*
* (c) 2amigOS! <http://2amigos.us/>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace dosamigos\google\places;
use Da\Google\Places\Client\AbstractClient;
use Da\Google\Places\Client\PlaceClient;
use Da\Google\Places\Client\SearchClient;
use yii\base\Component;
use yii\base\InvalidConfigException;
abstract class AbstractComponent extends Component
{
/**
* @var string response format. Can be json or xml.
*/
public $format = 'json';
/**
* @var string your API key
*/
public $key;
/**
* @var return json results as arrays instead of objects
*/
public $forceJsonArrayResponse = false;
/**
* @var AbstractClient|PlaceClient|SearchClient
*/
protected $client;
/**
* Wraps PlaceClient methods.
*
* @param string $name
* @param array $params
*
* @return mixed
*/
public function __call($name, $params)
{
if (method_exists($this->getClient(), $name)) {
return call_user_func_array([$this->getClient(), $name], $params);
}
return parent::__call($name, $params);
}
/**
* @throws InvalidConfigException
*/
public function init()
{
if (empty($this->key) || empty($this->format)) {
throw new InvalidConfigException('"key" and/or "format" cannot be empty.');
}
parent::init();
}
/**
* @return AbstractClient|PlaceClient|SearchClient
*/
abstract public function getClient();
}