Section en-php

How to Create a Custom Email Transport with Symfony Mailer

Written by admin on 19/05/2023
Category:   PHP, symfony
Tags:  
Today, we're going to see how to create a custom email transport with Symfony Mailer. For the example, we'll create a transport named “pt”. Prerequisites Before we begin, make sure you have installed and configured Symfony Mailer and HttpClient in your project. You can add them to your project using the following commands: composer require symfony/mailer composer require symfony/http-client Creating the Transport Class The first thing to do is...

PHP FFI: Creating a Bind with a Library, QuickJS – Part 5

Written by admin on 24/01/2023
Category:   PHP, PHP / FFI
Tags:  
To conclude this mini technical file on PHP's foreign functions interface, I set out to simply connect to a lib. A kind of challenge that could at the same time help me progress on the topic. So I had to come up with a project idea. Something not too small or too simple but also not too big. Failed, I found an idea but this turns out to be much more complex than I imagined. No matter, I still tried. So for our article, I thought I would attempt...

Symfony: Forcing an entity to use a different database connection than the default configured one

Written by admin on 19/01/2023
Category:   PHP, symfony
Tags:  
It is not uncommon to have multiple databases for a single project. Normally, when two databases are used, entities can be organized into specific directories that are declared in your configuration. In this case, the system will use the connection configured for the entity directory. You can see an example of multiple connections here Symfony 4 / Sonata: managing a multi-server admin interface Let's assume that we want to point to a read-only database (a ...

Use composer and bin/console from your Docker image directly within PHPSTORM

Written by on 19/01/2023
Category:   PHP, symfony, phpstorm, Divers
Tags:  
Okay, you are like me. Your machine has nothing installed locally. Not even composer nor PHP in CLI!While you use PHP and maybe even Symfony (or not), you need to use composer daily. You use PhpStorm every day and think it's a shame not to benefit from all the options of your IDE, especially everything related to composer and the Symfony console. So how do you configure PhpStorm to specify that the composer for your project is located in the docker image?Here is an example of docker-compose.y...

Sonata Custom Actions

Written by admin on 19/01/2023
Category:   PHP, symfony, Sonata
Tags:  
Following the article written by Thomas Bourdin SYMFONY / SONATA: ADDING A CLONE FUNCTION TO A CRUD, we are going to show how, in a very simple way, we can add custom actions to an interface. On the Dashboard: But we are also going to see how to simply and generically customize the custom actions of the listing, your CRUD’s header and finally how to add actions for batch processing. For my example, I started with a very simple table called ...

Debug with PhpStorm and Symfony in a Docker Image

Written by admin on 19/01/2023
Category:   PHP, PHP / FFI, symfony, phpstorm
Tags:  
PHP/Docker Configuration If you are developing with Symfony, installed in a docker compose and still not using the debugger, then this article is for you. We are going to show you how to prepare your environment so you no longer have to do dd() or var_dump. Once you have tasted the joys of debugging, you won't be able to do without it, as it will greatly enhance your comfort. For this article you need to have a Symfony app powered by apache/php (or nginx and...

Create a library with composer

Written by on 04/01/2023
Category:   PHP, Divers
Tags:  
What is Composer? Just as NPM is to JavaScript, Composer is the dedicated tool for PHP that allows you to manage library dependencies for your applications. If you've used a framework like Symfony, you've definitely used it. In reality, every PHP developer uses it on a daily basis. If you're on this page, you're probably wondering how to create a library that can be easily redistributed and shared with the community. That's what I'll try to show you. For the sake of our tutorial, I'll take a ...

PHPSTORM Configuration of 'Quality Tools' in a Docker Image

Written by on 15/12/2022
Category:   PHP, symfony, phpstorm
Tags:  
Here's a question I recently pondered. Usually, I install QA tools directly on my host or in the Docker image. If tools are installed on my host, there's no problem configuring PhpStorm. If the tools are directly configured in the Docker image, there's also no problem using them within the image. However, how can one combine the power of PhpStorm and Docker to link the two? So, here’s how to proceed with the installation of php_codesniffer, Mess Detector, CS Fixer, PSalm, PhpStan. ...

Sonata DataMapper and Autowiring

Written by on 08/12/2022
Category:   PHP, symfony, Sonata
Tags:  
If you have a specific need to transform data between the form and the recording of your entity and think that this transformation code should be located in a service because it makes more sense, you can use the dataMapper by utilizing the dependency injection provided by Symfony. But how to implement it? A small reminder about the DataMapper. If we agree with the official Symfony documentation regarding DataMapper and DataTransformer, a dataMapper has the responsibility to read and write an ...

SF6 / Sonata 5: Managing a OneToMany interface in a CRUD with Sonata's CollectionType

Written by admin on 27/11/2022
Category:   PHP, symfony, Sonata
Tags:   sonata, symfony, admin
In this example, we will take the concrete case of a simple interface that includes multiple elements. We have chosen to use a "Projects" table in which we will assign documents. Therefore, for a project, we can assign several documents. And to facilitate administration, we will ensure that we can manage our nested interface directly within the edit view of our project.We need to create the schema. Firstly, we import our current schema into MysqlWorbench usi...

PHP FFI: Using a Kotlin Multiplatform Library – Part 4

