The essential news about content management systems and mobile technology. Powered by Perfect Publisher and XT Search for Algolia.
The News Site publishes posts to the following channels: Facebook, Instagram, Twitter, Telegram, Web Push, Tumblr, and Blogger.
The post APM vs. Logging: Do I Need Both? appeared first on Laravel News.
Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.
Read more https://laravel-news.com/apm-vs-logging-do-i-need-both
The post Glob-like File and Pattern Matching Utilities for PHP appeared first on Laravel News.
Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.
Read more https://laravel-news.com/glob-like-file-and-pattern-matching-utilities-for-php
A library to update a CMS plugin led the path to explore what Composer is, the classic use cases where it shines, its limitations, and the suitable solutions for naming conflicts.
A few years ago, when I was updating one of my plugins for a CMS, I needed a library to complete the update. This library was available on Packagist, the default Composer package repository.
The components and modules used in the library worked with my plugin. However, I encountered a problem. The library version I wanted to use didn’t match the other developer’s version. Their version was incompatible with my requirements.
I was facing naming conflicts and differences
in the functions between versions with “my version.”
This problem led to the exploration of what Composer
is, the classic use cases where it shines, its
limitations, and the solutions you can apply.
Over the years, the development of plugins or extensions for a CMS (Content Management System, such as WordPress, Joomla, PrestaShop, etc.) has been using the CMS-centered solution that defines components, modules, and plugins and uses the CMS framework.
Rather than using a solution centered on a CMS, you can use
a modern solution centered on a library.
When you change your way of designing software, everything
lies in the package library. This library is independent
and can be developed and tested separately.
Therefore, the Components and modules are the entry points of the user interface. You can separate them from the package library. At the same time, you can define the calls from the library to the CMS Framework.
This is where Composer comes in.
Composer is a dependency manager.
You declare what libraries you need to use in your project in a schema definition. Composer then downloads the libraries in the project and manages the libraries’ versions and dependencies between libraries.
The package library that the project installs has all the domain source code and associated Composer libraries.
There are many reasons to use Composer. Some of them are:
Yes, you can include Composer in a plugin for a CMS. Think of Composer as a “Utility.” An example of the benefit of using Composer is replacing the usage of the classic autoloader.
The autoloader is the mechanism that helps PHP find where the source code is.
Using Composer, you can declare a single autoloader, and it will automatically load the source code.
Until now, your project architecture is correct, Composer is fantastic, and thousands of PHP developers are using it.
So, it looks like a perfect world.
However, there’s an issue.
Composer works perfectly as a standalone tool. It’s designed to work only on the developer’s computer and cannot work on a live site. Also, it’s a tool that you can use at development time.
If you have two separate developers using the same libraries, it is a win-win situation. But, if they don’t have standard definitions or libraries, conflict arises.
If you plan to use Composer libraries in an extension, you must find a way to solve the potential problems.
Let’s look at this XT Laravel Starter example with library definitions. In particular, this project uses the Guzzle library v7.
If we have another developer using version 5 of Guzzle, installing the package and simultaneously executing the extension can result in conflicts.
For instance, an asynchronous request is sent differently in Guzzle v7 than in v5. You need a solution to prevent these differences from cropping up.
The most common way to solve the Composer conflicts between teams is prefixing PHP. Change the source code and add a prefix wherever the conflict appears.
For instance, this is a piece of code from the Carbon Datetime Library.
I added “MyLibrary” to the namespace to identify the library in my extensions.
There are many cases/examples, but the general idea is to add a prefix to identify objects uniquely.
Yes, you can prefix entire projects, and the results are astounding!
After using Composer and manually prefixing entire libraries, it’s time to automate the prefixing. To overcome conflicts between installed libraries and prefix entire projects, you can use PHP prefixing online services. The prefixing service is a computing-intensive task.
The prefixing engine parses all files, analyzes the dependencies of all libraries, and performs several phases of processing. It runs on hardware and multi-core servers, taking advantage of parallel processing. This helps in processing the projects quickly.
In this article, you’ve learned about the rationale behind the usage of Composer for plugin development.
Composer changes the design of the software. When using Composer, the main roadblock is analyzing the requirements based on your package’s available libraries and architecture. Even with such a challenge, the potential benefits of Composer far outweigh the initial difficulties (time spent on the initial learning process, integrating and installing dependencies).
Composer is a game-changer for developing a plugin, and the evolution of PHP is currently linked to Composer. The benefit is enormous. You can use the latest innovations of the PHP ecosystems and, at the same time, focus on your business.
In upcoming articles, I will present three projects that illustrate the benefit of using Composer with a CMS.
Stay tuned!
The post Using Composer in a CMS: A practical approach first appeared on PHP Prefixer Blog.Read more https://blog.php-prefixer.com/2022/03/24/using-composer-in-a-cms-a-practical-approach/
The post Find Missing Translations with the Laravel Translations Checker appeared first on Laravel News.
Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.
Read more https://laravel-news.com/laravel-translations-checker
The post Given-When-Then Plugin for Pest appeared first on Laravel News.
Join the Laravel Newsletter to get Laravel articles like this directly in your inbox.
Read more https://laravel-news.com/pest-given-when-then