VGTech is a blog where the developers and devops of Norways most visited website share code and tricks of the trade… Read more

Are you brilliant? We're hiring. Read more

Zend Framework 2


Swagger docs in ZF2 with examples – Part 2: Swagger UI


This blog post on Swagger UI is a follow-up on my recent post on Swagger annotation parsing in ZF2. If you’re not already set up with Swagger annotation parsing in you ZF2 app I recommend that you read part 1 first.

In the last post we got ZF2 set up with annotation parsing and everything, and the only thing missing was Swagger UI for the neat presentation. I skipped that previosly but today we’ll add the last piece. (more…)

Swagger docs in ZF2 with examples – Part 1: Setup and annotations


So everyone is building APIs now – parsing and outputting JSON is not that hard. Some people even build truly RESTful APIs, or something not to far from that.

Before, when building APIs was about SOAP with XML schemas and WSDL specifications, people spent so much time building their APIs that they had the time to think. Now, building an API is so easy and fast that the documentation is often suffering. Either because not much documentation is written in the first place, or because the API is evolving and nobody takes the time to update the documentation.

Swagger is a popular project providing auto generated API docs based on a service specification. This spec is based on annotation comments in the controllers and models, giving the developer a fairly easy, and close to the code way of keeping the API docs up to date.

In this two-part article on Swagger I will try to cover what you need to get your API docs up and running with Swagger + Swagger UI in ZF2. (more…)

Inheriting configuration in Zend Framework 2 applications


When working on Zend Framework 2 applications you might come across situations where you need to differentiate the application configuration for the different application environments, be it development, staging, testing and/or production. This can be cache TTL‘s, Memcached hosts, Redis hosts, debugging levels and more.

Instead of copy/pasting the complete configuration across multiple “environment”-configuration files or having switches in the code, like for instance:

Show code
if ($_SERVER['APPLICATION_ENV'] === 'development' || 
    $_SERVER['APPLICATION_ENV'] === 'testing']) {
    // ...

We wanted to use inheritance so that for instance the staging environment would inherit the complete production environment, with the exception of some caching configuration which we want to override in the staging configuration.

This post will explain how we solved this problem in one of our latest Zend Framework 2 applications.