Completed
Push — master ( 5a29a0...22ab66 )
by Dmitry
10:00
created

AbstractPackageCommand::beforeRun()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace hiqdev\assetpackagist\commands;
4
5
use hiqdev\assetpackagist\models\AssetPackage;
6
use yii\base\Component;
7
use zhuravljov\yii\queue\Job;
8
9
abstract class AbstractPackageCommand extends Component implements Job
10
{
11
    const EVENT_BEFORE_RUN = 'beforeRun';
12
    const EVENT_AFTER_RUN = 'afterRun';
13
14
    /**
15
     * @var AssetPackage
16
     */
17
    protected $package;
18
19
    /**
20
     * Triggers event before run
21
     */
22
    public function beforeRun()
23
    {
24
        $this->trigger(self::EVENT_BEFORE_RUN);
25
    }
26
27
    /**
28
     * Triggers event after run
29
     */
30
    public function afterRun()
31
    {
32
        $this->trigger(self::EVENT_AFTER_RUN);
33
    }
34
35
    /**
36
     * CollectDependenciesCommand constructor.
37
     * @param AssetPackage $package
38
     * @param array $config
39
     */
40
    public function __construct(AssetPackage $package, $config = [])
41
    {
42
        parent::__construct($config);
43
44
        $this->package = $package;
45
    }
46
47
    /**
48
     * Reloads package on wake up to ensure it is up to date
49
     *
50
     * @void
51
     */
52
    public function __wakeup()
53
    {
54
        $this->package->load();
55
    }
56
57
    /**
58
     * @return AssetPackage
59
     */
60
    public function getPackage()
61
    {
62
        return $this->package;
63
    }
64
}
65