Creating your own security attribute with Symfony
Medium | Nacho Colomina
by Nacho Colomina
1y ago
Symfony security has a great feature to check authorization named Voters. Voters are services which allows you to check user authorization in the way you need. You can see more about Voters here: https://symfony.com/doc/current/security/voters.html In this article, I would like to share with you another way to define custom authorization checking: Create our custom security attribute Let’s imagine we store user roles out of our User class (the one which implements Symfony UserInterface) and we have a controller on which we only want to allow ROLE_SUPERUSER users. Creating the attribute Le ..read more
Visit website
Creating a one api endpoint with PHP and Symfony (Part 5)
Medium | Nacho Colomina
by Nacho Colomina
1y ago
Sometimes we need to block certain parts of our code since their execution have to be atomic, such as a heavy calculation in which any other alteration in its processing could create inconsistencies. In this part of the article, we will do some modifications to be able to ensure an operation is executed once per request. In order to achieve that, we’re going to use redis as a semaphore so that, every time a request acquire an operation execution, it can block it until it finishes or during an specified time. If you have not read the other articles, you can find then here: Part 1: https ..read more
Visit website
Creating a one endpoint api with PHP and Symfony (Part 4)
Medium | Nacho Colomina
by Nacho Colomina
1y ago
In the last parts of this article we talked about: The basics to create a one api endpoint which discovers what operation have to perform through a parameter in the payload. How to add authentication and authorization to our api How to perform operations in the background If you haven’t read the previous parts, you can do it here: Part 1: https://medium.com/@ict80/creating-a-one-api-endpoint-with-php-and-symfony-d5f03d3141c0 Part 2: https://medium.com/@ict80/creating-a-one-api-endpoint-with-php-and-symfony-part-2-187604ffeb67 Part 3: https://medium.com/@ict80/creating-a-o ..read more
Visit website
Using chatGPT and Google search to find information you want
Medium | Nacho Colomina
by Nacho Colomina
1y ago
I would like to write this short article to show how chatGPT and common Google search can be combined to quickly get to the information you want. Let me show a very simple example. Imagine we want to start a blockchain project and we want to choose a database management system with fits our needs. First of all we could ask ChatGPT about what kind of databases are useful for blockchain development After reading above chatGPT answer, we can see that distributed databases could fit our needs, and now we would like to get a list of distributed databases. Let’s ask chatGPT: As we c ..read more
Visit website
Simple example of using PHP 8.1 enums
Medium | Nacho Colomina
by Nacho Colomina
1y ago
Php 8.1 comes with a new great feature called enums. Enums allow us to mantain a collection of constant values. Enums, like classes, can define methods and even implement interfaces. In this article, I would like to share with you a practical example of how to use enums. If you want to learn more about how enums work there are plenty of documentation in the internet. I recommend the article : https://medium.com/geekculture/php-8-1-welcome-enumeration-5b9ed1063ec0 where the author explains very well how enums work. Let’s start with the example. Imagine we want to classify an api call ..read more
Visit website
Symfony api one endpoint. Pushing notifications using mercure
Medium | Nacho Colomina
by Nacho Colomina
1y ago
In the article https://medium.com/@ict80/creating-a-one-endpoint-api-with-php-and-symfony-part-3-8955325c5101, I created an attribute to mark api operations to be executed in the background. When an annotated operation was called as background, its execution was delayed using symfony messenger and the client received an HTTP 202 Accepped response. In this article, I will make some changes to allow operations to notify the user when they finish. To achieve it, I will use mercure since symfony integrates with it really well. I am going to avoid code from some classes to focus only in the mo ..read more
Visit website
Symfony service subscribers
Medium | Nacho Colomina
by Nacho Colomina
1y ago
Symfony service subscribers are useful when we have a service that needs other services but we don’t know which one it will use. Instead of injecting all services in the constructor, we can create a service subscriber and inject it on the constructor. Let’s see how it works using an example. Imagine we have a service which have to download a document but, depending on the country, it has to use a different service to perform the download. The countries which differ on how to perform the download are: Spain (ES) France (FR) Germany (DE) The rest of the countries use the same method ..read more
Visit website
Managing api responses for exceptions on Symfony using KernelEvents
Medium | Nacho Colomina
by Nacho Colomina
1y ago
Many times, when building an api, we need to return diferent responses to clients depending on exeption thrown. In this short article, I would like to show you how to achieve this by using Symfony Kernel Exception event. Let’s imagine we are building a json api which throws (among others) the following exceptions: Symfony\Component\Validator\Exception\ValidationFailedException: When input data validation fails. Symfony\Component\HttpClient\Exception\TransportException: When a call to an external resource fails. And let’s assume we want to: When a ValidationFailedException is ..read more
Visit website

Follow Medium | Nacho Colomina on FeedSpot

Continue with Google
Continue with Apple
OR