crhayes/blade-partials

Laravel 5.1 error

Opened this issue · 8 comments

With the new release, I get:

FatalErrorException in ViewServiceProvider.php line 64:
Call to undefined method Illuminate\View\Compilers\BladeCompiler::createOpenMatcher()

I'm investigating this

can't get it...

Hi @younes0,

What problem are you facing? Blade seems to of had a bit of an overhaul with 5.1 and the extend method has been altered. Mainly due to the removal of the create*Matcher methods.

You can get over this with a small change by copying the regex patterns into your own code and do something like this in the service provider for instance:

public function boot()
{
    Blade::extend(function($view, $compiler) {
        $pattern = $this->createMatcher('directiveName');
    });
}

protected function createMatcher($function)
{
    return '/(?<!\w)(\s*)@'.$function.'(\s*\(.*\))/';
}

If however you'd rather upgrade properly, the directive method essentially does some of the heavy lifting for you as seen in the docs. The example in the docs will replace @datetime($foo) with the returned value, saving you from having to do the matching.

Thanks @dbonner1987 for your help,

I used a dirty workaround by duplicating BladeCompiler class and adding the removed create*Matcher methods.

I couldn't convert this to the new format:

return preg_replace(
    $pattern, 
    '$1<?php $__env->renderPartial$2, get_defined_vars(), function($file, $vars) use ($__env) { 
        $vars = array_except($vars, array(\'__data\', \'__path\')); 
        extract($vars); ?>', 
    $value
);

I will look into this further later or make a PR based on your solution:https://github.com/Arrilot/laravel-widgets/blob/master/src/ServiceProvider.php#L119

I'll try and look into this issue this week. Thanks for the report.

Is there a cleaner solution to this yet?

Had there been any progress on this for Laravel 5.2?
This should be a feature implemented into Blade itself I think

I have managed relative include using Blade::directive on Laravel 5.4, I think other version 5 may work,

here is the gist

https://gist.github.com/ciptohadi-web-id/91a4ca34ed0f5d1ce15c8a66ee36c284