-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added asset bundle class with APP_ASSET_FORCE_PUBLISH option
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
namespace dmstr\web; | ||
|
||
/** | ||
* @link http://www.diemeisterei.de/ | ||
* @copyright Copyright (c) 2016 diemeisterei GmbH, Stuttgart | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
use yii\helpers\FileHelper; | ||
use yii\web\AssetBundle as BaseAssetBundle; | ||
|
||
/** | ||
* Configuration for `backend` client script files. | ||
* | ||
* @since 4.0 | ||
*/ | ||
class AssetBundle extends BaseAssetBundle | ||
{ | ||
/** | ||
* Initializes asset bundle with optional CSS/LESS development settings | ||
* | ||
* If `APP_ASSET_FORCE_PUBLISH` is set, touch the asset folder with the highest mtime | ||
* of all contained files. | ||
* This will create a new folder in web/assets for every change and request made to the app assets. | ||
*/ | ||
public function init() | ||
{ | ||
parent::init(); | ||
|
||
if (getenv('APP_ASSET_FORCE_PUBLISH')) { | ||
$path = \Yii::getAlias($this->sourcePath); | ||
$files = FileHelper::findFiles($path); | ||
$mtimes = []; | ||
foreach ($files as $file) { | ||
$mtimes[] = filemtime($file); | ||
} | ||
touch($path, max($mtimes)); | ||
} | ||
} | ||
} |