Ran into this recently, and it seems that TravisCI has PHP 8.2 support but only on Ubuntu 20.04 Focal Fossa and it's missing a library. Hints on this forum post. The gist is that dist: focal has to be set as well as an extra package installed form apt. Without the apt package, an error… Continue reading Using PHP 8.2 on TravisCI
Category: PHP
How to Require One Symfony Form Field and/or Another
Say there's a Symfony form that requires either one field to be submitted or another field. In this case, it's okay if both are submitted, but at least one is required. I had this exact situation come up earlier this week and all the solutions I found were related to adding validation to models. I… Continue reading How to Require One Symfony Form Field and/or Another
What Dependencies Should be Injected into a Controller?
This article ist mostly about Symfony, but the advice here applies across frameworks. It's easier to define what's shouldn't be injected as a dependency: things global to the framework or the application being built. A form system is something global to the framework/application. Should the FormFactory be injected into every controller? How about templating? Should… Continue reading What Dependencies Should be Injected into a Controller?
Working with PostgreSQL Arrays in PHP
I recently had to do some work with PostgreSQL arrays in a PHP app. My first question: how do I manage arrays as parameterized values in a query? Turns out there are two ways forward: Array Literals These appear in the Postgres documentation as curly brace surrounded, comma delimited lists: {1,2,3}. A literal like this… Continue reading Working with PostgreSQL Arrays in PHP
Useful Health Check Endpoints in PHP Applications
At PMG we run pretty much every application in AWS's Elastic Container Service with web entrypoint handled by Application Loader Balancers. One feature of the ALB and ECS is that web-based services do a blue/green deployment. When a new version of the application is shipped, it spins up a new container in the ECS cluster… Continue reading Useful Health Check Endpoints in PHP Applications
Symfony Logout Handlers vs Logout Success Handlers
Important note: logout and logout success handlers are now deprecated in Symfony 5.1, instead there's a new LogoutEvent to listen for and use. Symfony's security configuration for logout functionality in a firewall has a few handler keys that are worth digging into: Logout Handlers These are defined in the handlers key of the configuration above… Continue reading Symfony Logout Handlers vs Logout Success Handlers
Custom User Provider Factories for the Symfony Security Bundle
Symfony has some great documentation on adding custom security authentication providers, but there is a similarly mature system for user providers. While there is support for custom user providers already which are defined as services within an application, I was looking for a way to provide something similar to the way memory user providers work:… Continue reading Custom User Provider Factories for the Symfony Security Bundle
Testing Custom League OAuth2 Client Providers
This week I had to create a custom league/oauth2-client provider to talk to an private OAuth 2 server (also courtesy of The PHP League). Most of this is pretty routine. Implement some getters that are used in a few template methods. Most of those getters are public and easy to test, but a few of… Continue reading Testing Custom League OAuth2 Client Providers
Making Multiple Instances Play Nice with Symfony’s Autowiring
Symfony's autowiring is one of the best things to come to the framework in the 3.X series. Without it we would all still be extending ContainerAware base classes and be using a service locator. But what if we need multiple instances of somethign in the container? The docs talk about dealing with multiple implementations of… Continue reading Making Multiple Instances Play Nice with Symfony’s Autowiring
Improving Symfony ChoiceType Error Messages
The Symfony ChoiceType is a complex, interesting beast. By far my biggest complaint about it is the error messages shown to the user during validation are not great. Defaulting to, "This value is not valid," with no help for the user on what values are actually allowed. That's okay for plain HTML interfaces where the… Continue reading Improving Symfony ChoiceType Error Messages