Skip to content

Commit

Permalink
Fixed composer compatibility (#4)
Browse files Browse the repository at this point in the history
* hash generator written in a way more compatible with all versions of composer

* removed require of composer 2.0 or greater
  • Loading branch information
RodrigoDornelles authored Aug 26, 2021
1 parent 5dd8d88 commit bff07cc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"minimum-stability": "stable",
"require": {
"php": ">=7.0",
"yiisoft/yii2": "*",
"composer/composer": ">=2.0"
"yiisoft/yii2": "*"
},
"autoload": {
"psr-4": {
Expand Down
8 changes: 4 additions & 4 deletions src/Menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace dynamikaweb\adaptive;

use Composer\InstalledVersions as Composer;
use yii\helpers\ArrayHelper;
use yii\helpers\Inflector;
use yii\helpers\Html;
Expand Down Expand Up @@ -198,9 +197,10 @@ public function renderFile($view, $params = [])
*/
public function generateHash()
{
return strtr('menu-{md5}-{version}', [
'{version}' => Composer::getVersion('dynamikaweb/yii2-adaptive-menu'),
'{md5}' => md5(json_encode($this->items)),
return strtr('menu-{hash_items}-{hash_assets}-{lastmod}', [
'{hash_assets}' => md5($this->_asset->touchTimes),
'{hash_items}' => md5(json_encode($this->items)),
'{lastmod}' => getlastmod(),
]);
}
}
20 changes: 20 additions & 0 deletions src/MenuAsset.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,28 @@ class MenuAsset extends \yii\web\AssetBundle
'script.js',
];

/**
* return file exactly patch
*
* @param string $view
* @return string
*/
public function getFile($view)
{
return "{$this->sourcePath}/{$this->files[$view]}";
}

/**
* Concat asset file modified times
*
* @return string
*/
public function getTouchTimes()
{
return implode('-', array_map(function($file) {
return filemtime($this->getFile($file));
},
array_keys($this->files)
));
}
}

0 comments on commit bff07cc

Please sign in to comment.