18
18
19
19
use Aws \Common \Aws ;
20
20
use Aws \Common \Client \UserAgentListener ;
21
- use Aws \Common \Exception \RuntimeException ;
22
21
use Guzzle \Common \Event ;
23
22
use Guzzle \Service \Client ;
24
- use Illuminate \Support \ServiceProvider ;
25
23
use Illuminate \Foundation \Application ;
24
+ use Illuminate \Support \ServiceProvider ;
26
25
27
26
/**
28
27
* AWS SDK for PHP service provider for Laravel applications
@@ -36,15 +35,19 @@ public function register()
36
35
{
37
36
$ this ->app ['aws ' ] = $ this ->app ->share (function ($ app ) {
38
37
// Instantiate the AWS service builder
39
- $ config = isset ($ app ['config ' ][ ' aws ' ]) ? $ app ['config ' ]['aws ' ] : array ();
38
+ $ config = ( isset ($ app ['config ' ]) && isset ( $ app [ ' config ' ][ ' aws ' ]) ) ? $ app ['config ' ]['aws ' ] : array ();
40
39
$ aws = Aws::factory ($ config );
41
40
42
41
// Attach an event listener that will append the Laravel version number in the user agent string
43
42
$ aws ->getEventDispatcher ()->addListener ('service_builder.create_client ' , function (Event $ event ) {
43
+ // The version number is only available in BETA4+, so an extra check is needed
44
+ $ version = defined ('Illuminate\Foundation\Application::VERSION ' ) ? Application::VERSION : '4.0.0 ' ;
45
+
46
+ // Add the listener to modify the UA string
44
47
$ clientConfig = $ event ['client ' ]->getConfig ();
45
48
$ commandParams = $ clientConfig ->get (Client::COMMAND_PARAMS ) ?: array ();
46
49
$ clientConfig ->set (Client::COMMAND_PARAMS , array_merge_recursive ($ commandParams , array (
47
- UserAgentListener::OPTION => ' Laravel ' . ( defined ( ' Application::VERSION ' ) ? ' / ' . Application:: VERSION : '' ) ,
50
+ UserAgentListener::OPTION => " Laravel/ { $ version }" ,
48
51
)));
49
52
});
50
53
0 commit comments