Migrating user table from Mysql to Postgres with Symfony and Doctrine

When using bin/console make:entity on Mysql and then later you switch your application to Postgres and you have a table called user, which you most likely have when using security component of Symfony.
Then you will receive an error because user is a reserved word in Postgres!

An exception occurred while executing 'INSERT INTO user (id, email, roles, password, is_verified) VALUES (?, ?, ?, ?, ?)' with params [3, "dev@dev.de", "[]", "your-encrypted-password", 0]:
SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "user"
LINE 1: INSERT INTO user (id, email, roles, password, is_verified) V...

Continue reading “Migrating user table from Mysql to Postgres with Symfony and Doctrine”

Recreate pruned docker networks with docker-compose

So here is nice chain of docker errors and its solution.

1. Docker has reached its maximum of created networks and errors like this:

ERROR: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network

The easiest (and most brute though) solution to this is to prune all networks, as suggested here on SO.

docker network prune

This will delete all networks that are not connected to currently active containers.
But this also means it will delete all networks of your not runnning dev projects.
(Which might be numerous as in my case.)

Continue reading “Recreate pruned docker networks with docker-compose”

Migrating from gulp to esbuild

Esbuild is the new cool kid in the bundler world.
It is super fast since its written in Go and comes with a lot of builtin features for modern frontend development.

So i wanted to try it myself and migrated a former gulp build to esbuild.

But as it showed the gulp build was not so modern, as it was just Sass and Javascript minification. No ES6, No React, no JSX with inline styles.

So Esbuild was not working out of the box but needed some extra config and the Sass plugin.

npm i -d esbuild esbuild-plugin-sass

Also I had to rewrite the Javascript to use ES6 modules, but this was fortunatly easy.

Continue reading “Migrating from gulp to esbuild”

Passing a boolean to the constructor of “Symfony\Component\Dotenv\Dotenv” is deprecated

You might encounter this deprecation message after your upgrade to symfony 5.1 in your symfony project:

Since symfony/dotenv 5.1: Passing a boolean to the constructor of “Symfony\Component\Dotenv\Dotenv” is deprecated, use “Dotenv::usePutenv()

To fix this, go to config/bootstrap.php and remove the false from the Dotenv constructor:
(new Dotenv(false))->loadEnv(dirname(DIR).'/.env');
to
(new Dotenv())->loadEnv(dirname(DIR).'/.env');
See: https://github.com/symfony/symfony/issues/37195

Actually the file config/bootstrap.php has been removed from symfony 5.1 and was replaced in public/index.php.

But since the project was updated from an symfony 4 version the bootrap file is still present.

So another option would be to remove the boostrap file and update the project entirely to symfony 5.1 recipe.
This is not trivial though as you can see in this corresponfing PullRequest.

EU/VAT – Mehrwertsteuer Madness

Calculating European VAT Rates with PHP – the easy way.

Disclaimer: No legal advice, just a little experience report.

If you sell digital things (services, digital goods etc.) to EU countries, you might have to calculate the VAT at the rate of the customer’s country (and even pay it there afterwards).
The latter is even the more inconvenient part, but at least the first part can be done quite easily with good old PHP.

Continue reading “EU/VAT – Mehrwertsteuer Madness”

Directories settings in PHPStorm and IntelliJ Ultimate

I recently switched from PHPStorm to IntelliJ Ultimate because of some Java. But still i am working a lot on PHP and symfony projects.

One thing i usually do on symfony projects in PHPStorm is to edit the “Directories” in the settings to avoid having results from var/cache or var/logs in the search results.

Also it slows down the search which i heavily use. So i exlude all folders that should not be searched because they are cache files or are redundant in some other way.

Continue reading “Directories settings in PHPStorm and IntelliJ Ultimate”

SilverStripe with php built-in server

Sometimes you just want to check a SilverStripe version, module or theme fast and dont want to setup the whole stack.
Then simply use PHPs built-in webserver to serve your SilverStripe site.

php -S localhost:8000 ./framework/main.php

Now you can call http://localhost:8000 to check your SilverStripe website.

Or, a bit more verbose, use https://github.com/assertchris/silverstripe-serve
which is a nice wrapper around this.
Continue reading “SilverStripe with php built-in server”

Superleansilexplate Update v3

Some news from the Superleansilexplate:

  • v3 now uses symfony3 components
    Silex 1.3 supports symfony3 so lets use it :)
    Note: as symfony3 doesnt support php5.4 anymore, we dont either!
  • new ConsoleServiceProvider
    the one from knplabs that was used before seems to be unmaintained and wasnt matching the dependencies anymore.
    So i decided to take it over and renew it a bit. Check it out!
  • Docker support
    I started to use Docker as dev enviroment for my projects, so i added dev & prod Docker support.
    For the sake of simplicity it uses a single container with Apache and PHP7.
    If you have Docker and docker-compose on your machine just spin it up with docker-compose up and check on localhost:8088.

Continue reading “Superleansilexplate Update v3”

Symfony2 from YAML to XML configuration

Actually i was a fan of YAML regarding the configuration files of Symfony2.
This was probably because i was used to it since symfony 1.4 and i also thought its better readable.
Its partly still true, but my Netbeans Editor has some problems with using @ in YAML and this breaks my highlighting.
So the better readability vanished to nirvana.

So i checked out XML configuration. Its also widely used by the community.
Pros and Cons (mostly Pros) you can read in this post by Fabien.

Continue reading “Symfony2 from YAML to XML configuration”