0

I'm trying to follow this guide to Migrating Legacy Web Applications to Laravel.

This is my situation:

I've 2 web application under the same host, both written in PHP

  • one (the legacy) is a "custom framework"
  • second is a Laravel 5.4 application

My goal is to serve both the application only under Laravel app, so my unique entry point for the application is the index.php from the Laravel.

As you can read in the article, I'm trying to start the legacy app inside the Laravel App\Exceptions\Handler

public function render($request, Exception $exception) {
   if( $exception instanceof NotFoundHttpException ) {
      // pass to legacy framework - contents of index.php
      die();
   }
}

when the legacy route is not found.

I've created my own App\Providers\LegacyServiceProvider

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class LegacyServiceProvider extends ServiceProvider
{
    protected $defer = true;

    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton("LegacyApp", function ($app){
            require_once base_path("legacy/index.php");
            return;
        });
    }
}

addend in the config/app.php laravel configuration file

    // other providers
    App\Providers\LegacyServiceProvider::class,


and now comes the fun part... This is the index.php of the legacy app

<?php
require_once __DIR__ ."/app/config/conf.php";

$oSession = new Session();
$oDb = new DbMedoo();
$dbCon = $oDb->dbConn();

include __DIR__ . '/app/routes.php';

app/config/conf.php

<?php

// Some definitions here

// ROUTING
$router = new AltoRouter();

// TWIG
$loader = new Twig_Loader_Filesystem(SITE_CONFIG_DIR . "../../src/App/views");

// Other stuff here

the app/routes.php file

<?php
// **************************************************
// ****************    AltoRouter   *****************
// **************************************************

$router->map( 'GET|POST', '/', 'home.php', 'home');

// Some other legacy routes here

and finally a simple home.php "controller"

<?php

// Some initial checks here

$someModelClass = new SomeModelClass();
$anotherModelClass = new AnotherModelClass();

// some other logics here

$template = $twig->loadTemplate('home.twig');

echo $template->render(array(
    'someVariables' => $someVariableToPass,
));

As you can see I've no Class!!

END OF STORY!

So, when i try to run the legacy app in the App\Exception\Handler

if( $exception instanceof NotFoundHttpException ) {
    // pass to legacy framework
    app()->make("LegacyApp");
    die(); // prevent Laravel sending a 404 response
}

This error fittingly appears

(1/1) ReflectionException
Class LegacyApp does not exist

Suggestions are welcomed

Someone with the same situation here? How I could do this without refactor the entire codebase?

Thank you in advice

1 Answer 1

0

I would say that you can't. And don't use the word, "refactor." Use the word, "rewrite." Because that's what you would be doing to an application that right now is running and moving the freight even though it's not in "Laravel."

I would predict that the financial justification is almost certainly not there.

Sign up to request clarification or add additional context in comments.

1 Comment

I agree. This is my legacy and I can't figure out how to dismiss without loosing our mind.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.