Lukas is a freelance web and mobile developer based in Manchester in the North of England. He's been developing in PHP since moving away from those early days in web development of using all manner of tools such as Java Server Pages, classic ASP and XML data islands, along with JavaScript - back when it really was JavaScript and Netscape ruled the roost. When he's not developing websites and mobile applications and complaining that this was all fields, Lukas likes to cook all manner of World foods.

Lukas's articles

  1. Getting Started with Assetic

    There was a time when asset management meant little more than inserting a <link> tag or two and a couple of <script> tags into your HTML.

    Nowadays, though, that approach just won’t cut it. There’s performance, for one thing. Assets are a significant performance drain both in terms of file size and the number of HTTP requests – optimizing both has become an essential part of the development process. This has been exacerbated by the proliferation of mobile devices.

    Also, as client-side applications have become more and more sophisticated, managing dependencies amongst scripts and libraries has become increasingly complex.

    Furthermore, technologies such as Less, Compass and Coffeescript require assets to be compiled, adding yet another step to the process of managing assets.

    In this article I’m going to look at a PHP package called Assetic which helps manage, compile and optimize assets such as scripts, stylesheets and images.

  2. Introduction to JadePHP

    There are dozens of templating engines out there, with options such as Smarty, Twig (used in the upcoming version of Drupal) and Blade (the default for Laravel) among the best known – as well as vanilla PHP, of course. Stepping away from PHP specifically, eRuby / ERB and Haml for Ruby / Ruby on Rails, and Javascript has scores of popular choices including Mustache, Handlebars, Hogan and EJS. Some have subtly different syntax, some more markedly so.

    One which differs quite significantly from most is Jade, an engine usually associated with Javascript applications – it’s supported out-of-the-box by Express for Node.js, for example. It’s Jade I’m going to look at in this article; or more specifically the PHP port JadePHP.

    Haml and Jade

    It would be remiss to talk about Jade without mentioning Haml, from which Jade takes its inspiration – and indeed there are several libraries for using Haml with PHP. Jade shares its overall philosophy, which is to make templating “beautiful” and use what the authors describe as templating “haiku”. Whatever that actually means, there’s no denying Haml and Jade do share some characteristics which make them fundamentally different to most templating languages.

    What’s the Difference?

    Most templating engines involve writing the target markup and “injecting” it with placeholders and / or basic logic – a superset, in a sense. Jade still has placeholders and logic, but also provides a shorthand for writing XML-like elements. Generally that means HTML, although you can also use it for things like RSS as well as XML itself.

    In fact if you wanted to, you could just use Jade as a shorthand for HTML without taking advantage of its more “traditional” templating features.

    How to use the Repository

    Rather frustratingly, the code is not currently available via Composer – although it should be a simple enough task to package it up, if anyone has an hour or two. You can get it to to work, however, by cloning the repository and include‘ing or require‘ing the included autoload.php.dist (the Github repository includes Symfony’s UniversalClassLoader).

    Here’s an example, adapted from the one in the project’s README, which assumes that the repository has been downloaded into a directory called jade:

    require('./jade/autoload.php.dist');
    
    use Everzet\Jade\Dumper\PHPDumper,
            Everzet\Jade\Visitor\AutotagsVisitor,
            Everzet\Jade\Filter\JavaScriptFilter,
            Everzet\Jade\Filter\CDATAFilter,
            Everzet\Jade\Filter\PHPFilter,
            Everzet\Jade\Filter\CSSFilter,
            Everzet\Jade\Parser,
            Everzet\Jade\Lexer\Lexer,
            Everzet\Jade\Jade;
    
    $dumper = new PHPDumper();
    $dumper->registerVisitor('tag', new AutotagsVisitor());
    $dumper->registerFilter('javascript', new JavaScriptFilter());
    $dumper->registerFilter('cdata', new CDATAFilter());
    $dumper->registerFilter('php', new PHPFilter());
    $dumper->registerFilter('style', new CSSFilter());
    
    // Initialize parser & Jade
    $parser = new Parser(new Lexer());
    $jade   = new Jade($parser, $dumper);
    
    $template = __DIR__ . '/template.jade';
    
    // Parse a template (both string & file containers)
    echo $jade->render($template);
    

    This will compile the file template.jade and echo its contents.

    Where you actually use this depends on your workflow, whether you’re using a framework, and so on. You could, perhaps, use a service such as Watchman, Guard or Resource Watcher to watch the filesystem for changes to your Jade templates, and compile them at the appropriate time during the development process.

  3. Abstract File Systems with Flysystem

    Reading and writing files is an integral aspect of any programming language, but the underlying implementation can vary enormously. For example, the finer details of writing data to the local filesystem compared to uploading over FTP is very different – yet conceptually, it’s very similar.

    In addition to old warhorses like FTP, online storage is increasingly ubiquitous and inexpensive – with scores of services available such as Dropbox, Amazon’s S3 and Rackspace’s Cloud Files – but these all use subtly different methods for reading and writing.

    That’s where flysystem comes in. It provides a layer of abstraction over multiple file systems, which means you don’t need to worry where the files are, how they’re stored, or need be concerned with low-level I/O operations. All you need to worry about are the high-level operations such as reading, writing and organizing into directories.

    Such abstraction also makes it simpler to switch from one system to another without having to rewrite vast swathes of application code. It also provides a logical approach to moving or copying data from one storage system to another, without worrying about the underlying implementation.

    You can use Dropbox, S3, Cloud Files, FTP or SFTP as if they were local; saving a file becomes the same process whether it’s being saved locally or transferred over the network. You can treat zip archives as if they were a bunch of folders, without worrying about the nitty gritty of creating and compressing the archives themselves.

  4. Selling Downloads with Stripe and Laravel

    Digital goods are an increasingly valuable commodity. Whether you're a designer selling templates or font files, a developer charging for packages of code or a musician selling MP3s, selling digital goods online is often far easier than physical goods – with much lower production costs and no delivery charges. In this article I'll show how […]

  5. Building a Live-score Widget Using PHP Web Sockets

    The introduction of web sockets makes it possible for web applications to handle near real-time data without resorting to "hacks" such as long-polling. One example of an application requiring up-to-the-minute data is sports scores. Even now, many websites which display this information use Flash applications, since Actionscript provides the facility to communicate over socket-based connections. […]

  6. Responsive Images Using Picturefill and PHP

    One of the key challenges with responsive web design, and a subject of much discussion in recent years, is how to deal with images. Setting a max-width on image elements enables designers to allow their size to adapt to the page dimensions, but in itself that approach can lead to far bigger images being downloaded […]

  7. Introduction to Redbean

    An Introduction to Redbean When it comes to RAD and prototyping, there are lots of tools available to help get projects up-and-running quickly. From quick-starts to micro-frameworks, from build tools such as Composer to one-click installers, and of course ORMs – there are all sorts of ways to speed up development time. I'm going to […]

  8. Creating a Subscription-Based Website with Laravel and Recurly, Part 2

    This entry is part 2 of 2 in the series Creating a Subscription-Based Website with Laravel and Recurly

    This entry is part 2 of 2 in the series Creating a Subscription-Based Website with Laravel and RecurlyIn the first part of this series we created the bare bones of a subscription-based website using Laravel. We also set the site up with roles, and granted a pending role to new users. We’re now at the […]

  9. Creating a Subscription-Based Website with Laravel and Recurly, Part 1

    This entry is part 1 of 2 in the series Creating a Subscription-Based Website with Laravel and Recurly

    This entry is part 1 of 2 in the series Creating a Subscription-Based Website with Laravel and RecurlyScheduling and processing payments is easy, but don’t think recurring payments are trivial. Things can get complicated very quickly. You need to decide how to handle failures (how many failed payment attempts does someone get?), billing details must […]

  10. Running Tasks in the Cloud with IronWorker

    In this article I’m going to show you how we can use IronWorker to run code in the Cloud, just as if it were being run inside our PHP application’s code. There are a number of advantages to running tasks in the cloud, for example: processor-intensive tasks can be offloaded from your web server better […]