Kategorie-Archiv: Development

A link to your Call for Papers

You have an upcoming conference for which you run a Call for Papers (CfP)? Then why not let everyone know by adding a link to where we can find more informations?

Something like the following could be parsed automatically and would allow easier finding of your CfP:

<link rel="cfp" href="[Link to your CfP-page]" data-closes="[ISO-Date of the end of the CfP]"/>

This could then look like this:

<link rel="cfp" href="https://example.com/cfp" data-closes="2015-12-24 12:00:00+02:00" />

That way websites displaying CfPs could fetch the information that there is a CfP from your main website and you would not need to provide extra informations about a CfP on a different place.

And while we’re at it: Your Event surely has a geographical location, so why not add that one via the following resource?

<link rel="venue" href="geo:[latitude],[longitude]"/>

It uses a geo-URI as specified in RFC5870 and can therefore also been read automatically to check for the venue of your event.

Database-Testing with PHPUnit and sqlite

Today I wanted to test a database-handling class using PHPUnits PHPUnit_Extensions_Database_TestCase and an sqlite in-memory database.

On running the tests I always got the following error-messages:

MyDatabaseTest::testDatabaseConnection with data set #0 ()
PHPUnit_Extensions_Database_Operation_Exception: COMPOSITE[TRUNCATE] operation failed on query:
                DELETE FROM "[tablename]"
             using args: Array
 [SQLSTATE[HY000]: General error: 1 no such table: [tablename]]


After some checking what might help I got different solutions:

  • Use MySQL as test-backend – No, I want to use an sqlite with in-memory storage as it’s fast and doesn’t require too much setup on a CI-Server
  • Use a pre-configured sqlite-file and therefore a file-based sqlite. That might have been possible, but I just wanted to use in-memory….

The solution was rather simple. It seems that PHPUnit deletes the content of the table in question before setting up the table to execute a test. That only works, if the table already exists. Therefore I’ve added a create table xyz statement right after setting up the in-memory-table. So the test-class now looks like that:

class MyDatabaseTest extends PHPUnit_Extensions_Database_TestCase
    protected $pdo = null;

     * @return PHPUnit_Extensions_Database_DB_IDatabaseConnection
    public function getConnection()
        if (null === $this->pdo) {
            $this->pdo = new PDO('sqlite::memory:');
            $this->pdo->exec('create table [tablename]([table-definition])');
        return $this->createDefaultDBConnection($this->pdo, ':memory:');

     * @return PHPUnit_Extensions_Database_DataSet_IDataSet
    public function getDataSet()
        return $this->createXMLDataSet('[path/to/xml-seed-file]');

    public function testDatabaseConnection()
        $pdo = $this->getConnection()->getConnection();
        // Do your database-tests here using the required pdo-object

Perhaps this can help someone to find a solution earlier 😉

Displaying Date-Ranges

Recently a new issue popped up on the joind.in issue-tracker which called for nicer date-ranges. As I did something like that a few weeks prior I grabbed the issue and starded working.

The output is a small library that enables you to display a date-range like 12. – 13. March 2015 instead of 12. March 2015 – 13. March 2015.

Simple thing.

It also displays March 12th – March 13th 2015 if you want to.

Not that easy any more.

I won’t bother you with the details on how it’s done (it seemed more difficult than it actually was) as you can see that in the source-code if you are interested.

Displaying Date-Ranges weiterlesen

New and cool features in PHP5.6

PHP5.6 is, at the date of writing this, in the first beta phase. So the good question is: What new and cool features can we expect in the shiny new PHP-Version?

  • Exponential operator
  • importing namespaced functions
  • constant scalar expressions
  • variadic functions
  • argument unpacking
  • phpdbg
  • Streams for POST-data
  • Default Character-Encoding improvements
  • TLS improvements
  • More „under-the-hood“-Improvements

For a full list of changes have a look at the RFC-Part of the php.net wiki

New and cool features in PHP5.6 weiterlesen

Create signed PDF-Files

Some days ago a friend of mine asked me how to create PDF-Receipts. Background is that – at least in Germany – you can replace printed receipts with digitally signed PDF-Files. The signature has to comply to certain legal standards to be able to replace the printed copy but the way is the same whether it’s a self-signed certificate or an official one.

For the start I wanted to see how to sign a PDF-Document created with TCPDF. At a later time I will also have a look at how to sign a PDF-File using the libraries supported by PDFlib.com.

Signing PDF-files with TCPDF requires you to have the private key and the certificate available via a stream-ressource. That excludes certificates and keys on a signature-card as long as you can not export them.

Creating a signed PDF-File using TCPDF is rather simple as you can see in this code-snippet:


// set certificate file
$certificate = 'file://' . __DIR__ . '/cert/certificate.crt';
$privateKey = 'file://' . __DIR__ . '/cert/privateKey.crt';
// set document signature
$pdf->setSignature($certificate, $privateKey, 'test1234', '', 1, array());

// Do some more stuff here like creating the actual PDF-File

//Close and output PDF document
$pdf->output('test.pdf', 'D');

That’s it.

The hard part now is for one thing creating the actual PDF-File.
And the more important one question was „Which certificate-key-thingy goes where“.

That was the one that took me most of the time. When using a self-signed certificate as described in the TCPDF-Example you can somehow use the given openSSL shell-lines to get somehow to a result. But I wanted to sign the document with a „qualified electonical signature“ which takes some more steps.

What is a qualified electronical signature? It’S nothing else than any other digital signature from a certification authority. The only difference is, that it has been issued according to the german „Signaturgesetz“ which means, that it is based on a qualified certificate and has been created using a certain approved PKI. As I am not a lawyer, this is simply my own description of a legal process which might be inaccurate or plain false. So do not take my word as legally authoritative. A list of issuers for qualified electronical signatures can be found at http://www.nrca-ds.de/ZDAliste.htm

As I do not posses such a qualified electronical signature (and there currently is no need for me to get one) I tried the whole stuff with a certificate I got myself from CA-Cert. As far as I know (but I will verify that one soon) you can export a qualified electronic signature into a format that can be used for these purposes.

The relevant parts are the following variables

needs to point to a certificate file in PEM-Format. Thats a plaintext-file with —–BEGIN CERTIFICATE—– and —–END CERTIFICATE—– and some base64 encoded stuff in between.
needs to point to a private key file in binary PKCS7-Format. Those files normally end in something like ‚.p12‘ or ‚.pfx‘. To open this file you normally need a passphrase which you have to provide as third parameter to $pdf->setSignature.

Using that certificate and private key you can now sign your PDF-file.