1818
1919use Aws \Common \Aws ;
2020use Aws \Common \Client \UserAgentListener ;
21- use Aws \Common \Exception \RuntimeException ;
2221use Guzzle \Common \Event ;
2322use Guzzle \Service \Client ;
24- use Illuminate \Support \ServiceProvider ;
2523use Illuminate \Foundation \Application ;
24+ use Illuminate \Support \ServiceProvider ;
2625
2726/**
2827 * AWS SDK for PHP service provider for Laravel applications
@@ -36,15 +35,19 @@ public function register()
3635 {
3736 $ this ->app ['aws ' ] = $ this ->app ->share (function ($ app ) {
3837 // 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 ();
4039 $ aws = Aws::factory ($ config );
4140
4241 // Attach an event listener that will append the Laravel version number in the user agent string
4342 $ 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
4447 $ clientConfig = $ event ['client ' ]->getConfig ();
4548 $ commandParams = $ clientConfig ->get (Client::COMMAND_PARAMS ) ?: array ();
4649 $ clientConfig ->set (Client::COMMAND_PARAMS , array_merge_recursive ($ commandParams , array (
47- UserAgentListener::OPTION => ' Laravel ' . ( defined ( ' Application::VERSION ' ) ? ' / ' . Application:: VERSION : '' ) ,
50+ UserAgentListener::OPTION => " Laravel/ { $ version }" ,
4851 )));
4952 });
5053
0 commit comments