0

I need to integrate Slider Revolution editor into my Laravel (5.5) app.

I've put the editor in public/revslider/ folder to be able to use the visual editor. I also created a helper class to "communicate" with it and be able to use it inside my Blade views:

namespace App\Helpers;

include( public_path('revslider/embed.php') );

class Slider{

/**
 * This function is called where you want to put your slider
 */
public static function make($slider){
    return \RevSliderEmbedder::putRevSlider( $slider );
}

/**
 * This function is called inside <HEAD> tag to include all 
 * SR assets (js/css/font files)
 */
public static function head(){
    return \RevSliderEmbedder::headIncludes(false); 
}

}

The SR's PHP code does not use namespaces. In fact it is a strange mix of Code Igniter, Wordpress and vanilla php.

The problem is it is trying to declare a translation function __(...):

if( ! function_exists('__'))
{
    function __($string = '')
    {
       ....
    }
}

and since there is already such Laravel's helper function, it does not redeclare it and tries to use Laravel's __() function. And that obviously causes errors.

I temporarily managed to fix this problem by changing the name of SR's __() function (and all references to it). But of course it is not a best way to solve this problem, since I will be unable to use SR's automatic updates or will be forced to do these changes after every update.

So my questions are:

  1. Is there any good way of integrating such "bad" code into your project, invoking it safely without conflicts? Is there any way of isolating such code and avoid clashes? By "bad code" I mean code that does not follow strict OOP/PSR rules present in projects like Laravel.

  2. What is the best way to include "external" PHP code? I've just used plain include() inside of my helper class' file, but is there a better/cleaner way? Like, I don't know, loading it through composer?

Gacek
  • 10,184
  • 9
  • 54
  • 87
  • So you are asking is there a better way to include `helper` functions for `RevSlider` in `Laravel app`? – Nikola Gavric Feb 12 '18 at 11:15
  • Yes and no. I'm asking is there a way of calling SR's `\RevSliderEmbedder::headIncludes(false);` function in some kind of isolated way, so it won't clash with Laravel's functions. – Gacek Feb 12 '18 at 11:17
  • No I don't think so, even if you do somehow, how are you resolve which `__` function will be called (RevSlider or Laravel) when you call it..and even if you succeed at this, one of `__` function won't be registered because the other one will be already created so it will just skip creation, hope ti clarifies it – Nikola Gavric Feb 12 '18 at 11:24
  • Yes - that is the situation right now. I'm just curious if there IS any way of isolating such code. Then inside of this isolated "environment" the SR's `__` function will be called, and Laravel's `__` function everywhere else. – Gacek Feb 12 '18 at 11:26
  • Never encountered this issue, but my wild guess is that you can certainly achieve this through `composer.json`, if he doesn't provide any `way around this` than I hardly think you will find anything – Nikola Gavric Feb 12 '18 at 11:30
  • @Gacek did you find a solution for that at the end ? – unknown Mar 15 '19 at 05:30
  • @unknown unfortunately not – Gacek Mar 15 '19 at 08:02
  • @Gacek so at the end u did not integrate your laravel project with slider revolution? because i'm wondering does laravel project support this plugin – unknown Mar 15 '19 at 08:19

0 Answers0