Testing PDF creation with headless chrome and PHP

I had the task the other day to use a headless chrome to generate PDF files from websites in a PHP app.

The plan was to use chrome-php with a headless chrome to generate the PDF.

Usually you would install chrome/chromium on a linux server via apt and just run chrome from the PATH with chrome.
Since i was on shared hosting i was not sure if this was possible since i was not allowed to run apt commands.
So i tried to use Puppeteer which ships a headless chrome executable and use just this directly.
I installed Puppeteer with npm locally and uploaded the chrome executable to the shared hosting.
Puppeteer will place the headless chrome in the .cache dir in your home directory, f.e.:



scp -r ~/.cache/puppeteer/chrome/linux-113.0.5672.63/chrome-linux64 me@sharedhosting:/usr/home/test

Continue reading “Testing PDF creation with headless chrome and PHP”

Class “Psr\Log\Test\TestLogger” not found

The psr/log package used to have not only the Interface for PSR-3 Logger, but also actual implementations of the interface like the TestLogger.
The TestLogger could be used as mock for any PSR-3 Logger in your test cases.

However from v3 the TestLogger was removed, so that the psr/log package would focus solely on the Interface.

If you used the TestLogger in your project and you or some of your dependencies upgraded psr/log to >= v3 you most likely saw this error:

Class "Psr\Log\Test\TestLogger" not found

Continue reading “Class “Psr\Log\Test\TestLogger” not found”

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”

Persistente Objekte in PHP und redirects

Achtung Falle!
Benutzt man persistente Objekte in PHP, die ungefähr so aufgebaut sind, wie hier beschrieben.

class User
public function __construct(){}

// save object to session variable
public function __destruct()
   $_SESSION['user'] = serialize($this);
// factory method
public static function factory()
   if(isset($_SESSION['user']) === TRUE)
      return unserialize($_SESSION['user']);
   return new User();

Continue reading “Persistente Objekte in PHP und redirects”

Grouping & Sorting in MongoDB

Will man mit PHP und MongoDB soetwas wie “SQL Aggregate Functions” umsetzen muss man sich etwas verbiegen.

MongoDb hat zwar eine group() function, die in etwa SQLs GROUP BY entspricht, allerdings kann man dies nicht kombinieren mit SORT oder LIMIT bzw den sort() und limit() Funktionen, da diese keinen Cursor zurückgibt sondern direkt ein Array.

Will man also sortieren und limitieren muss man sich des Map / Reduce features von MongoDB bedienen.

Continue reading “Grouping & Sorting in MongoDB”

Datei-Endungen im Vork Framework

Von Haus aus kommen im Vork Framework alle MVC Dateien ohne Endung daher.
Wer das ändern möchte kann folgende Dinge tun:

in der Klasse config in der Datei .config folgendes einfügen:

public $fileExtension = '.php';

dann erwartet vork im MVC Ordner Dateien mit der Endung .php.
Um alle Dateien umzubenennen braucht man eigentlich nur Windows Vista, eine präzise Maus und etwas Geduld.
oder folgende Zeile:

find /myVorkFolder/mvc -type f -exec mv '{}' '{}'.php ;

Continue reading “Datei-Endungen im Vork Framework”