Skip to content

Commit

Permalink
remove duplicating code
Browse files Browse the repository at this point in the history
  • Loading branch information
RC4347 committed Dec 2, 2022
1 parent f907779 commit d3a2ff7
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 47 deletions.
26 changes: 5 additions & 21 deletions src/SignedCookieService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,44 +4,28 @@

use Aws\CloudFront\CloudFrontClient;
use Aws\Exception\AwsException;
use RC4347\CloudFrontSigner\base\BaseService;
use RC4347\CloudFrontSigner\credentials\AccessConfig;
use RC4347\CloudFrontSigner\credentials\ClientConfig;
use RC4347\CloudFrontSigner\credentials\ExpireConfig;

class SignedCookieService
class SignedCookieService extends BaseService
{

public ?string $policy;

public ClientConfig $clientConfig;
public AccessConfig $accessConfig;
public ExpireConfig $config;

/**
* @param string|null $policy
* @param ClientConfig $clientConfig
* @param AccessConfig $accessConfig
* @param ExpireConfig $config
*/
public function __construct(ClientConfig $clientConfig, AccessConfig $accessConfig, ExpireConfig $config, ?string $policy = null)
public function __construct(ExpireConfig $config, ClientConfig $clientConfig, AccessConfig $accessConfig, ?string $policy = null)
{
parent::__construct($config, $clientConfig, $accessConfig);
$this->policy = $policy;
$this->clientConfig = $clientConfig;
$this->accessConfig = $accessConfig;
$this->config = $config;
}

/**
* @return array|string
*/
public function run()
{
$cloudFrontClient = new CloudFrontClient([
'profile' => $this->clientConfig->profile ?? 'default',
'version' => $this->clientConfig->version ?? 'latest',
'region' => $this->clientConfig->region
]);

$cloudFrontClient = $this->getClient();
return $this->getSignedCookie($cloudFrontClient);
}

Expand Down
29 changes: 3 additions & 26 deletions src/SignedUrlService.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,16 @@

use Aws\CloudFront\CloudFrontClient;
use Aws\Exception\AwsException;
use RC4347\CloudFrontSigner\credentials\AccessConfig;
use RC4347\CloudFrontSigner\credentials\ClientConfig;
use RC4347\CloudFrontSigner\credentials\ExpireConfig;
use RC4347\CloudFrontSigner\base\BaseService;

class SignedUrlService
class SignedUrlService extends BaseService
{
public ExpireConfig $config;
public ClientConfig $clientConfig;
public AccessConfig $accessConfig;

/**
* @param ExpireConfig $config
* @param ClientConfig $clientConfig
* @param AccessConfig $accessConfig
*/
public function __construct(ExpireConfig $config, ClientConfig $clientConfig, AccessConfig $accessConfig)
{
$this->config = $config;
$this->clientConfig = $clientConfig;
$this->accessConfig = $accessConfig;
}

/**
* @return string
*/
public function run(): string
{
$cloudFrontClient = new CloudFrontClient([
'profile' => $this->clientConfig->profile ?? 'default',
'version' => $this->clientConfig->version ?? 'latest',
'region' => $this->clientConfig->region
]);

$cloudFrontClient = $this->getClient();
return $this->getSignedUrl($cloudFrontClient);
}

Expand Down
38 changes: 38 additions & 0 deletions src/base/BaseService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace RC4347\CloudFrontSigner\base;

use Aws\CloudFront\CloudFrontClient;
use RC4347\CloudFrontSigner\credentials\AccessConfig;
use RC4347\CloudFrontSigner\credentials\ClientConfig;
use RC4347\CloudFrontSigner\credentials\ExpireConfig;

abstract class BaseService
{
public ExpireConfig $config;
public ClientConfig $clientConfig;
public AccessConfig $accessConfig;

/**
* @param ExpireConfig $config
* @param ClientConfig $clientConfig
* @param AccessConfig $accessConfig
*/
public function __construct(ExpireConfig $config, ClientConfig $clientConfig, AccessConfig $accessConfig)
{
$this->config = $config;
$this->clientConfig = $clientConfig;
$this->accessConfig = $accessConfig;
}

public function getClient()
{
return new CloudFrontClient([
'profile' => $this->clientConfig->profile ?? 'default',
'version' => $this->clientConfig->version ?? 'latest',
'region' => $this->clientConfig->region
]);
}

public abstract function run();
}

0 comments on commit d3a2ff7

Please sign in to comment.