Completed
Pull Request — master (#1999)
by Basil
02:17
created

Asset::init()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.9666
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
namespace luya\web;
4
5
use luya\helpers\Inflector;
6
use ReflectionClass;
7
8
/**
9
 * Asset Bundles.
10
 *
11
 * The main differente to the Yii implementation is that {{$sourcePath}} has a default value which points into a `/resources` folder containing
12
 * the name of the assets itself.
13
 * 
14
 * Assuming an `MySuperAsset` asset in `/app` folder will lookup all files under `/app/resources/my-super-asset/...`.
15
 *
16
 * @author Basil Suter <[email protected]>
17
 * @since 1.0.0
18
 */
19
class Asset extends \yii\web\AssetBundle
20
{
21
    /**
22
     * @var string When $sourcePath is null, the Asset object will automaticcaly assign the current 
23
     */
24
    public $defaultSourcePathFolder = 'resources';
25
26
    public function init()
27
    {
28
        parent::init();
29
30
        if ($this->sourcePath === null) {
31
            $class = new ReflectionClass($this);
32
            $this->sourcePath = dirname($class->getFileName()) . DIRECTORY_SEPARATOR . $this->defaultSourcePathFolder . DIRECTORY_SEPARATOR . Inflector::camel2id($class->getShortName());
33
        }
34
    }
35
}
36