Skip to content
This repository was archived by the owner on Aug 12, 2024. It is now read-only.

Commit e40db09

Browse files
authored
Merge pull request #16 from moonbaselabs/master
Add null & log drivers
2 parents 6bef9bf + d7e866e commit e40db09

File tree

4 files changed

+68
-29
lines changed

4 files changed

+68
-29
lines changed

config/zendesk-laravel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22
return [
3+
'driver' => env('ZENDESK_DRIVER', 'api'),
34
'subdomain' => env('ZENDESK_SUBDOMAIN',null),
45
'username' => env('ZENDESK_USERNAME',null),
56
'token' => env('ZENDESK_TOKEN',null)

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ The username for the authenticating account.
6363

6464
The API access token. You can create one at: `https://SUBDOMAIN.zendesk.com/agent/admin/api/settings`
6565

66+
- `ZENDESK_DRIVER` _(Optional)_
67+
68+
Set this to `null` or `log` to prevent calling the Zendesk API directly from your environment.
69+
6670
## Usage
6771

6872
### Facade
Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
<?php namespace Huddle\Zendesk\Providers;
22

3+
use Huddle\Zendesk\Services\NullService;
34
use Huddle\Zendesk\Services\ZendeskService;
4-
use Zendesk;
55
use Illuminate\Support\ServiceProvider;
66

77
class ZendeskServiceProvider extends ServiceProvider {
88

9-
/**
10-
* Indicates if loading of the provider is deferred.
11-
*
12-
* @var bool
13-
*/
14-
protected $defer = false;
15-
16-
/**
17-
* Register the service provider and merge config.
18-
*
19-
* @return void
20-
*/
21-
public function register() {
22-
$packageName = 'zendesk-laravel';
23-
$configPath = __DIR__.'/../../config/zendesk-laravel.php';
9+
/**
10+
* Indicates if loading of the provider is deferred.
11+
*
12+
* @var bool
13+
*/
14+
protected $defer = false;
15+
16+
/**
17+
* Register the service provider and merge config.
18+
*
19+
* @return void
20+
*/
21+
public function register()
22+
{
23+
$packageName = 'zendesk-laravel';
24+
$configPath = __DIR__.'/../../config/zendesk-laravel.php';
2425

2526
$this->mergeConfigFrom(
2627
$configPath, $packageName
@@ -29,16 +30,22 @@ public function register() {
2930
$this->publishes([
3031
$configPath => config_path(sprintf('%s.php', $packageName)),
3132
]);
32-
}
33-
34-
/**
35-
* Bind service to 'zendesk' for use with Facade
36-
*
37-
* @return void
38-
*/
39-
public function boot()
40-
{
41-
$this->app->bind('zendesk', ZendeskService::class);
42-
}
43-
44-
}
33+
}
34+
35+
/**
36+
* Bind service to 'zendesk' for use with Facade.
37+
*
38+
* @return void
39+
*/
40+
public function boot()
41+
{
42+
$this->app->bind('zendesk', function () {
43+
$driver = config('zendesk-laravel.driver', 'api');
44+
if (is_null($driver) || $driver === 'log') {
45+
return new NullService($driver === 'log');
46+
}
47+
48+
return new ZendeskService;
49+
});
50+
}
51+
}

src/Services/NullService.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php namespace Huddle\Zendesk\Services;
2+
3+
use Illuminate\Support\Facades\Log;
4+
5+
class NullService {
6+
7+
/**
8+
* @var bool
9+
*/
10+
private $logCalls;
11+
12+
public function __construct(bool $logCalls = false)
13+
{
14+
$this->logCalls = $logCalls;
15+
}
16+
17+
public function __call($name, $arguments)
18+
{
19+
if ($this->logCalls) {
20+
Log::debug('Called Huddle Zendesk facade method: '.$name.' with:', $arguments);
21+
22+
return new self;
23+
}
24+
25+
return $this;
26+
}
27+
}

0 commit comments

Comments
 (0)