Support the ongoing development of Laravel.io →
posted 10 years ago
Architecture
Last updated 2 years ago.
0

I dont think that any framework will be better from another for what you want to do.

I feel that the difficulty level of this depends greatly from the way your code is written.

Moreover is very difficult based on the fact that you dont want downtime. From my very little experience i think that this is nearly impossible to do.

Why dont you cutoff development on your current code (no new features etc etc only serious stop-issues fixing) and move on to port your code to laravel?

Last updated 2 years ago.
0

I understand. However, I'm searching for ways of making transparent the migration for pieces of code already ported to Laravel, while mantaining functional older plain PHP code.

For example, Laravel "overwrites" superglobals ($_GET, $_POST, etc.) using classes and methods, (ex. Input::get()). My PHP project of course make direct use of superglobals. How can I "make it go" under Laravel without having to rewrite instantly all my PHP code?

Last updated 2 years ago.
0

I don't think you can effectively move a project from spaghetti code to a framework while retaining continuous deployment* without making huge sacrifices that would heavily negate the value of using a framework. If your code has been developed in such a way that you can't refactor individual portions (for example input management) it's probably a very good sign that you need to start again from the ground up.

The logical approach is (as e4rthdog said) to develop a new version of the site (on $framework) while the current codebase remains online but is no longer actively developed -- except for fixes. This is the only approach that will ensure you get the full benefit of a framework (Laravel or otherwise), polluting your framework code with backwards compatibility magic would be like learning to ride a bike and then "riding" the bike by pushing your feet along the ground.

If you live in some sort of real world hell that doesn't give you the opportunity of freezing the codebase and you absolutely must on pain of death (may I suggest you run for the hills?) then maybe you could build some sort of magic route that takes all of your legacy website requests and reconstructs the request data from framework format to legacy website format, then as you rebuild page by page you can slowly phase old the old routes (eg: when /blog-post is made, replace all /blog-post.php links). Something like:

Route::any('{file}.php', function($file)
{
    // assign get parameters
    // assign post data
    // convert session data into legacy site format
    // perform whatever bootstrapping is required
    require_once ("legacy/{$file}.php");
});

An alternative would be bypass the framework altogether, instruct your web server to redirect all *.php requests direct to the file that exists and then your framework of choice can handle any files that don't match an existing file, but you're still going to suffer from needing to build your framework codebase around the needs of your spaghetti codebase, because you'll need to retain backwards compatibility.

Try and make a full rewrite possible, you'll thank yourself down the line.

ps. read this https://leanpub.com/mlaphp

Last updated 2 years ago.
0

In short, you can't.

Why you want to migrate your project to laravel? Does it have a more pro's then cons?

Laravel is just a php framework, just like your "plain" project.

When you like to migate, it would be a big job, but in the future you can build on it.

Last updated 2 years ago.
0

Thanks citricsquid, I've already implemented a solution similar to your custom route: in the near future I'll know if this may be a good compromise between "using a framework" and "rewriting everything from the ground up" or not. The only problem is that routing DOES NOT work for index.php pages, for example this code:

Route::get('legacy/index.php',function(){
    return "This is index";
});

won't be executed as expected when visiting that page. Why this? Is there a solution?

Last updated 2 years ago.
0

het86 said:

Thanks citricsquid, I've already implemented a solution similar to your custom route: in the near future I'll know if this may be a good compromise between "using a framework" and "rewriting everything from the ground up" or not. The only problem is that routing DOES NOT work for index.php pages, for example this code:

Route::get('legacy/index.php',function(){ return "This is index"; });

won't be executed as expected when visiting that page. Why this? Is there a solution?

I'd guess that calling anything that ends with index.php is automatically rewritten to go to Laravel's index.php by apache, so from the perspective of the framework, anything that ends with "index.php" just gets treated as if they were the "/" url.

You might want to try using Route::get('legacy/', function() { }); and seeing if that works.

Last updated 2 years ago.
0

That doesn't work, sorry. I think this could be considered a bug (not expected behaviour) of Laravel 4.x.

thepsion5 said:

het86 said:

Thanks citricsquid, I've already implemented a solution similar to your custom route: in the near future I'll know if this may be a good compromise between "using a framework" and "rewriting everything from the ground up" or not. The only problem is that routing DOES NOT work for index.php pages, for example this code:

Route::get('legacy/index.php',function(){ return "This is index"; });

won't be executed as expected when visiting that page. Why this? Is there a solution?

I'd guess that calling anything that ends with index.php is automatically rewritten to go to Laravel's index.php by apache, so from the perspective of the framework, anything that ends with "index.php" just gets treated as if they were the "/" url.

You might want to try using Route::get('legacy/', function() { }); and seeing if that works.

Last updated 2 years ago.
0

het86 said:

That doesn't work, sorry. I think this could be considered a bug (not expected behaviour) of Laravel 4.x.

thepsion5 said:

het86 said:

Thanks citricsquid, I've already implemented a solution similar to your custom route: in the near future I'll know if this may be a good compromise between "using a framework" and "rewriting everything from the ground up" or not. The only problem is that routing DOES NOT work for index.php pages, for example this code:

Route::get('legacy/index.php',function(){ return "This is index"; });

won't be executed as expected when visiting that page. Why this? Is there a solution?

I'd guess that calling anything that ends with index.php is automatically rewritten to go to Laravel's index.php by apache, so from the perspective of the framework, anything that ends with "index.php" just gets treated as if they were the "/" url.

You might want to try using Route::get('legacy/', function() { }); and seeing if that works.

Hm, I just tried a fresh laravel install with the following route:

Route::get('foo/bar/index.php', function(){
   return 'hit foo/bar/index.php';
});

And hitting that url worked as intended. I wonder if it might be your apache or .htaccess that's preventing that from functioning in your case.

Last updated 2 years ago.
0

For anyone interested in, I think I will slowly refactor my project taking inspiration from some aspects of laravel's design. Trying to switch an already working piece of software on an existing framework platform is probably the wrong approach to the problem. Thanks anyway.

Last updated 2 years ago.
0

if you using nginx server

you should add

        try_files $uri = 404;

for your nginx config

404 will trigger laravel to catch xxx.php from route

nginx conf example:

server {
    listen 80;
    server_name dev.com.tw;
    set $root /home/vagrant/Code/dev.com.tw/public;
    root $root;

    index index.html index.htm index.php;

    charset utf-8;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }


    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    access_log off;
    error_log  /var/log/nginx/dev.com.tw-error.log error;

    error_page 404 /index.php;

    sendfile off;

    location ~ \.php$ {
        try_files $uri = 404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass unix:/var/run/php5-fpm.sock;
        fastcgi_index index.php;
        include fastcgi_params;
    }

    location ~ /\. {
        deny all;
    }
}

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

het86 het86 Joined 5 May 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.