1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* @package cellcote/laravel-proxify |
5
|
|
|
* @author Michele Andreoli <michi.andreoli[at]gmail.com> |
6
|
|
|
* @copyright Copyright (c) Michele Andreoli |
7
|
|
|
* @author Rik Schreurs <rik.schreurs[at]mail.com> |
8
|
|
|
* @copyright Copyright (c) Rik Schreurs |
9
|
|
|
* @license http://mit-license.org/ |
10
|
|
|
* @link https://github.com/cellcote/laravel-proxify |
11
|
|
|
*/ |
12
|
|
|
|
13
|
|
|
namespace Cellcote\LaravelProxify; |
14
|
|
|
|
15
|
|
|
use Illuminate\Support\ServiceProvider; |
16
|
|
|
use Illuminate\Http\JsonResponse; |
17
|
|
|
use Cellcote\LaravelProxify\Exceptions\ProxyException; |
18
|
|
|
|
19
|
|
|
class ApiProxyServiceProvider extends ServiceProvider { |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* Indicates if loading of the provider is deferred. |
23
|
|
|
* |
24
|
|
|
* @var bool |
25
|
|
|
*/ |
26
|
|
|
protected $defer = false; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Bootstrap the application events. |
30
|
|
|
* |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
|
|
public function boot() { |
34
|
|
|
$this->publishes([ |
35
|
|
|
__DIR__ . '/config/proxy.php' => config_path('proxy.php'), |
36
|
|
|
]); |
37
|
|
|
|
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Register the service provider. |
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
public function register() { |
46
|
|
|
//$this->registerErrorHandlers(); |
47
|
|
|
$this->registerApiProxy(); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Register ApiProxy with the IoC container |
52
|
|
|
* @return void |
53
|
|
|
*/ |
54
|
|
|
public function registerApiProxy() { |
55
|
|
|
$this->app->bindShared('api-proxy.proxy', function($app) { |
|
|
|
|
56
|
|
|
$params = $app['config']['proxy']; |
57
|
|
|
$proxy = new Proxy($params); |
58
|
|
|
return $proxy; |
59
|
|
|
}); |
60
|
|
|
|
61
|
|
|
$this->app->bind('Cellcote\LaravelProxify\Proxy', function($app) { |
62
|
|
|
return $app['api-proxy.proxy']; |
63
|
|
|
}); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Get the services provided by the provider. |
68
|
|
|
* |
69
|
|
|
* @return string[] |
70
|
|
|
*/ |
71
|
|
|
public function provides() { |
72
|
|
|
return array('api-proxy.proxy'); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Register the ApiProxy error handlers |
77
|
|
|
* @return void |
78
|
|
|
*/ |
79
|
|
|
private function registerErrorHandlers() { |
80
|
|
|
$this->app->error(function(ProxyException $ex) { |
|
|
|
|
81
|
|
|
if (\Request::ajax() && \Request::wantsJson()) { |
82
|
|
|
return new JsonResponse([ |
83
|
|
|
'error' => $ex->errorType, |
84
|
|
|
'error_description' => $ex->getMessage() |
85
|
|
|
], $ex->httpStatusCode, $ex->getHttpHeaders() |
86
|
|
|
); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return \View::make('api-proxy-laravel::proxy_error', array( |
90
|
|
|
'header' => $ex->getHttpHeaders()[0], |
91
|
|
|
'code' => $ex->httpStatusCode, |
92
|
|
|
'error' => $ex->errorType, |
93
|
|
|
'message' => $ex->getMessage() |
94
|
|
|
)); |
95
|
|
|
}); |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
} |
99
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.