MtHaml icon indicating copy to clipboard operation
MtHaml copied to clipboard

Laravel compatibility: filter constructors should not require parameters

Open michaelk83 opened this issue 9 years ago • 0 comments

I'm using MtHaml with Laravel 5 with the help of https://github.com/BKWLD/laravel-haml , and I've encountered a compatibility issue in the SCSS filter. I suspect there's a similar issue in the CoffeeScript filter, but haven't tested.

If I instantiate the SCSS filter inside the BKWLD/laravel-haml configuration, I get a PHP Fatal error when the configuration is cached:

Fatal error: Call to undefined method MtHaml\Filter\Scss::__set_state() in .../bootstrap/cache/config.php

On the other hand, if I specify only the filter class name, as it should be done, then the filter constructor fails because it expects the compiler class as a parameter.

The configuration handling is a BKWLD/laravel-haml issue, but the underlying problem is in MtHaml: it should be possible to instantiate all filters without parameters. If a compiler is not provided, it should create a default compiler instance automatically. The constructor should only throw if the compiler class is not found and can't be loaded.

Specifically with Laravel 5, it may be enough to add a type hint on the compiler parameter. Laravel should be able to inject the dependency on its own once it knows which class it needs.

michaelk83 avatar Jul 26 '16 15:07 michaelk83