-
-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to config AssetBundle in ViewFactory. #49
Comments
Asset bundles part is not finished so I guess it's impossible at this point. |
Hi, i have managed to put it to work but before opening a pr I want to point out some important things, and I want yours opinions about it: 1.- Yiisoft\Files\FileHelper: [add functions filterPath(), normalizeOptions(), copyDirectory()] Example: web.php:
AssetManager::class => function (ContainerInterface $container) {
$aliases = $container->get(Aliases::class);
$assetConfig = [
'appendTimestamp' => true,
'forceCopy' => true
];
$assetManager = new AssetManager($aliases);
$assetManager->setConfig($assetConfig);
return $assetManager;
},
AssetManager.php
/**
* @var array $assetManagerOptions.
*/
private $assetManagerOptions = [
'afterCopy',
'appendTimestamp',
'assetMap',
'basePath',
'baseUrl',
'beforeCopy',
'bundles',
'dirMode',
'fileMode',
'forceCopy',
'hashCallback',
'linkAssets'
];
/**
* setConfig AssetManager.
*
* @param array $config
*
* @throws \InvalidArgumentException
*
* @return void
*/
public function setConfig(array $config): void
{
foreach ($config as $key => $item) {
if (in_array($key, $this->assetManagerOptions)) {
$this->$key = $config["$key"];
} else {
throw new \InvalidArgumentException("AssetManager options: ($key) no exist.");
}
}
}
ViewFactory.php:
class ViewFactory
{
public function __invoke(ContainerInterface $container)
{
$aliases = $container->get(Aliases::class);
$assetManager = $container->get(AssetManager::class);
$eventDispatcher = $container->get(EventDispatcherInterface::class);
$logger = $container->get(LoggerInterface::class);
$theme = $container->get(Theme::class);
$view = $aliases->get('@views');
$webView = new WebView($view, $theme, $eventDispatcher, $logger);
$webView->setAssetManager($assetManager);
return $webView;
}
} |
AssetManager::class => [
'__class' => AssetManager::class,
'__construct()' => [Reference::to(Aliases::class)],
'appendTimestamp()' => [true],
'forceCopy()' => [true],
], |
Hi, (2): It is correct we do not have access to server request or router, but we need some basic things such as checking a url is relative, absolute, gethostinfo, many of them can be done with $ _REQUEST and $_SERVER, it would be good not to access them directly in views or controllers, these are basic things that I think can be offered, as was done with Method::POST, Method::GET. (3) With respect to the three if it is better to use simple setters and getters, and change the properties to private. |
|
I've been reviewing the issues in Yii2 and beforeCopy is only used to avoid empty directories, because they don't use the option [only] that only copies the files we need, the assets are full of a lot of complex logic, I think it should be simpler, that They think. public $publishOptions = [
'only' => [
'css/all.css',
'css/fontawesome.css',
'webfonts/*',
],
]; |
Yes. Could be like that. |
I have advanced a lot and I am going with the tests and I want to consult you some things. For example the position tests in the views use: public function testPositionDependency($pos, $jqAlreadyRegistered)
{
$view->getAssetManager()->bundles['TestAssetBundle'] = [
'jsOptions' => [
'position' => $pos,
],
];
} Now the propierties is private and we cannot dynamically change the behavior which seems to me to be the right thing, if you configure the position within the asset the tests work correctly, I think that to change the position dynamically it must be used. WebView->registerJsFile()
WebView->registerJCssFile() So if this will be the correct way to do it, I will modify the tests to upload the modifications. |
|
How to config AssetBundle in ViewFactory.
Thks,
The text was updated successfully, but these errors were encountered: