forked from yiisoft/yii2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
99 additions
and
53 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 |
---|---|---|
@@ -1,29 +1,29 @@ | ||
{ | ||
"name": "yiisoft/yii2-bootstrap", | ||
"description": "The Twitter Bootstrap extension for the Yii framework", | ||
"keywords": ["yii2", "bootstrap"], | ||
"type": "yii2-extension", | ||
"license": "BSD-3-Clause", | ||
"support": { | ||
"issues": "https://github.com/yiisoft/yii2/issues?labels=ext%3Abootstrap", | ||
"forum": "http:https://www.yiiframework.com/forum/", | ||
"wiki": "http:https://www.yiiframework.com/wiki/", | ||
"irc": "irc:https://irc.freenode.net/yii", | ||
"source": "https://github.com/yiisoft/yii2" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Qiang Xue", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"yiisoft/yii2": "*", | ||
"twbs/bootstrap": "3.2.* | 3.1.* | 3.0.*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"yii\\bootstrap\\": "" | ||
} | ||
} | ||
"name": "yiisoft/yii2-bootstrap", | ||
"description": "The Twitter Bootstrap extension for the Yii framework", | ||
"keywords": ["yii2", "bootstrap"], | ||
"type": "yii2-extension", | ||
"license": "BSD-3-Clause", | ||
"support": { | ||
"issues": "https://github.com/yiisoft/yii2/issues?labels=ext%3Abootstrap", | ||
"forum": "http:https://www.yiiframework.com/forum/", | ||
"wiki": "http:https://www.yiiframework.com/wiki/", | ||
"irc": "irc:https://irc.freenode.net/yii", | ||
"source": "https://github.com/yiisoft/yii2" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Qiang Xue", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"yiisoft/yii2": "*", | ||
"twbs/bootstrap": "3.2.* | 3.1.* | 3.0.*" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"yii\\bootstrap\\": "" | ||
} | ||
} | ||
} |
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
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 |
---|---|---|
|
@@ -10,42 +10,44 @@ | |
use Yii; | ||
use yii\base\Component; | ||
use yii\base\InvalidConfigException; | ||
use yii\base\InvalidParamException; | ||
use yii\helpers\FileHelper; | ||
use yii\helpers\Url; | ||
|
||
/** | ||
* AssetManager manages asset bundles and asset publishing. | ||
* AssetManager manages asset bundle configuration and loading. | ||
* | ||
* AssetManager is configured as an application component in [[\yii\web\Application]] by default. | ||
* You can access that instance via `Yii::$app->assetManager`. | ||
* | ||
* You can modify its configuration by adding an array to your application config under `components` | ||
* as it is shown in the following example: | ||
* as shown in the following example: | ||
* | ||
* ~~~ | ||
* ```php | ||
* 'assetManager' => [ | ||
* 'bundles' => [ | ||
* // you can override AssetBundle configs here | ||
* ], | ||
* //'linkAssets' => true, | ||
* // ... | ||
* ] | ||
* ~~~ | ||
* | ||
* @property AssetConverterInterface $converter The asset converter. Note that the type of this property | ||
* differs in getter and setter. See [[getConverter()]] and [[setConverter()]] for details. | ||
* ``` | ||
* | ||
* @author Qiang Xue <[email protected]> | ||
* @since 2.0 | ||
*/ | ||
class AssetManager extends Component | ||
{ | ||
/** | ||
* @var array list of available asset bundles. The keys are the class names (**without leading backslash**) | ||
* of the asset bundles, and the values are either the configuration arrays for creating the [[AssetBundle]] | ||
* objects or the corresponding asset bundle instances. For example, the following code disables | ||
* the bootstrap css file used by Bootstrap widgets (because you want to use your own styles): | ||
* @var array|boolean list of asset bundle configurations. This property is provided to customize asset bundles. | ||
* When a bundle is being loaded by [[getBundle()]], if it has a corresponding configuration specified here, | ||
* the configuration will be applied to the bundle. | ||
* | ||
* The array keys are the asset bundle names, which typically are asset bundle class names without leading backslash. | ||
* The array values are the corresponding configurations. If a value is false, it means the corresponding asset | ||
* bundle is disabled and [[getBundle()]] should return null. | ||
* | ||
* If this this property is false, it means the whole asset bundle feature is disabled and [[getBundle()]] | ||
* will always return null. | ||
* | ||
* The following example shows how to disable the bootstrap css file used by Bootstrap widgets | ||
* (because you want to use your own styles): | ||
* | ||
* ~~~ | ||
* [ | ||
|
@@ -64,8 +66,25 @@ class AssetManager extends Component | |
* @return string the base URL through which the published asset files can be accessed. | ||
*/ | ||
public $baseUrl = '@web/assets'; | ||
/** | ||
* @var array mapping from source asset files (keys) to target asset files (values). | ||
* When an asset bundle is being loaded by [[getBundle()]], each of its asset files (listed in either | ||
* [[AssetBundle::css]] or [[AssetBundle::js]] will be examined to see if it matches any key | ||
* in this map. If so, the corresponding value will be used to replace the asset file. | ||
* | ||
* Note that the target asset files should be either absolute URLs or paths relative to [[baseUrl]] and [[basePath]]. | ||
* | ||
* In the following example, any occurrence of `jquery.min.js` will be replaced with `jquery/dist/jquery.js`. | ||
* | ||
* ```php | ||
* [ | ||
* 'jquery.min.js' => 'jquery/dist/jquery.js', | ||
* ] | ||
* ``` | ||
*/ | ||
public $assetMap = []; | ||
|
||
|
||
/** | ||
* Initializes the component. | ||
* @throws InvalidConfigException if [[basePath]] is invalid | ||
|
@@ -140,12 +159,33 @@ public function registerAssetFiles($view, $bundle) | |
|
||
protected function getAssetUrl($bundle, $file) | ||
{ | ||
if (($mappedFile = $this->mapAsset($file)) !== false) { | ||
return Url::isRelative($mappedFile) ? $this->baseUrl . '/' . $mappedFile : $mappedFile; | ||
} | ||
|
||
if (strncmp($file, '@/', 2) === 0) { | ||
$file = $this->baseUrl . substr($file, 1); | ||
} elseif (Url::isRelative($file)) { | ||
$file = $bundle->baseUrl . '/' . $file; | ||
} | ||
// todo: assetMap | ||
|
||
return $file; | ||
} | ||
|
||
protected function mapAsset($file) | ||
{ | ||
if (isset($this->assetMap[$file])) { | ||
return $this->assetMap[$file]; | ||
} | ||
|
||
$n = strlen($file); | ||
foreach ($this->assetMap as $from => $to) { | ||
$n2 = strlen($from); | ||
if ($n2 <= $n && substr_compare($file, $from, $n - $n2, $n2) === 0) { | ||
return $to; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
} |