Comments (8)
@glen-84 AFAIK, filtering applies to single assets (or asset collections) - not automagically applied
from assetmanager.
@Ocramius Nooooo, I don't wanna have to list every single file. :-(
Assetic supports glob assets which are collections ... does AssetManager support this?
Edit: Actually that would probably merge them, which I don't want.
from assetmanager.
@grizzm0 can you provide feedback here? Seems like you have a solution
from assetmanager.
Sorry, took this discussion on IRC instead. Simply replace 'less' with 'css' in the filters array. It's based on mime type and not extension from the looks of it. And less has the mime of text/css.
from assetmanager.
Right, this works:
'css' => array(
array('filter' => 'Lessphp')
)
TBH, I don't understand how AM distinguishes between a mime type and an extension. For example:
'less' => array(
array('filter' => 'Lessphp')
)
Is 'less' a mime type or an extension here? I intended for it to be an extension, but it seems that this doesn't work.
Perhaps it should be more like:
'extensions' => array(
'less' => array(
array('filter' => 'Lessphp')
)
)
from assetmanager.
The problem is that the extension is determined base on the mime type of the file, not the actual extension.
Have a look at https://github.com/RWOverdijk/AssetManager/blob/master/src/AssetManager/Service/AssetFilterManager.php#L75-L82 and https://github.com/RWOverdijk/AssetManager/blob/master/src/AssetManager/Service/MimeResolver.php#L577-L584.
Let's say I have this configuration:
'filters' => array(
'less' => array(
array('filter' => 'Lessphp'),
),
),
and I'm trying to load the file /path/to/hello-world.less
. Since I have neither the path
nor the mimetype
in the configuration, AssetFilterManager
is going to go into the logic block for extension, shown below:
$extension = $this->getMimeResolver()->getExtension($asset->mimetype);
if (!empty($config[$extension])) {
$filters = $config[$extension];
} else {
return;
}
So, basically, if the extension comes back as less
and we have a less
key in the filters config. The problem is that the extension is coming back from the MimeResolver
as css
, and here's why:
if (!($extension = array_search($mimetype, $this->mainMimeTypes))) {
$extension = array_search($mimetype, $this->mimeTypes);
}
return !$extension ? null : $extension;
Have a look at MimeResolver::$mimeTypes
- this array contains several instances of the text/css
mime type, shown below:
'css' => 'text/css',
'less' => 'text/css',
'sass' => 'text/css',
'scss' => 'text/css',
The issue is that array_search(...)
is going to return the key of the first found instance of what's being searched for. We're looking for the text/css
mimetype, and the first instance is css
, so MimeResolver
reports back that the file's extension is css
, which is incorrect.
I believe the best solution here is to use php's pathinfo(...)
function to determine the extension.
Remove: $extension = $this->getMimeResolver()->getExtension($asset->mimetype);
Replace with: $extension = pathinfo($asset->getSourcePath(), PATHINFO_EXTENSION);
This will give us the file's actual extension regardless of the mimetype.
I would happily send a PR for this, but I can't get the test suite to run and there are no instructions on how to do so. :)
from assetmanager.
The instructions are in the travis file :)
We could match against both extensions, as to not break BC, but I'm not sure if we really want that. If you do so, the files will be stored as less, too. That will cause problems for most people.
from assetmanager.
The instructions are in the travis file :)
Oh yeah! Oops... I will blame my failure to notice that on not having had enough coffee yesterday. :)
I'm not sure what you mean about the files being stored as less too, though. If you mean that *.css
files will be passed through the Lessphp
filter when they previously were not, then that shouldn't happen. That would only happen if css
is specified as the extension in the filter config, which means that's what the user wanted anyway (and that presently works today).
The pathinfo(...)
suggestion I think would give full BC. I can put together a PR when I have some time see what you think.
from assetmanager.
Related Issues (20)
- Support for EventManager & ServiceManager 3.0 HOT 6
- Append last modified date to Asset View Helper even withoud cache HOT 5
- FilePathCache throws exceptions almost every release HOT 13
- AssetManager is not installable with new skeleton application HOT 8
- PHP Fatal error: Uncaught TypeError: Argument 2 passed to AssetManager\Service\AssetCacheManager::setCache() must implement interface Assetic\Asset\AssetInterface, null given HOT 8
- Bower components and image paths HOT 2
- Wrong MIME type when converting asset HOT 2
- Asset not loaded on latest ZendSkeletonFramework HOT 2
- How to create a resolver that remap extension? HOT 4
- Create Seperate "Core" repository and package HOT 8
- Caching/Processing assets without asset() view helper HOT 3
- node: Permission denied HOT 1
- How to add a response header - Last-Modified, E-Tag HOT 1
- unable to load AssetManager HOT 1
- Asset view helper not work with ZF3 with basic documentation configuration. ZF3 use his own Asset view helper. HOT 1
- asset view helper BC HOT 10
- Can't install via composer due to version locks HOT 18
- Composer Version 2x HOT 1
- packagist versions not auto updated HOT 3
- laminas/laminas-dependency-plugin HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from assetmanager.