Skip to content

Commit

Permalink
Merge pull request #12 from vinkla/update/laravel
Browse files Browse the repository at this point in the history
Update Laravel integration
  • Loading branch information
olssonm committed Aug 12, 2024
2 parents 10556f5 + 8f9329c commit 6dfe278
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 49 deletions.
4 changes: 4 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,9 @@
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"suggest":{
"illuminate/contracts": "Required to use the Laravel integration (^10.0|^11.0).",
"illuminate/support": "Required to use the Laravel integration (^10.0|^11.0)."
}
}
File renamed without changes.
65 changes: 16 additions & 49 deletions src/Providers/SwishServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,38 @@

namespace Olssonm\Swish\Providers;

use Illuminate\Contracts\Container\Container;
use Illuminate\Support\ServiceProvider;
use Olssonm\Swish\Certificate;
use Olssonm\Swish\Client;

class SwishServiceProvider extends ServiceProvider
{
/**
* Path to config-file
*
* @var string
*/
protected $config;

/**
* Constructor
*
* @param \Illuminate\Contracts\Foundation\Application $app
* @return void
*/
public function __construct($app)
{
$this->config = __DIR__ . '/../config.php';

parent::__construct($app);
}

/**
* Register any package services.
*
* @return void
*/
public function register(): void
{
// Publishing of configuration
$this->publishes([
$this->config => config_path('swish.php'),
]);
$source = realpath($raw = __DIR__ . '/../../config/swish.php') ?: $raw;

$this->publishes([$source => config_path('swish.php')]);

// If the user doesn't set their own config, load default
$this->mergeConfigFrom(
$this->config,
'swish'
);
$this->mergeConfigFrom($source, 'swish');

$this->app->singleton('swish', function () {
$this->app->singleton('swish', function (Container $app): Client {
$certificate = new Certificate(
clientPath: config('swish.certificates.client'),
passphrase: config('swish.certificates.password'),
rootPath: config('swish.certificates.root'),
signingPath: config('swish.certificates.signing'),
signingPassphrase: config('swish.certificates.signing_password'),
clientPath: $app['config']['swish.certificates.client'],
passphrase: $app['config']['swish.certificates.password'],
rootPath: $app['config']['swish.certificates.root'],
signingPath: $app['config']['swish.certificates.signing'],
signingPassphrase: $app['config']['swish.certificates.signing_password'],
);
return new Client($certificate, config('swish.endpoint'));

return new Client($certificate, $app['config']['swish.endpoint']);
});

$this->app->bind(Client::class, 'swish');
$this->app->alias('swish', Client::class);
}

/**
* Get the services provided by the provider.
*
* @return array<string>
* @codeCoverageIgnore
*/
public function provides()
/** @codeCoverageIgnore */
public function provides(): array
{
return ['swish'];
}
Expand Down

0 comments on commit 6dfe278

Please sign in to comment.