Magento is written in PHP and uses elements of the Zend Framework and the MVC (model-view-controller) architectural pattern. It has a highly modular structure that relies on multiple open-source technologies besides PHP.
Magento history using PHP
The development of Magento began in 2007 when the number of PHP frameworks on the market was limited. Back then, the notable ones were CakePHP, CodeIgniter, Zend Framework, and Symfony 1.
CakePHP and CodeIgniter were only suitable for quick application development due to their simplicity, and Symfony 1 was reasonably new and not nearly as advanced as it is today.
The Zend Framework was the framework of choice for developing enterprise-level applications. Backed by the makers of PHP, it addressed all the essential requirements of an ideal framework, such as security, performance, and extensibility, and hence was used during the development. It’s worth noting that Magento 1 was built using components of the Zend Framework and wasn’t an entirely Zend-based application.
Even when the development of Magento 2 began in November 2011, Zend Framework 1 was the most stable offering in the market.
The first stable version of Zend Framework 2 was only released in 2012, when Magento was already in development. Hence, Magento 2 contains components of both frameworks and other frameworks like Laminas and Symfony instead of a single framework.
The development of Magento 2 concluded in 2015. While the original plan was to address existing backward compatibility and performance issues, the project scope grew over the years. The development team decided to build and implement their own framework called the Magento Framework instead of using existing mature frameworks, such as Symfony 2.
As of Magento 2.3.5, Adobe has started porting unsupported components of the Zend Framework to Laminas, which is a continuation of the same framework.
The Magento Framework
Not to be confused with the Zend Framework, the Magento Framework is a primarily PHP software component that determines the interaction of application components such as routing, indexing, caching, exception handling, and request flow.
It is organized into logical groups called libraries and reduces the effort of creating extensions containing business logic, thus reducing dependencies and making the Magento code more modular.
The Magento Framework handles operations such as HTTP protocols, rendering content, and extension interactions with the database and filesystem, making it essential to the functioning of all extensions.
Due to this, Adobe doesn’t recommend developers modify the framework files. Instead, they should call on its libraries to inherit classes and interfaces defined in the framework when creating Magento extensions.
Inside the Magento root directory, the framework is structured as follows:
vendor/ ../magento ../framework lib/ ../internal ../LinLibertineFont ../web
/vendor/magento/framework
strictly contains libraries of PHP code and the application entry point responsible for routing requests to modules. /lib/internal
contains both PHP and non-PHP framework libraries including JavaScript and CSS/Less. /lib/web/
contains JavaScript and CSS/Less files that are accessible through a web browser whereas those in the /lib/internal
folder contain PHP code that cannot be accessed by a browser.
Magento extensibility
Magento’s development team has always focused on ensuring extensibility through all aspects of its development. The platform’s core functionality is packaged in discrete modules to allow customization without replacing core code.
By extending its code instead of replacing it, Magento allows developers to preserve the integrity of the application’s code while empowering store owners to build online stores with limitless functionality.
Magento relies on well-known architectural and programming structures in PHP for its extensibility. This has helped Magento build a diverse product ecosystem around it consisting of developers and merchants globally.
The official Magento Marketplace offers over 3700 third-party themes and extensions, and that only represents a small fraction of their entire product ecosystem. The products on their marketplace are backed by a rigorous extension quality program to ensure every theme and extension is thoroughly inspected for high-quality coding standards and security before being allowed on the marketplace.
Coding standards
As a platform built to support large-scale enterprises, Magento’s core development team follows the Magento coding standard and recommends that developers working with the platform follow it as well. They also recommend that developers use tools like PHP_CodeSniffer to check code compliance while working with the platform.
The Magento coding standards address the following aspects:
- Use of insecure functions.
- PHP code syntax.
- PHP Standards Recommendations (PSR) compliance.
- Incorrect exception handling.
- Naming conventions.
- Unescaped output.
- Use of deprecated PHP functions.
- Empty code blocks and many other PHP and Magento related code issues.
Their entire set of rules can be found in the ruleset.xml file of the Magento coding standard.
Magento’s use of PHP provides it with the flexibility and scalability that its users admire. A thorough understanding of its framework, coding standards, and PHP allows developers to maximize its potential for ecommerce management.