I replaced another CMS powered site with an Astro powered static site the other day.
Here is why:
Import data into MySql with docker-compose
Having a docker-compose setup which involves a Database like Mysql or MariaDB, then at some point you might want to import data into those Databases.
There are several ways to import the data in your docker-compose setup.
- Using a volume for import data
- Using mysql client from commandline with docker-compose exec
- Using phpmyadmin in docker-compose setup
- Using a mysql GUI client on the host and connect to the DB in the Docker container
So let’s see how we can do this:
Continue reading “Import data into MySql with docker-compose”Nerdpress on Mastodon
We follow the PHP community and are now also Mastodon! Yay!
Follow us here: https://phpc.social/@nerdpress_org
All our Blog posts will be announced there as on Twitter.
Since we blog a lot about PHP in general and Symfony in particular https://phpc.social seems like a good choice for us as our Mastodon instance.
Continue reading “Nerdpress on Mastodon”Stream an image from Symfony controller
When sending an image/file from a Symfony controller you would usually read the file from filesystem.
This you can do by passing the file path to the BinaryFileResponse class and return it in the controller, as described in the docs:
https://symfony.com/doc/current/components/http_foundation.html#serving-files
use Symfony\Component\HttpFoundation\BinaryFileResponse;
$file = 'path/to/file.txt';
$response = new BinaryFileResponse($file);
Code language: PHP (php)
But in some cases you might want to create an image dynamically and return it directly from the controller without storing it on the filesystem.
So you can create your image with the GD library and directly stream the GDImage object from the symfony controller with the StreamedResponse class.
Doctrine migrations and Postgis
Using Postgres with the Postgis extension to integrate GeoData / GIS functionality in your project is not natively supported by Doctrine and Doctrine migrations.
First you have to add the extension to Postgres, even if you use the Postgis docker image like postgis/postgis:14-3.3-alpine
.
So add this SQL statement to the up method of your first migration:$this->addSql('CREATE EXTENSION IF NOT EXISTS postgis;');
and the DROP statement for the extension to the down method:$this->addSql('DROP EXTENSION postgis;');
Now, when using Doctrine with Postgres and Postgis extension, migrations still behave a bit odd and try to remove Sequences created by Postgis, because Doctrine migrations does not take Postgis extension’ s built-in Sequences into account.
Continue reading “Doctrine migrations and Postgis”Show kubernetes secrets with k9s
If you want to show decrypted secrets of your kubernetes (k8s) deployment with k9s try this:
First choose the namespace you want to check the secrets in by typing a colon and namespace
Continue reading “Show kubernetes secrets with k9s”Symfony deprecation log channel
Are you annoyed of too many deprecation warnings in you logs of your symfony app?
Probably yes because it is really a lot of noise.
However deprecation logs are still useful to ensure future compatibility of your app.
So since version 5.1 symfony will log deprecations to a dedicated log channel when it exists and ships with this monolog config:
monolog:
channels:
- deprecation # Deprecations are logged in the dedicated "deprecation" channel when it exists
Code language: PHP (php)
This is added already in the recipe and ships when installing symfony.
Ok, but the handler for this deprecation channel is not configured, so you have to do this yourself.
How? Add this to your monolog config:
Converting umlaute with symfony String component
There are multiple PHP native ways to convert umlaute and other special characters to ascii save formats, but most of them i experience insufficient in the one or other way.
Since i am using symfony anyway i can use the String component which has a handy slugger which converts any characters into safe ascii characters.
It is very flexible and can be customized with locales, custom replacements and closures.
$umlautString = "Müller Meier";
$slugger = new Symfony\Component\String\Slugger\AsciiSlugger('de');
$slugger->slug($umlautString, $seperator = ' ')->toString();
echo $umlautString; // mueller meier
Code language: PHP (php)
I guess this will become my go-to method resp. slugger to convert umlaute in any PHP application.
Continue reading “Converting umlaute with symfony String component”Silverstripe file credits addon
I released a new small Addon (or Module or Plugin) for SilverStripe CMS which adds a credits tab to the FileAdmin, so you can add f.e. the copyright holder of the image or any file.
Useful when you need to name credits, licence and source links for any asset used on your SilverStripe site.
https://github.com/ivoba/silverstripe-file-credits
https://packagist.org/packages/ivoba/silverstripe-file-credits
https://addons.silverstripe.org/add-ons/ivoba/silverstripe-file-credits
Disable SilverStripe deprecation warnings in PHP8.1
Since SilverStripe 4.10 is not yet fully ready for PHP8.1 you wil receive quite some deprecation warnings in dev mode when you are brave and run it nonetheless on PHP8.1.
Deprecated: SilverStripe\Config\Collections\MemoryConfigCollection implements the Serializable interface, which is deprecated. Implement __serialize() and __unserialize() instead (or in addition, if support for old PHP versions is necessary) in /var/www/html/vendor/silverstripe/config/src/Collections/MemoryConfigCollection.php on line 13
Unfortunatly we can’t control the error_reporting from SilverStripe since it is set in the kernel of the framework.
So we are forced to hack the Kernel which is rather unfortunate.
In the SilverStripe Slack channel someone proposed to use composer-patch which will apply a patch to a given vendor dependency during composer install.
This is quite cool because you don’t need to fork the dependency and take care of getting upstream changes.
So i went this path down and it looks like in this gist:
https://gist.github.com/ivoba/d8c4379236149a8c42e1922ae98a93e3