Skip to content

Commit 36b8faa

Browse files
authored
Use namespaces from apiclient 2.8 (#57)
* PHP8 version bumps Bump min google/apiclient for php 8 support Drops support for Laravel below 6.0 Update date travis coverage * Use Namespaced Google Services over underscore * StyleCi * Readme updates
1 parent 5662f12 commit 36b8faa

File tree

5 files changed

+48
-38
lines changed

5 files changed

+48
-38
lines changed

.travis.yml

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,6 @@ cache:
77
matrix:
88
fast_finish: true
99
include:
10-
- php: 7.2
11-
env: LARAVEL='5.8.*' COMPOSER_FLAGS='--prefer-lowest'
12-
- php: 7.2
13-
env: LARAVEL='5.8.*' COMPOSER_FLAGS='--prefer-stable'
14-
- php: 7.3
15-
env: LARAVEL='5.8.*' COMPOSER_FLAGS='--prefer-lowest'
16-
- php: 7.3
17-
env: LARAVEL='5.8.*' COMPOSER_FLAGS='--prefer-stable'
18-
- php: 7.4
19-
env: LARAVEL='5.8.*' COMPOSER_FLAGS='--prefer-lowest'
20-
- php: 7.4
21-
env: LARAVEL='5.8.*' COMPOSER_FLAGS='--prefer-stable'
2210
- php: 7.2
2311
env: LARAVEL='6.*' COMPOSER_FLAGS='--prefer-lowest'
2412
- php: 7.2
@@ -31,6 +19,10 @@ matrix:
3119
env: LARAVEL='6.*' COMPOSER_FLAGS='--prefer-lowest'
3220
- php: 7.4
3321
env: LARAVEL='6.*' COMPOSER_FLAGS='--prefer-stable'
22+
- php: 8.0
23+
env: LARAVEL='6.*' COMPOSER_FLAGS='--prefer-lowest'
24+
- php: 8.0
25+
env: LARAVEL='6.*' COMPOSER_FLAGS='--prefer-stable'
3426
- php: 7.2
3527
env: LARAVEL='7.*' COMPOSER_FLAGS='--prefer-lowest'
3628
- php: 7.2
@@ -43,6 +35,26 @@ matrix:
4335
env: LARAVEL='7.*' COMPOSER_FLAGS='--prefer-lowest'
4436
- php: 7.4
4537
env: LARAVEL='7.*' COMPOSER_FLAGS='--prefer-stable'
38+
- php: 8.0
39+
env: LARAVEL='7.*' COMPOSER_FLAGS='--prefer-lowest'
40+
- php: 8.0
41+
env: LARAVEL='7.*' COMPOSER_FLAGS='--prefer-stable'
42+
- php: 7.2
43+
env: LARAVEL='8.*' COMPOSER_FLAGS='--prefer-lowest'
44+
- php: 7.2
45+
env: LARAVEL='8.*' COMPOSER_FLAGS='--prefer-stable'
46+
- php: 7.3
47+
env: LARAVEL='8.*' COMPOSER_FLAGS='--prefer-lowest'
48+
- php: 7.3
49+
env: LARAVEL='8.*' COMPOSER_FLAGS='--prefer-stable'
50+
- php: 7.4
51+
env: LARAVEL='8.*' COMPOSER_FLAGS='--prefer-lowest'
52+
- php: 7.4
53+
env: LARAVEL='8.*' COMPOSER_FLAGS='--prefer-stable'
54+
- php: 8.0
55+
env: LARAVEL='8.*' COMPOSER_FLAGS='--prefer-lowest'
56+
- php: 8.0
57+
env: LARAVEL='8.*' COMPOSER_FLAGS='--prefer-stable'
4658

4759
before_install:
4860
- travis_retry composer self-update

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ Finally run `php artisan vendor:publish --provider="PulkitJalan\Google\GoogleSer
4141

4242
#### Using an older version of PHP / Laravel?
4343

44-
If you are on a PHP version below 7.2 or a Laravel version below 5.8 just use an older version of this package.
44+
If you are on a PHP version below 7.2 or a Laravel version below 6.0 just use an older version of this package.
4545

4646
## Usage
4747

@@ -114,7 +114,7 @@ From [Google's upgrading document](https://github.com/google/google-api-php-clie
114114
> Note: P12s are deprecated in favor of service account JSON, which can be generated in the Credentials section of Google Developer Console.
115115
116116

117-
Get `Google_Client`
117+
Get `Google\Client`
118118
```php
119119
$client = new PulkitJalan\Google\Client($config);
120120
$googleClient = $client->getClient();
@@ -129,7 +129,7 @@ Get a service
129129
```php
130130
$client = new PulkitJalan\Google\Client($config);
131131

132-
// returns instance of \Google_Service_Storage
132+
// returns instance of \Google\Service\Storage
133133
$storage = $client->make('storage');
134134

135135
// list buckets example
@@ -141,7 +141,7 @@ $storage->objects->get('bucket', 'object');
141141

142142
Laravel Example:
143143
```php
144-
// returns instance of \Google_Service_Storage
144+
// returns instance of \Google\Service\Storage
145145
$storage = Google::make('storage');
146146

147147
// list buckets example

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
],
1616
"require": {
1717
"php": "^7.2|^8.0",
18-
"illuminate/support": "^5.8|^6.0|^7.0|^8.0",
19-
"google/apiclient": "^2.4"
18+
"illuminate/support": "^6.0|^7.0|^8.0",
19+
"google/apiclient": "^2.9"
2020
},
2121
"require-dev": {
22-
"phpunit/phpunit": "^8.3",
22+
"phpunit/phpunit": "^9.3",
2323
"mockery/mockery": "^1.2.3"
2424
},
2525
"autoload": {

src/Client.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
namespace PulkitJalan\Google;
44

5-
use Google_Client;
65
use Illuminate\Support\Arr;
6+
use Google\Client as GoogleClient;
77
use PulkitJalan\Google\Exceptions\UnknownServiceException;
88

99
class Client
@@ -14,20 +14,20 @@ class Client
1414
protected $config;
1515

1616
/**
17-
* @var \Google_Client
17+
* @var Google\Client
1818
*/
1919
protected $client;
2020

2121
/**
22-
* @param array $config
23-
* @param string $userEmail
22+
* @param array $config
23+
* @param string $userEmail
2424
*/
2525
public function __construct(array $config, $userEmail = '')
2626
{
2727
$this->config = $config;
2828

2929
// create an instance of the google client for OAuth2
30-
$this->client = new Google_Client(Arr::get($config, 'config', []));
30+
$this->client = new GoogleClient(Arr::get($config, 'config', []));
3131

3232
// set application name
3333
$this->client->setApplicationName(Arr::get($config, 'application_name', ''));
@@ -52,7 +52,7 @@ public function __construct(array $config, $userEmail = '')
5252
/**
5353
* Getter for the google client.
5454
*
55-
* @return \Google_Client
55+
* @return Google\Client
5656
*/
5757
public function getClient()
5858
{
@@ -62,11 +62,10 @@ public function getClient()
6262
/**
6363
* Setter for the google client.
6464
*
65-
* @param string $client
66-
*
65+
* @param string $client
6766
* @return self
6867
*/
69-
public function setClient(Google_Client $client)
68+
public function setClient(GoogleClient $client)
7069
{
7170
$this->client = $client;
7271

@@ -76,15 +75,14 @@ public function setClient(Google_Client $client)
7675
/**
7776
* Getter for the google service.
7877
*
79-
* @param string $service
78+
* @param string $service
79+
* @return \Google_Service
8080
*
8181
* @throws \Exception
82-
*
83-
* @return \Google_Service
8482
*/
8583
public function make($service)
8684
{
87-
$service = 'Google_Service_'.ucfirst($service);
85+
$service = 'Google\\Service\\'.ucfirst($service);
8886

8987
if (class_exists($service)) {
9088
$class = new \ReflectionClass($service);
@@ -114,6 +112,7 @@ protected function auth($userEmail = '')
114112

115113
/**
116114
* Determine and use credentials if user has set them.
115+
*
117116
* @param $userEmail
118117
* @return bool used or not
119118
*/
@@ -137,12 +136,11 @@ protected function useAssertCredentials($userEmail = '')
137136
/**
138137
* Magic call method.
139138
*
140-
* @param string $method
141-
* @param array $parameters
139+
* @param string $method
140+
* @param array $parameters
141+
* @return mixed
142142
*
143143
* @throws \BadMethodCallException
144-
*
145-
* @return mixed
146144
*/
147145
public function __call($method, $parameters)
148146
{

tests/ClientTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function testClientGetter()
1616
{
1717
$client = Mockery::mock('PulkitJalan\Google\Client', [[]])->makePartial();
1818

19-
$this->assertInstanceOf('Google_Client', $client->getClient());
19+
$this->assertInstanceOf('Google\Client', $client->getClient());
2020
}
2121

2222
public function testClientGetterWithAdditionalConfig()
@@ -34,7 +34,7 @@ public function testServiceMake()
3434
{
3535
$client = Mockery::mock('PulkitJalan\Google\Client', [[]])->makePartial();
3636

37-
$this->assertInstanceOf('Google_Service_Storage', $client->make('storage'));
37+
$this->assertInstanceOf('Google\Service\Storage', $client->make('storage'));
3838
}
3939

4040
public function testServiceMakeException()

0 commit comments

Comments
 (0)