2017 © Pedro Peláez
 

library blade-macro

Reusable scope-protected blade blocks, with empty I/O on runtime (replacement for @include which uses native I/O based PHP includes).

image

jobinja/blade-macro

Reusable scope-protected blade blocks, with empty I/O on runtime (replacement for @include which uses native I/O based PHP includes).

  • Friday, June 8, 2018
  • by jobinja
  • Repository
  • 4 Watchers
  • 6 Stars
  • 1,506 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 12 Versions
  • 6 % Grown

The README.md

Blade Macro

This package introduces a new blade directive called @macro which allows reusable scope-protected blade code blocks. Just like what @include does but with zero runtime I/O., (*1)

@include uses native PHP include directive, which causes runtime I/O, Event if Opcache is fully enabled. But sometimes @include is used when we want to just Don't repeat ourselves But this abstraction should not cause any performance bottleneck., (*2)

Installation

For Laravel >= 5.5.0:, (*3)

composer require jobinja/blade-macro

For Laravel <= 5.3.0:, (*4)

composer require jobinja/blade-macro:1.0.*

Usage

Just use the following service provider in your app.php:, (*5)

[
    \JobinjaTeam\BladeMacro\JobinjaBladeMacroServiceProvider::class,
    //...
]

Then you can simply replace your needed old @include directives with the new @macro one:, (*6)

@include('some_partial', ['some_var' => 'some_value')

// Should be replaced with:
@macro('some_partial', ['some_var' => 'some_value'])

Configuration

By default the package re-compiles blade views on each request in development environment, if you want to disable this feature run:, (*7)

php artisan vendor:publish --provider=JobinjaTeam\BladeMacro\JobinjaBladeMacroServiceProvider

and config the package based on your needs., (*8)

Problem

Please see #16583 or simply read the following:, (*9)

Consider the following loop:, (*10)

@for($i=1; $i < 500000; $i++)
    @include('iteration_presenter', ['iteration' => $i])
@endfor

The above code will be replaced by something like the following:, (*11)

<?php for($i=1; $i < 5000000; $i++){ ?>
    <?php
        // Just for example in real world laravel wraps this
        // around a method to satisfy scope protected data.
        include './blade_compiled_path/iteration_presenter.php';
    ?>
<?php } ?>

The above code includes the iteration_presenter.blade.php file for 5,000,000 times, which causes heavy I/O calls, but the only reason we have used the iteration_presenter partial is to create more abstraction and don't repeat ourselves., (*12)

Solution

Instead of using native include directive we have created a new @macro directive which simply copy/pastes the partial content in compile time, and simply there is no I/O then:, (*13)

@for($i=1; $i < 500000; $i++)
    @macro('iteration_presenter', ['iteration' => $i])
@endfor

The above @macro directive will be translated to the following:, (*14)


    <?php (function ($scopeData) { extract($scopeData); ?>

    <?php echo e($iteration);?>

    <?php })($someHowComputedScope) ;?>

Running tests

composer test

License

Licensed under MIT, part of the effort for making Jobinja.ir better., (*15)

The Versions

08/06 2018

dev-master

9999999-dev

Reusable scope-protected blade blocks, with empty I/O on runtime (replacement for @include which uses native I/O based PHP includes).

  Sources   Download

MIT

The Requires

 

The Development Requires

by Reza Shadman

laravel templating blade performance blade-optimize

08/06 2018

2.0.0

2.0.0.0

Reusable scope-protected blade blocks, with empty I/O on runtime (replacement for @include which uses native I/O based PHP includes).

  Sources   Download

MIT

The Requires

 

The Development Requires

by Reza Shadman

laravel templating blade performance blade-optimize

16/01 2017

1.0.9

1.0.9.0

Reusable scope-protected blade blocks, with empty I/O on runtime (replacement for @include which uses native I/O based PHP includes).

  Sources   Download

MIT

The Requires

 

The Development Requires

by Reza Shadman

laravel templating blade performance blade-optimize

16/01 2017

1.0.8

1.0.8.0

Reusable scope-protected blade blocks, with empty I/O on runtime (replacement for @include which uses native I/O based PHP includes).

  Sources   Download

MIT

The Requires

 

The Development Requires

by Reza Shadman

laravel templating blade performance blade-optimize

09/01 2017

1.0.7

1.0.7.0

Reusable scope-protected blade blocks, with empty I/O on runtime (replacement for @include which uses native I/O based PHP includes).

  Sources   Download

MIT

The Requires

 

The Development Requires

by Reza Shadman

laravel templating blade performance blade-optimize

24/12 2016

1.0.6

1.0.6.0

Reusable scope-protected blade blocks, with empty I/O on runtime (replacement for @include which uses native I/O based PHP includes).

  Sources   Download

MIT

The Requires

 

The Development Requires

by Reza Shadman

laravel templating blade performance blade-optimize

24/12 2016

1.0.5

1.0.5.0

Reusable scope-protected blade blocks, with empty I/O on runtime (replacement for @include which uses native I/O based PHP includes).

  Sources   Download

MIT

The Requires

 

The Development Requires

by Reza Shadman

laravel templating blade performance blade-optimize

24/12 2016

1.0.4

1.0.4.0

Reusable scope-protected blade blocks, with empty I/O on runtime (replacement for @include which uses native I/O based PHP includes).

  Sources   Download

MIT

The Requires

 

The Development Requires

by Reza Shadman

laravel templating blade performance blade-optimize

24/12 2016

1.0.3

1.0.3.0

Reusable scope-protected blade blocks, with empty I/O on runtime (replacement for @include which uses native I/O based PHP includes).

  Sources   Download

MIT

The Requires

 

The Development Requires

by Reza Shadman

laravel templating blade performance blade-optimize

24/12 2016

1.0.2

1.0.2.0

Reusable scope-protected blade blocks, with empty I/O on runtime (replacement for @include which uses native I/O based PHP includes).

  Sources   Download

MIT

The Requires

 

The Development Requires

by Reza Shadman

laravel templating blade performance blade-optimize

24/12 2016

1.0.1

1.0.1.0

Reusable scope-protected blade blocks, with empty I/O on runtime (replacement for @include which uses native I/O based PHP includes).

  Sources   Download

MIT

The Requires

 

The Development Requires

by Reza Shadman

laravel templating blade performance blade-optimize

24/12 2016

1.0.0

1.0.0.0

Reusable scope-protected blade blocks, with empty I/O on runtime (replacement for @include which uses native I/O based PHP includes).

  Sources   Download

MIT

The Requires

 

The Development Requires

by Reza Shadman

laravel templating blade performance blade-optimize