I would advise you to think that Laravel is the main application that allows you to skip legacy code for routes that you have not yet converted. I did this with a huge legacy application that had everything you would expect from an application written 10 years ago, and although it all worked together, it hurt from the very beginning (like the ones you experience, but vice versa) by as it was finished, I just deleted the old code until there was nothing left. With your approach, I cannot understand what will happen when the time comes to permanently undo the old code.
I ended up with:
/app /Console /Http etc... /old /lib /screens /config index.php
OldController had a setup with
public function index($all = null) { ob_start(); require __DIR__.'/../../old/index.php'; $html = ob_get_clean(); return response()->string($html); }
The old / index.php should have done things like:
// TODO: In place to avoid E_DEPRECATED errors for mysql error_reporting(E_ALL ^ E_DEPRECATED); session_start(); // Allow all hardcoded includes in old/ to work $path = __DIR__; set_include_path(get_include_path() . PATH_SEPARATOR . $path); // Set up the global user to suit old code if (Auth::user()) { $myUser = Auth::user()->toArray(); $myUser['requests'] = getRequestList($myUser['uid']); $loggedin = true; Log::debug('using Auth::user() id ' . $myUser['uid']); } else { $loggedin = false; } // Translate Laravel flashed data to existing message arrays if (session()->has('login_error_array')) { $login_error_array = session()->get('login_error_array'); }
I did some dubious things, always using Laravel auth and LegacyHasher for old passwords, in AuthController:
/** * Login * * @return \Illuminate\Http\RedirectResponse */ public function postLogin() { // Logic is a bit cleaner to follow if we fail late instead of early if ($this->hasParams(['login_email', 'login_password'])) { // Login using Laravel password $credentials = [ 'email' => strtolower(Input::get('login_email')), 'password' => Input::get('login_password'), 'active' => ['Y', 'B'] ]; // Use the extended user provider to allow using an array of values in the credentials $provider = new ExtendedEloquentUserProvider(new BcryptHasher(), config('auth.model')); Auth::setProvider($provider); if (Auth::attempt($credentials, Input::has('login_remember'))) { Log::info(sprintf('successful login from: %s', $credentials['email'])); return redirect('/'); } // Try with legacy password $provider = new ExtendedEloquentUserProvider(new LegacyHasher(), config('auth.model')); Auth::setProvider($provider); if (Auth::attempt($credentials, Input::has('login_remember'))) { // Save correctly hashed password // TODO: Only add this once this is definitely working ok as it messes up the DB for legacy code //Auth::user()->password = Hash::make(Input::get('login_password')); //Auth::user()->save(); Log::info( sprintf( 'legacy password for login %s, id %d', $credentials['email'], Auth::user()->uid ) ); Log::info(sprintf('successful login from: %s', $credentials['email'])); return redirect('/'); } } Log::warning(sprintf('login failed for: %s', Input::get('login_email'))); // TODO: Use flashed errors for legacy compatibility session()->flash('login_error_array', ['Wrong Username or Password']); return redirect('login.htm')->withInput(); }
LegacyHasher (yes, that was ...)
public function check($value, $hashedValue, array $options = array()) {
And upload other stuff that is out of frame here. But it is doable, albeit painful. After honestly working on this, all of the old code is removed, and I have a complete, tested Laravel application. He got several hundred TODOs scattered in a liberal, but much more manageable way.
I am happy to help with more detailed information if you decide to go in this direction.