ekandreas / bladerunner

WordPress plugin for Laravel Blade templating DEPRECATED
http://bladerunner.elseif.se
12 stars 1 forks source link

Memory Exhausted when including blade template with same name #65

Closed fiskhandlarn closed 3 years ago

fiskhandlarn commented 7 years ago

If I have index.php in my theme with the following contents:

<?php
bladerunner('index');

This package chokes in Illuminate\View\Engines\PhpEngine::evaluatePath when that method tries to include the same index.php in my theme (thus leading to a recursive loop where index.php tries to include itself).

ekandreas commented 7 years ago

Sounds bad! Have you placed a index.blade.php in "views"?

fiskhandlarn commented 7 years ago

Yes, but this happens both when a index.blade.php is present in views and when it's not.

fiskhandlarn commented 7 years ago

In Illuminate\View\Engines\PhpEngine::evaluatePath, incoming $__path is set to:

ekandreas commented 6 years ago

You don't need anything in your index.php. It has to be there as a mandatory file for WordPress. Just put a blade-file in views, eg: views/index.blade.php and fill it with a master and sections!

fiskhandlarn commented 6 years ago

This problem still persists.

You don't need anything in your index.php.

Not sure if you mean theme/index.php. If so, if I have an empty index.php file in my theme, nothing is of course outputted.

If I have the contents as written in my first post in the index.php file in my theme I get the same PHP error as before, irregardless if views/index.blade.php is empty, has content or even exists at all. Could https://github.com/ekandreas/bladerunner/issues/65#issuecomment-340720133 be a starting point for finding a solution?

Worth noting is that this happens both when I override bladerunner/template/bladepath and when I'm not.

fiskhandlarn commented 6 years ago

I think I found where this issue happens:

The findInPaths method in vendor/illuminate/view/FileViewFinder.php searches for index.php and index.blade.php in these locations:

/themes/theme
/themes/theme\views

But since index.php exists in the first location (/themes/theme), it stops there, tries to include it and gets stuck in an infinite loop.

fiskhandlarn commented 6 years ago

A possible solution to this could be to somehow reverse the $paths array in FileViewFinder so that it looks in /themes/theme\views first. Don't know if this is possible via this repo though, or if that's something that has to be done in the Illuminate repo.

fiskhandlarn commented 6 years ago

Any news on this? :)

ekandreas commented 6 years ago

Nope, I have trouble reproducing the error. Could you please give me more information/setup?

fiskhandlarn commented 6 years ago

Create index.php in your WordPress template directory:

<?php
bladerunner('index');

Visiting the site root in the browser. I get this error:

Fatal error: Allowed memory size of 268435456 bytes exhausted (tried to allocate 32768 bytes) in \public\themes\project\index.php on line 1

As stated earlier, this happens both when a index.blade.php is present in views and when it's not.

Please let me know if I can help in clarifying this any further. :)

vpillinger commented 6 years ago

Have you tried the following

bladerunner('views.index');

That tells it to look in the views/ folder for the index file.

fiskhandlarn commented 6 years ago

@vpillinger Then this package tries to look for views/views/index.blade.php, which feels kind of redundant IMO. Or do you mean that it looks for views/index.blade.php for you with that code?

vpillinger commented 6 years ago

@fiskhandlarn When I use bladerunner I use the following folder structure in my root theme directory

views
  layouts
  pages
  partials

In my index.php file I call bladerunner(views.pages.index). It finds the view in "views/pages/index." It does not appear to search in "views/views/pages/index". Are you using the newest version? Perhaps this behavior changed at some point.

Sobladerunner('views.index') should look in views/index.blade.php folder.

fiskhandlarn commented 6 years ago

I'm starting to understand why this is happening. Apparently this repo expects the bladerunner/template/bladepath to be set to the parent directory of the views/ directory (thus needing to prepend the blade name with 'views.' each time bladerunner() is called. And I expected the path to be the actual directory where all my views are. The latter is the way Laravel does it:

<!-- Stored in resources/views/child.blade.php -->

[...]

Route::get('blade', function () {
    return view('child');
});

@ekandreas If you rather keep your custom behaviour maybe the docs should be updated with a warning? :) The example I provided for the 'bladerunner/template/bladepath' filter should at least be updated.

ekandreas commented 6 years ago

Yes, the global view command uses theme root as entrypoint. This design is made so because of usage of Bladerunner in other instances like plugin development. bladerunner function should be deprecated.

fiskhandlarn commented 6 years ago

@ekandreas "should" or "could"? I'm not sure I understand, do you mean plugins using this package? If so, it's still redundant having to write 'views.' in each call to bladerunner() IMO.

ekandreas commented 6 years ago

Yes, if you use Laravel daily then "views" feels redundant. Just make your own path :-)

ekandreas commented 6 years ago

And yes, we can update the documentation. Could you please point me out where to update. The readme says theme-root-folder as starting point.

fiskhandlarn commented 6 years ago

@ekandreas I'm not sure, but I think it should be clarified both under https://github.com/ekandreas/bladerunner#directories (both as a separate list item explaining that all blade files must be loaded from a sub directory, and modify "Your views must be placed within your theme folder." (which isn't really true, if by "within" you're meaning "directly in")) and as a explanation before the 'bladerunner/template/bladepath' example code under https://github.com/ekandreas/bladerunner#filters.

ekandreas commented 3 years ago

Hi! This is a deprecated package. Please use https://github.com/EFTEC/BladeOne instead!