1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Publiux\laravelcdn; |
4
|
|
|
|
5
|
|
|
use Publiux\laravelcdn\Contracts\AssetInterface; |
6
|
|
|
use Publiux\laravelcdn\Contracts\CdnHelperInterface; |
7
|
|
|
use Publiux\laravelcdn\Contracts\CdnInterface; |
8
|
|
|
use Publiux\laravelcdn\Contracts\FinderInterface; |
9
|
|
|
use Publiux\laravelcdn\Contracts\ProviderFactoryInterface; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class Cdn |
13
|
|
|
* Class Cdn is the manager and the main class of this package. |
14
|
|
|
* |
15
|
|
|
* @category Main Class |
16
|
|
|
* |
17
|
|
|
* @author Mahmoud Zalt <[email protected]> |
18
|
|
|
*/ |
19
|
|
|
class Cdn implements CdnInterface |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* An instance of the finder class. |
23
|
|
|
* |
24
|
|
|
* @var Contracts\ |
25
|
|
|
*/ |
26
|
|
|
protected $finder; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* The object that will hold the assets configurations |
30
|
|
|
* and the paths of the assets. |
31
|
|
|
* |
32
|
|
|
* @var Contracts\AssetInterface |
33
|
|
|
*/ |
34
|
|
|
protected $asset_holder; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* @var \Publiux\laravelcdn\Contracts\ProviderFactoryInterface |
38
|
|
|
*/ |
39
|
|
|
protected $provider_factory; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var \Publiux\laravelcdn\Contracts\CdnHelperInterface |
43
|
|
|
*/ |
44
|
|
|
protected $helper; |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param FinderInterface $finder |
48
|
|
|
* @param AssetInterface $asset_holder |
49
|
|
|
* @param ProviderFactoryInterface $provider_factory |
50
|
|
|
* @param CdnHelperInterface $helper |
51
|
|
|
* |
52
|
|
|
* @internal param \Publiux\laravelcdn\Repository $configurations |
53
|
|
|
*/ |
54
|
|
|
public function __construct( |
55
|
|
|
FinderInterface $finder, |
56
|
|
|
AssetInterface $asset_holder, |
57
|
|
|
ProviderFactoryInterface $provider_factory, |
58
|
|
|
CdnHelperInterface $helper |
59
|
|
|
) { |
60
|
|
|
$this->finder = $finder; |
61
|
|
|
$this->asset_holder = $asset_holder; |
62
|
|
|
$this->provider_factory = $provider_factory; |
63
|
|
|
$this->helper = $helper; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Will be called from the Publiux\laravelcdn\PushCommand class on Fire(). |
68
|
|
|
*/ |
69
|
|
|
public function push() |
70
|
|
|
{ |
71
|
|
|
// return the configurations from the config file |
72
|
|
|
$configurations = $this->helper->getConfigurations(); |
73
|
|
|
|
74
|
|
|
// Initialize an instance of the asset holder to read the configurations |
75
|
|
|
// then call the read(), to return all the allowed assets as a collection of files objects |
76
|
|
|
$assets = $this->finder->read($this->asset_holder->init($configurations)); |
77
|
|
|
|
78
|
|
|
// store the returned assets in the instance of the asset holder as collection of paths |
79
|
|
|
$this->asset_holder->setAssets($assets); |
80
|
|
|
|
81
|
|
|
// return an instance of the corresponding Provider concrete according to the configuration |
82
|
|
|
$provider = $this->provider_factory->create($configurations); |
83
|
|
|
|
84
|
|
|
return $provider->upload($this->asset_holder->getAssets()); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* Will be called from the Publiux\laravelcdn\EmptyCommand class on Fire(). |
89
|
|
|
*/ |
90
|
|
|
public function emptyBucket() |
91
|
|
|
{ |
92
|
|
|
// return the configurations from the config file |
93
|
|
|
$configurations = $this->helper->getConfigurations(); |
94
|
|
|
|
95
|
|
|
// return an instance of the corresponding Provider concrete according to the configuration |
96
|
|
|
$provider = $this->provider_factory->create($configurations); |
97
|
|
|
|
98
|
|
|
return $provider->emptyBucket(); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|