Written by on 11/11/2022
Category:   PHP, PHP / FFI
Tags:  
With Stéphane Péchard https://www.linkedin.com/in/stephanepechard/, Android expert and KMP guru, we wondered if developing an algorithm under KMP and executing it directly in PHP would be feasible. The specifications were simple: the Android dev (Stéphane) provides me with a header file, a .so file and I handle it. With the header file, the contract, we should be able to come up with something... So we managed to make our function call. But to be honest, I still strug...

PHP FFI: Callback - Part 3

Written by on 11/11/2022
Category:   PHP, PHP / FFI
Tags:  
The CallbackDuring the preparation of this article, I noticed that many resources on the internet directly use the libc for their examples. You can easily find fairly demonstrative and simple examples. But to do something cool and original, I thought to myself "let's find something to show with this libc too". After all… if it's just passing a structure as most examples do, it won't be useful. And then I came across a function in a forum where people were ...

PHP FFI: Passing Parameters – Part 2

Written by on 11/11/2022
Category:   PHP, PHP / FFI
Tags:  
Calling the PHP library directly?What if we had fun writing a piece of code that is useless? Come on!!! Come on!! Come on!!!Alright OK. I propose we do something useless by using PHP to call a C library that uses the Zend Engine.Actually, this paragraph is not as useless as it seems. Its purpose is to show you a particular behavior 😊PHP-FFI has a few limitations: you can't pass a PHP variable directly to retrieve its dynamic value from the external library.You only have access to passing C la...

PHP FFI: Introduction – Part 1

Written by on 11/11/2022
Category:   PHP, PHP / FFI
Tags:  
IntroductionSince version 7.4 of PHP, we finally have access to interoperability functions between different languages and PHP: the FFI or Foreign Function Interface.What is FFI? It is simply the ability to use an external library (.dll or .so) directly in PHP, without having to create a PHP extension. Yes, with just a PHP script! It is, among other things, what has made Python so famous and allowed it to have so many features.The great thing about FFI is that a PHP developer who is not an e...

Symfony 6 / Sonata 5: Installing SonataClassification.

Written by on 14/03/2022
Category:   PHP, symfony, Sonata
Tags:  
We have seen in previous articles how to initialize a Symfony 6 + Sonata 5 project with media and users in a secure admin. We then looked at how to manage user localizations.Now we will see how to install and manage classifications. We proceed with the installation of the latest version to date. php8.1 composer.phar require sonata-project/classification-bundle:5.x-dev Apparently, we have a configuration error. Unrecognized option "media" under "sonata_classification.class". Availabl...

Symfony 6 / Sonata 5: Link locales and timezone to user preferences.

Written by admin on 10/03/2022
Category:   PHP, symfony, Sonata
Tags:  
We saw in a previous article how to install Symfony 6 + Sonata Admin 5 with user and media management. We will continue this installation with the configuration of languages and time zones. We will install intlBundle which allows to manage localized display. php8.1 composer.phar require sonata-project/intl-bundle We take this opportunity to add a timezone and locale field to the user.To do this, we will extend userBundle and add a field in the admin...

Symfony 6 / Sonata 5: Initialize a Symfony 6 + Sonata Admin 5 + UserBundle + MediaBundle project

Written by admin on 10/03/2022
Category:   PHP, symfony, Sonata
Tags:  
Here are the commands to initialize a Symfony project with a secure admin. To run Symfony 6 we will need to install php8.0 or php8.1 For php8.0 sudo apt-get install php8.0-cli libapache2-mod-php8.0 php8.0-common php8.0-opcache php8.0-igbinary php8.0-imagick php8.0-msgpack php8.0-readline php8.0-memcached php8.0-xml php8.0-mbstring php8.0-gd php8.0-mysql php8.0-curl php8.0-intl php8.0-memcache php8.0-memcached memcached libapache2-mod-php8.0 php8.0-zip php8.0-mysql For...

Symfony 4 / Sonata: Create a second interface with the same entity

Written by on 06/11/2020
Category:   PHP, symfony, Sonata
Tags:   sonata, symfony
Here we will see how to create a second interface while the entity is already in use in a CRUD interface.The problem with automatically generated interfaces is that they use the name of the entity to construct the routes.If we configure a second interface with an entity that is already used, we will end up with the same route as the first.To address this issue, we will use these two parameters in our admin class to override the default values.Suppose we are using the entity "model", we could...

Symfony 4 / Sonata: Managing a Multi-Language Admin Interface

Written by on 30/10/2020
Category:   PHP, symfony, Sonata
Tags:   sonata, symfony
We will see how to set up a multilingual admin interface with a language selection button (language switcher).Installing translationBundle composer require sonata-project/translation-bundle bin/console assets:install The language switcher requires a specific twig filter.Otherwise, you will get an error like:Unknown "language_name" filter.Then, you need to install these two bundles composer require twig/intl-extra composer require twig/extra-bundle bin/console cache:clear We add the default c...

Symfony 4 / Sonata: Manage a Multi-Server Admin Interface

Written by admin on 11/09/2020
Category:   PHP, symfony, Sonata
Tags:   sonata, symfony
We will see how to manage an admin interface that connects to multiple servers.In our example, we have set up a default MySQL server that manages our admin interface. Users, media, etc.And we have set up a PostgreSQL server that contains a table we wish to manage.We can add as many servers as we wish. Our MySQL Server We have traditionally set up a Symfony Sonata instance by default with a classic MySQL connection. So we can create our database, the schema, and...