What is magento framework in php

What language is Magento written in?

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.

Читайте также:  Def что значит питон

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.

A man walking out of the portal

From automated database migration to functionality redevelopment and manual resolution of compatibility issues, Staylime takes on all the pains associated with upgrade to Magento 2.

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.

Источник

Commerce and Magento Framework

The Magento Framework controls how application components interact, including request flow, routing, indexing, caching, and exception handling. It provides services that reduce the effort of creating modules that contain business logic, contributing to the goal of both making Magento code more modular as well as decreasing dependencies.

This primarily PHP software component is organized into logical groups called libraries, which all modules can call. Most of the framework code sits under the domain layer or encloses the presentation, service, and domain layers. The framework contains no business logic. (Although the Magento Framework does not contain resource models, it does contain a library of code to help implement a resource model.)

Don’t confuse the Magento Framework with the Zend web application framework that ships with Magento.

You should never modify Framework files, although if you are extending Magento, you must know how to call Framework libraries. Modules you create will typically inherit from classes and interfaces defined in the Framework directories.

Responsibilities

The Magento Framework provides libraries that help reduce the effort of creating modules that contain business logic.

The Framework is responsible for operations that are useful for potentially all modules, including:

  • handling HTTP protocols
  • interacting with the database and filesystem
  • rendering content

Organization

Here is the Magento Framework folder structure:

vendor/ ../magento ../framework lib/ ../internal ../LinLibertineFont ../web 
  • /vendor/magento/framework contains only PHP code. These are libraries of code plus the application entry point that routes requests to modules (that in turn call the Framework libraries). For example, libraries in the Framework help implement a resource model (base classes and interfaces to inherit from) but not the resource models themselves. Certain libraries also support CSS rendering.
  • /lib/internal contains some non-PHP as well as PHP components. Non-PHP framework libraries includes JavaScript and LESS/CSS.
  • /lib/web contains JavaScript and CSS/LESS files. These files reside under web and not internal because they are accessible from a web browser, while the PHP code under internal is not. (Any code that a web browser must access should be under web , while everything else under internal .)

The vendor/magento/framework directory maps to the Magento\Framework namespace.

Highlights of Magento Framework

The Magento Framework ( lib/internal/Magento/Framework/ ) provides a robust range of functionality. If you are an extension developer, you may be interested in this subset of Framework namespaces.

Namespace Purpose
Magento\Framework\DataObject Provides standard functionality for storing and retrieving data through magic methods. This is the base class for many Magento classes.
Magento\Framework\Model Contains base Model classes that almost all Magento Model classes extend from.
Magento\Framework\Model\AbstractModel
Magento\Framework\Model\ResourceModel\AbstractResource
Magento\Framework\Controller Contains classes to help return different types of results (for example, JSON and redirects).
Magento\Framework\View Contains code to render pages and layouts.
Magento\Framework\Data Contains additional classes that handle forms.
Magento\Framework\Url Contains code to look up other pages in Magento.

Other namespaces under Magento\Framework that will interest extension developers:

Namespace Purpose
Magento\Framework\ObjectManager Used to provide dependency injection.
Magento\Framework\App Contains framework code that has knowledge about the Magento application. This code bootstraps the application and reads in the initial configuration. It also contains the entry point to the command line tools, the web application, and the cron job. And finally, it routes requests while providing the deployment context (such as reading in the configuration for the database configuration, languages, and caching systems).
Magento\Framework\Api Contains base classes for advanced functionality of extendable objects through the system (that is, objects that can be extended to add new data through Commerce Marketplace extensions).
Magento\Framework\Config Contains the generic configuration reader. Each config file has its own specialized reader extending these classes.
Magento\Framework\Filesystem Contains classes that handle reading from and writing to the file system.
Magento\Framework\HTTP\PhpEnvironment
Magento\Framework\Session
Magento\Framework\Stdlib\Cookie Code to handle the HTTP request/responses as well as session/cookies is found here.
Magento\Framework\Exception Contains the basic exceptions that are thrown throughout the Magento codebase.
Magento\Framework\Event Contains the code that publishes synchronous events and that handles observers for any Magento event is handled here.
Magento\Framework\Validator Contains the code that validates data (currencies, not empty) and that handles observers for any Magento event.

Aug 26th, 2021

Источник

Оцените статью