You have problems with legacy - then you are in luck! Sawing a monolith in PHP

Introduction

I am often asked to talk about working with legacy monoliths. There is a lot of talk about microservice architecture, but it is rarely mentioned that projects come to it after years of growth with a monolithic application. To change the architecture of a live solution, you have to go through several stages. The author has worked with various projects - both with a full-fledged multitenancy service-oriented REST architecture, and with a huge monolith, in the repository of which there were commits for ten years. This article is about the dark side, legacy code, and practical solutions to problems with monolithic PHP applications.





Reasons for the emergence of legacy

There are two main reasons for legacy code.





The first reason is that new versions of operating systems, languages, browsers, libraries are released. The problem is especially relevant for mobile applications and scripting languages ​​- with each release of a new version of the platform, it is necessary to fix the compatibility problems of the old code. This process is stable and predictable for years to come.





The second is technical debt, which is created on purpose. Management shortens software development time by eliminating design, automated testing, or code review, approves third-party libraries that are not supported, and developers do not document complex logic. This is common and does not depend on the amount of money in the company's account. Don't scold bad bosses. They have good reasons to do so.





Products have a life cycle ; the period of high demand for popular products lasts three to four months. Competitors will copy all the best and make it even better, so companies are forced to regularly release new items. To maintain revenue, new products and revisions are released every few months, so new cycle sales offset the decline in product sales at the end of the cycle. Both Apple and Marvel make three or four major releases a year, and Oracle also has a quarterly release cycle in the enterprise SAAS market. However, there is no recipe for success. 97% of startups throw away their product and try something new before they find a product that they buy from. Therefore, the cost of developing MVP in startups is minimized.





You're in trouble with Legacy, so you're in luck!

, , . . , , , . , , , , . , , , , legacy-. - legacy , , .





?

. , Wordpress , 38% -. -, . Wordpress , , .





, - , .





, ?





. .





. API . , .





, .





, . . . , , .





PHP .





Rector , .





Exakat PHP, , , .





Phan , PHP.





, , .





. PHP 5- 7- , .





. , . , , . , , . git- . , , .





- . , - , golang. - , , , . .





, - , , API, . , .





:





  • ,





  • API , ,





  • composer ,





  • , ,





  • , API.





- . . . API .





, PHP, API. , . “release, control, validation” “DevOps”. . , .





, , , .





- :





  1. - , ;





  2. API - , ;





  3. - , ;





  4. , ;





  5. ; : IoC- .





, .





, , , Packeton, git-. , Private Packagist.





composer- IoC-, : , , diff.





composer Symfony Dependency Injection IoC- . . IoC-, . IoC- .









) ,

) , .





, .





1. , , , “ ” . 





: . : , diff .





:





  • , , .





  • , , , , .





  • ,





  • , , getter-, -.





  • , .





- , . , , , , . : , , diff





2. . 





PHP (). , , / API (, diff). 





, . “”. 





: , , diff .





, -.





, , , - .





-“” () , , , composer-, .





5. . 





: , Single Responsibility Principle, . - , , . .





- -, . , , , , . - IoC-. 





: , , diff, .





6. . 





: $model = new ($modelName . ’Class’);





. , , .





switch- . , .





IoC- . , . . , .





:





  1. , , lazy.





  2. API Service Subscriber.





  3. API .





- Service Subscriber. , . : , , c , . Diff.





Service-Oriented Architecture

, , , , . - ? .





API. API restful-. - , , , . http- curl.





- :





  1. . ID , API, . .





  2. , . : . , , .





, . - . , . , . - . , , . , .








All Articles