A (tiny, incomplete, single user, write-only) ActivityPub server in PHP


Screenshot of a map. There is a pop-up containing an image of me drinking a pint.

I've written an ActivityPub server which only allows you to post messages to your followers. That's all it does. It won't record favourites or reposts. There's no support for following other accounts or receiving replies. It cannot delete or update posts nor can it verify signatures. It doesn't have a database or any storage beyond flat files. But it will happily send messages and allow itself to be followed. This shows that it is totally possible to broadcast fully-featured ActivityPub…

Continue reading →

Rewriting OpenBenches in Symfony


The Open Benches logo.

I once described my ideal coding environment to a colleague as "telneting directly into prod and damn the consequences!" I jest. But only a little. When I build for myself I treat best practices and coding styles as harmful. Chaotic evil but, hey, it's only myself I'm hurting. Anyway, my wife and I run a hobby site - OpenBenches.org - which was coded in a long alcopop fueled weekend. It's fair to say that it has exceeded our expectations in terms of people getting involved. But is…

Continue reading →

Getting Auth0 user information on non-firewall Symfony pages


Logo of the Symfony project.

I am using Auth0's Symfony library to allow users to log in with their social network providers. It works really well. Using this firewall configuration, a user who visits /private is successfully taken through the login flow and I can then use $this->getUser() to see their details. security: password_hashers: Symfony\Component\Security\Core\User\PasswordAuthenticatedUserInterface: 'auto' providers: users_in_memory: { memory: null } auth0_provider: …

Continue reading →

Doctrine - difference between bindValue() and setParameter() on prepared statements


Doctrine project logo.

This pissed me off and I couldn't figure out what I was doing wrong. So I'm blogging about my ignorance. Imagine you're using Symfony and Doctrine to access a database. You are using prepared statements to prevent any SQL injection problems. There are two main ways of doing this - and they disagree about how positional variables should be specified. Data Retrieval And Manipulation Here's a fairly trivial SQL statement with a couple of variables: $sql = "SELECT `userID` FROM `users` WHERE…

Continue reading →

Symfony - multiple paths to the same route within a controller


Logo of the Symfony project.

I couldn't work out how to use Route Aliasing within my controller. I couldn't find anything in the documentation about it. But, thanks to a StackOverflow comment it is possible. Suppose you want users to be able to access a page using /users/123 and /people/123 - with both routes displaying the same data? Normally you'd write something like #[Route('/user/{id}', name: 'show_user')] - as it happens, that first parameter can be an array! Which means you can write: <?php namespace…

Continue reading →

Fixing a weird issue with Symfony's Cache


Logo of the Symfony project.

I'm just getting started with Symfony, so I'm blogging some of the weird things I'm finding. Symfony has a concept of Cache Contracts. You can call an expensive / slow / intensive operation and immediately cache the result for a specific time period. Next time you call the operation, the results are served from the cache until the expiry time has been hit. Nifty! But I couldn't get it to work. Take this sample code. It should return the current date and time and cache the result for 5…

Continue reading →

Doctrine - how to use LIKE with dbal prepared statements


Logo of the Symfony project.

I'm just getting started with Symfony, so I'm blogging some of the weird things I'm finding. I want to use Doctrine dbal to search a database for a partial match. For example searching for "smith" should find "blacksmith" and "smithy". I have a prepared statement like this: $queryBuilder = $conn->createQueryBuilder(); $queryBuilder ->select("whatever") ->from("table") ->where("name LIKE '%?%'") ->setParameter(0, $query); …

Continue reading →