widmogrod / zf2-assetic-module Goto Github PK
View Code? Open in Web Editor NEWZend Framework module for Assetic
Zend Framework module for Assetic
Hi there,
I'd like to use minify and lessphp.
So how can i parameter your application to do the following (for example):
new FileAsset('/path/to/src/styles.less', array(new LessphpFilter())),
or
$fm->set('yui_css', new Yui\CssCompressorFilter('/path/to/yuicompressor.jar'));
David
Fatal error: Declaration of AsseticBundle\Module::init() must be compatible with that of Zend\ModuleManager\Feature\InitProviderInterface::init() in vendor\widmogrod\zf2-assetic-module\Module.php on line 14
Fatal error: Uncaught exception 'Zend\ModuleManager\Exception\RuntimeException' with message 'Module (AsseticBundle) could not be initialized
We actively use this assetic ZF2 module for the website we our building. Most of our developers run *nix systems, and we have no problems there. However we have a developer running the site on your typical WAMP (Windows + ..) installation, and he gets errors at random.
A trace of one such exception. Anyone that has similar problems or suggestions as to how we can fix these?
The line points at the file_put_contents
line of the AssetWriter.
( ! ) Fatal error: Uncaught exception 'RuntimeException' with message 'Unable to write file public/assets/jquery-ui/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png' in C:\Websites\JWV2\vendor\kriswallsmith\assetic\src\Assetic\AssetWriter.php on line 54
( ! ) RuntimeException: Unable to write file public/assets/jquery-ui/css/ui-lightness/images/ui-bg_glass_100_f6f6f6_1x400.png in C:\Websites\JWV2\vendor\kriswallsmith\assetic\src\Assetic\AssetWriter.php on line 54
Call Stack
# Time Memory Function Location
1 0.0003 248720 {main}( ) ..\index.php:0
2 1.3206 16646352 Zend\Mvc\Application->run( ) ..\index.php:17
3 1.3980 17856936 Zend\EventManager\EventManager->trigger( ) ..\Application.php:294
4 1.3980 17856936 Zend\EventManager\EventManager->triggerListeners( ) ..\EventManager.php:207
5 1.3981 17859000 call_user_func ( ) ..\EventManager.php:472
6 1.3981 17859032 AsseticBundle\Module->renderAssets( ) ..\EventManager.php:472
7 1.3981 17859576 AsseticBundle\Service->initLoadedModules( ) ..\Module.php:123
8 1.4189 18378672 Assetic\AssetWriter->writeManagerAssets( ) ..\Service.php:221
9 1.4457 18386176 Assetic\AssetWriter->writeAsset( ) ..\AssetWriter.php:38
10 1.4459 18386728 Assetic\AssetWriter::write( ) ..\AssetWriter.php:44
Hi there, how can i parameter a route named 'default/wildcard' ?
I tried this:
{code}
'default/wildcard' => array(
'@plugins_css',
'@application_css',
'@jquery'
),
'default//wildcard' => array(
'@plugins_css',
'@application_css',
'@jquery'
),
'default/wildcard' => array(
'@plugins_css',
'@application_css',
'@jquery'
),
'default\wildcard' => array(
'@plugins_css',
'@application_css',
'@jquery'
),
{code}
But none of them is working!
Regular 404s where a route is matched but there is no corresponding method to handle the route work just fine.
The case where a route can not be matched are not handled however, like:
I was able to handle this case by sort of re-implementing the renderAssets method in AsseticBundle/Listener.php but perhaps there should be some sort of configuration option to handle this case. My fix for the issue is below:
Application/Module.php
class Module
{
public function onBootstrap(MvcEvent $e)
{
$e->getApplication()->getEventManager()->attach(MvcEvent::EVENT_DISPATCH_ERROR, array($this, 'handleDispatchError'), 32);
}
public function handleDispatchError(MvcEvent $e)
{
$sm = $e->getApplication()->getServiceManager();
if ($e->getName() != MvcEvent::EVENT_DISPATCH_ERROR)
return;
$config = $sm->get('AsseticConfiguration');
if ($e->getName() === MvcEvent::EVENT_DISPATCH_ERROR) {
$error = $e->getError();
if ($error && !in_array($error, $config->getAcceptableErrors())) {
// break if not an acceptable error
return;
}
}
$response = $e->getResponse();
if (!$response) {
$response = new Response();
$e->setResponse($response);
}
$routeMatch = $e->getRouteMatch();
if ($routeMatch)
return;
/** @var $asseticService \AsseticBundle\Service */
$asseticService = $sm->get('AsseticService');
$asseticService->setRouteName('error_404');
$asseticService->setControllerName('Application\Controller\Index');
$asseticService->setActionName('error_' . uniqid());
// Create all objects
$asseticService->build();
// Init assets for modules
$asseticService->setupRenderer($sm->get('ViewRenderer'));
}
}
Snippet from module.config.php
return array(
'assetic_configuration' => array(
'debug' => true,
'buildOnRequest' => true,
'webPath' => __DIR__ . '/../../../public/assets',
'basePath' => 'assets',
'routes' => array(
'error_404' => array(
'@base_css',
'@head_home_js'
),
)
);
Hello, I think in the How to use AsseticBundle section of the README it should be written 'routes' instead of 'routers'.
Thank you for your coding! awesome ideas!
leafo/less is not listed as a requirement in readme.md and also as this is mostly just a compatablilty layer (zf2 module) for the original assetic, why is it listed in require in composer.json? is it being used?
please either remove from composer.json if it is not actually required, or update the readme.
Note: this is mentioned already in #65 by @rhysr and @aroos. But that issues contains several other ones, so this one is dedicated for this issue.
During developent the buildOnRequest
flag is obviously off. During development assets thus get moved every request. This is unnecessary and really slows things down (especially on Windows).
How hard/easy would it to tackle this issue? Any leads on how to do so?
writeManagerAssets() gets called here
https://github.com/widmogrod/zf2-assetic-> module/blob/master/src/AsseticBundle/Service.php#L221This gets run on every page request, which writes out ALL the assets to disk, even the > ones not used on this request. There is a cache which prevents complex asset compilation > reoccurring (e.g. sass, coffeescript etc), but this content still gets written out to the > webPath output location.
I've thought about this problem a bit, like checking the filemtime of the output against the > $asset->getLastModified() but i think the problem is that every page request is having to > deal with Assetic when it may not need to.
I'm experimenting with a different assetic module for zf2 to see how else this could be dealt with.
Not everyone is using lessphp.
The router names may cause collisions aplying the assets to routes where they are not supposed to be applied. The problem is in / src / AsseticBundle / Service.php
public function setRouteName($routeName)
{
$this->routeName = basename($routeName);
}
By using basename we may collide different routes. For example if we have:
admin/default
application/default
The asset's routeName will be default applying to both of them. Shouldn't this be something like:
public function setRouteName($routeName)
{
$routeName = explode('/', $routeName, 2);
$routeName = $routeName[0];
$this->routeName = basename($routeName);
}
In fact I would leave it just as:
public function setRouteName($routeName)
{
$this->routeName = basename($routeName);
}
and in function "setupRendererForRouter"... make a double check something like:
$assetOptions = $this->configuration->getRoute($this->getRouteName());
if (!$assetOptions) {
// If no assets found try the parent!
$routeName = explode('/', $this->getRouteName(),2);
$routeName = $routeName[0];
$assetOptions = $this->configuration->getRoute($this->getRouteName());
if (!$assetOptions) {
return false;
}
}
Hi ! I've started to use your module yesterday. I think it's quite awesome (the only question I'm curious about is how does it work if there are two files with the same name in two different modules...)
My sole problem at the moment is that your module is not going into vendor/ part of my architecture and is not updatable/installable using "php composer.phar" command.
Is there a way to do so ?
I have a problem when using the mixins option (mixins => true). The common assets like jquery.js are included after route specific asstes. I thought the using mixins option I could avoid colleciton repetitions in all modules but since default assets are included last it makes other assets generate javascript errors when they are using code from default assets. E.g. my module have its one js which uses jquery library a thus should be included after it. I think the order should be reversed- common assets first, specific assets last - perhaps by using an config option in order not to break the old behaviour. It would also work better for css - global (default) css would be defined first and then overriden by module specific ones.
I want to use the CoffeeScriptFilter, which requires /usr/bin/node.
As I am using MacPorts node resides in /opt/local/bin/.
RuntimeException: sh: /usr/bin/node: No such file or directory in /Users/hr/Sites/project/vendor/kriswallsmith/assetic/src/Assetic/Filter/CoffeeScriptFilter.php on line 51
Fatal error: Call to undefined method Zend\ModuleManager\ModuleManager::events() in module\AsseticBundle\Module.php
When you've defined several collections with the same filter alias, only the first collection gets the filter assigned.
Example:
'collections' => [
'base_css' => [
'assets' => [
'base/css/*.scss'
],
'filters' => ['scss' => ['name' => 'Assetic\\Filter\\ScssphpFilter']],
'options' => ['output' => 'cached/base_css.css'],
],
'global_css' => [
'assets' => [
'global/css/*.scss'
],
'filters' => ['scss' => ['name' => 'Assetic\\Filter\\ScssphpFilter']],
'options' => ['output' => 'cached/global_css.css'],
],
The second file (global.css) doesn't get filtered by SCSS.
This comes from a logical error in AsseticBundle/Service.php. Please see my forthcoming pull request.
Timestamps are always appended to URIs, regardless of settings such as cache=true.
I haven't checked other browsers, but Firefox seems to always fetch a resource again if it has a query string, even if that query string hasn't changed (I see lots of '200 OK' instead of '304 Not Modified'). Consequently client-side caching is always disabled, even when it is desirable (e.g. when fetching jQuery from a CDN).
Perhaps the timestamp should be included in the file name instead of as a query string appended to the URI...?
I have a problem while trying to inject my module's assets inside the default assets
return array(
'view_manager' => array(
'template_path_stack' => array(
'extendedzenddevelopertools' => __DIR__ . '/../view'
)
),
'assetic_configuration' => array(
'default' => array(
'assets' => array(
'@ExtendedZendDeveloperToolsJs',
'@ExtendedZendDeveloperToolsCss',
)
),
'modules' => array(
'ExtendedZendDeveloperTools' => array(
'root_path' => __DIR__ . '/../assets',
'collections' => array(
'ExtendedZendDeveloperToolsJs' => array(
'assets' => array(
'js/ref.js',
),
'filters' => array(
'?JSMinFilter' => array(
'name' => 'Assetic\Filter\JSMinFilter'
),
),
'options' => array(
'move_raw' => true,
),
),
'ExtendedZendDeveloperToolsCss' => array(
'assets' => array(
'css/ref.css',
),
'filters' => array(
'?CssImportFilter' => array(
'name' => 'Assetic\Filter\CssImportFilter',
),
'?CssRewriteFilter' => array(
'name' => 'Assetic\Filter\CssRewriteFilter',
),
),
),
)
)
)
)
);
While this code is under vendor, and it adds the ExtendedZendDeveloperToolsCss
inside the base_css, it doesnt work the same for the ExtendedZendDeveloperToolsJs
and i have no idea what is wrong.
Any idea ?
In the new version of this repository only assets are build during a request that are actually referenced in the assetic configuration.
This leads to problems in our application. We have a few files that need to be copied to the assets directory but are never mentioned in the assetic configuration for a request. For example our @bootstrap_js
collection.
How can we make sure that ALL assets are (possibly, if not already present) build and copied in an request?
Thanks.
Thank your for your last merge of regex routes, this PR was really helpful.
We are now facing another problem: when the order of the defined assets is incorrect, an exception in thrown. An example:
'a_css' => array(
'assets' => array(
'@b_css'
)
),
'b_css' => array(
'assets' => array(
'b.css'
)
)
This example throws an exception 'InvalidArgumentException' with message 'There is no "b_css" asset.
.
This example however should be valid as no circular dependency is defined. Is there an easy fix for this problem?
I cant get this to work with the ZendSkeletonApplication installation. I get a server 500 error.
Assetic\Filter\YUI\JsCompressorFilter is returning the following: Unable to access jarfile
Assetic\Exception\FilterException: An error occurred while running: "java" "-jar" "" "-o" "C:\WINDOWS\Temp\YUIB083.tmp" "--type" "js" "C:\WINDOWS\Temp\YUIB053.tmp" Error Output: Error: Unable to access jarfile Input: bladie bladie a-lot-of-javascript
I have the Symfony core library loaded and everything, installed Java JRE7, and now I have tried to put yuicompressor\yuicompressor.jar all over the place. And even hardcoded yuicompressor\yuicompressor.jar it at Assetic\Filter\Yui\BaseCompressorFilter.php like:
public function __construct($jarPath = '\yuicompressor\yuicompressor.jar', .........)
and also used absolute paths.......
Can anyone help me out?
Hi guys,
we've defined some collections in our application.
We want to create all assets during our build phase. I just discovered that AsseticBundle overwrites all the assets on every request. E.g. MyAsset.123.css exists and nothing changed, AsseticBundle overwrites it with MyAsset.123.css (same content, new timestamp).
Is this expected behaviour for AsseticBundle or a bug?
Cheers,
Alex
Current configuration is not intuitive.
In main ZF2 project configuration file module names are capitalized
return array(
'modules' => array(
'Application',
)
);
And directory name of module also capitalized
modules/Application
But in assetic_configuration module name now must be in lower case in contrast with another project configs.
return array(
'assetic_configuration' => array(
'modules' => array(
'application' => array(),
),
),
);
Dear all,
First of all, I'm really thankfull for your work on Zf2-assetic. Thank you :)
I can't figure out how to set the debug mode so that the js and css aren't combined in one file but stay file by file so that debugging is feasable.
If I set debug as true, it doesn't produce anything... Any help would be appreciated (or is it a bug ?)
We use in our project some assets with head_ in there name. For example typeahead_remote.
Is it possible to only use the head_ at the beginning of the asset name to include the asset in the headscript?
Thanks
Hi there:
I want to minify and combine 2 css files:
'plugins_css' => array(
'assets' => array(
# relative to 'root_path'
'jQuery/plugins/pretty/css/prettyPhoto.css',
'jQuery/plugins/jcrop/css/jquery.Jcrop.css'
),
'filters' => array('CssMinFilter' => array('name'=> 'Assetic\Filter\CssMinFilter')),
'options' => array('output' => 'plugins.css'),
),
Into my layout,
echo $this->headLink();
generate the following link:
But plugins.css doesn't exist.
I used to use "minify" and url were autogenerated by /min/?g=xxx.
So how does it works here ?
https://github.com/widmogrod/zf2-assetic-module/blob/master/autoload_classmap.php#L12
Must be replaced by :
'CssMin' => DIR . '/vendor/cssmin.php',
'lessc' => DIR . '/vendor/lessc.php',
'JSMin' => DIR . '/vendor/JSMin.php',
'JSMinPlus' => DIR . '/vendor/JSMinPlus.php',
I've just trying about the zf2. I prefer your assetic loading. As i was beginning without composer and downloading dependencies all works fine. As i reinstalled using composer i had to set min-stable to alpha in order to load zend developer tools. After reinstallation i receive the following notice:
Notice: Undefined index: assets in /media/sf_Workspaces/sumedia/bricks/bricks/trunk/vendor/widmogrod/zf2-assetic-module/src/AsseticBundle/Service.php on line 246
With best Regards
Sven
Hey there,
this module isn't working with the latest beta (3).
I get the following error:
( ! ) Fatal error: Uncaught exception 'Zend\Di\Exception\ClassNotFoundException' with message 'Class view could not be located in provided definitions.' in /var/www/m/muz_fe/vendor/ZendFramework/library/Zend/Di/Di.php on line 164
Any ideas how to fix this?
Thanks in advance and best regards,
Julian
Signature mismatch:
Fatal error: Declaration of AsseticBundle\CacheBuster\LastModifiedStrategy::process() must be compatible with Assetic\Factory\Worker\WorkerInterface::process (Assetic\Asset\AssetInterface $asset, Assetic\Factory\AssetFactory $factory)
The factory was added back in June FYI.
I have seen the option to add head sript by using path prefix. But I do not want to change asset file name provided by third parties e.g. jquery-1.9.js which are installed by composer or as a git submodule. It would be better to have an option in the asset configuration or use prefix of asset alias rather then path prefix e.g. @head_jquery_js
The problem occured when I added an inline script in my view script that makes use of the jquery library. jQuery is added as an asset in configuration but it is included as an inline script in the layout.phtml so scripts in a view script are included beforehand when jQuery is not defined yet.
The result looks like this:
<script> $(function() { $('#users').dataTable(); }); </script> <hr>
<footer>
<p>© 2005 - 2012 by Zend Technologies Ltd. All rights reserved.</p>
</footer>
</div> <!-- /container -->
<script type="text/javascript" src="/assets/jquery_js.js?1361047773"></script>
When I set 'basePath' and 'baseUrl' to '', both will be set to '/' during assetic initialization. The resulting URL is then something like '//myassetpath/bla.js', which is a protocol-relative URL with a hostname of 'myassetpath' which of course doesn't exist and thus the system fails.
I've worked around this by overriding 'AsseticBundle\Configuration::setBaseUrl()' to omit the trailing slash (which, strictly speaking, doesn't belong there anyway since there's the 'basePath' also):
class AsseticBundleConfigurationProxy extends AsseticConfiguration
{
/**
* Override setBaseUrl so that empty base URLs don't resolve to '/', which, in conjunction with a basepath
* of '/', results in an URL prefixed with '//' which resolves to a protocol-relative URL with a hostname
* that is really the first slug of the URL path.
*/
public function setBaseUrl($baseUrl)
{
if (null !== $baseUrl && 'auto' !== $baseUrl) {
$baseUrl = rtrim($baseUrl, '/');
}
$this->baseUrl = $baseUrl;
}
}
Thoughts?
hi,
I have followed all the instructions, but get this message. Is something wrong with my composer or?
Fatal error: Uncaught exception 'Zend\ServiceManager\Exception\ServiceNotFoundException' with message 'Zend\ServiceManager\ServiceManager::createFromInvokable: failed retrieving "asseticassetmanager(alias: Assetic\AssetManager)" via invokable class "Assetic\AssetManager"; class does not exist' in C:\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php:839 Stack trace: #0 C:\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(498): Zend\ServiceManager\ServiceManager->createFromInvokable('asseticassetman...', 'Assetic\AssetMa...') #1 C:\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php(441): Zend\ServiceManager\ServiceManager->create(Array) #2 C:\ZendSkeletonApplication\vendor\widmogrod\zf2-assetic-module\src\AsseticBundle\ServiceFactory.php(18): Zend\ServiceManager\ServiceManager->get('Assetic\AssetMa...') #3 [internal function]: AsseticBundle\ServiceFactory->cre in C:\ZendSkeletonApplication\vendor\zendframework\zendframework\library\Zend\ServiceManager\ServiceManager.php on line 839
There is a problem with the loading of different modules and their config.
Assets from the custom are not currently loaded because when initializing the Asseticbundel the loaded modules are saved to an attribute.
It would be better to query the ModuleManager::getLoadedModules() at the dispatch event.
It does not help to swap the order, because the default config will not be overwritten.
'modules' => array(
'..'
'AsseticBundle',
'Custom',
'..'
)
zf 2.0.6
We want to specify both a controller config and a router config, so that if both match the assets of these configurations are merged. However, because the router configuration is only used when the controller configuration is empty (guarded statement), no merger is possible. See here.
Is there any good reason for this behavior? If not, can you please merge the configuration of both items.
Hello,
Is it possible to do media queries with asseticbundle?
And how do I add these media tags to a stylesheet?
Thanks
Is it possible to have some filters turned on for a production environment but turned off for a development one? E.g. I would like to have scripts minified in production but not during development.
As I have seen filters are specified per collection so turning them off would require to override all the collection definitions in a separate configuration file for development e.g. assetic.local.php.
Is there another solution to this?
At first, I was happy and keen to rely on automatic injection of assets depending on the controller/action. However after some time using it, I've found it's prone to a lot of errors.
Because of the nature of zf2 mvc and modules interacting with the request flow, the injection is very fragile. For example, errors will cause the request to be handled by error controller, however the mod has already decided to use assets from the non-existent page. Another example would be any access-control modules, which deny access or forward depending on some conditions - this also confuses the mod.
The only safe way to handle this is to rely on explicit inclusion of resources. Because resources belong to the rendering/view phase, they should live there - so the perfect place would be a view helper, or resolver attached to a view helper. In any case, the inclusion must happen at rendering/view phase, not dispatch.
There's also the case of flexibility - current "matchers" only work on controller and action names. It is not possible to branch the inclusion logic inside controller and/or view script. If we had explicit inclusion then one could include any resources based on any requirements (be that in controller, layout, page view script or some listener).
Hi ive got:
Fatal error: Class 'Assetic\Filter\JSMinFilter' not found in vendor\widmogrod\zf2-assetic-module\src\AsseticBundle\Service.php on line 220
Because kriswallsmith/assetic (v1.0.3) doesn't contain this class !!!
It should require "kriswallsmith/assetic": "dev-master" wich includes these missing file
Hi there, here are 1 changes to do in Module.php:
line 28
$sharedEvents = $events->getSharedManager();
Moreover \Zend\View\Renderer doesn't exists and must be replaced by \Zend\View\Renderer\RendererInterface
into Service.php and ViewHelperSetup.php
David
This may be centered in my lack of understanding on how assetic works, but, I'm having a bit of a problem with combining assets. I posted on Stack Overflow here:
Is this a use that your module can solve?
Thanks for your big brain.
Hi,
With this new change the timestamp and extension gets appended twice:
base_1364163890.js.1364163890.js
and in addition the timestamp is getting appended to images causing them not to load.
-Nikesh
Hi there
echo $this->plugin('HeadLink');
echo $this->plugin('HeadStyle');
echo $this->plugin('HeadScript');
generate empty code!
Did i forget to do something?
In https://github.com/widmogrod/zf2-assetic-module/blob/master/src/AsseticBundle/Service.php, i think line 210 must be replaced with: "$assetOptions = $this->configuration->getRoute($this->getRouteName());"
public function setupViewHelpersForRouter(\Zend\View\PhpRenderer $view)
{
$assetOptions = $this->configuration->getController($this->getControllerName());
if (!$assetOptions) {
return false;
}
$viewSetup = new ViewHelperSetup(
$this->configuration->getBaseUrl(),
$view,
$this->getAssetManager()
);
$viewSetup->setupFromOptions($assetOptions);
return true;
}
Hi there,
Yesterday 17/05 a big change on zf2 made assetic-module not working anymore
Hi,
I can figure out how to get the view helper working.
$this->plugin('HeadScript')->appendFile($this->basePath() .'/js/sticky.js');
working only via module.config.php for managing the assets is our workflow a killer.
The basePath
configuration variable is set by zf2-assetic-module/configs/module.config.php to a default value of 'assets'. This is not documented and caused me some work and confusion.
Is it possible define one global collections for all modules, routes or controllers?
For example i have collection "base_css" defined in "application" module and i want use this collection in module "news".
{{Zend\ModuleManager}} cannot resolve {{AsseticBundle\Module}} because it is missing from the autoload class map. The following entry in composer.json fixes this:
"autoload": {
"psr-0": {
"AsseticModule": "src/"
},
"classmap": [
"./"
]
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.