May 16

Please Learn to Write

May 12

I have been working on multiple Silex services, as well as templates for creating console and web applications.

I’ve found using Silex to be far easier than using Symfony directly. I still have access to all of the Symfony components, and it’s trivial adding support for more. While I completely understand Symfony’s push for using bundles, it requires a huge learning curve. In an effort to make using Silex even easier, I developed the Config, Doctrine, and Log service/service providers. I also created a template for web applications.

Config

The Config service has three things covered:

  1. Support any file type
  2. Support caching
  3. Be re-usable

The service is designed so that the file parsing responsibilities are delegated to classes that implement a specific interface. These classes can be registered with the service in order to offer support for those file formats. The service itself includes support for the INI, JSON, and YAML formats.

Caching is accomplished by taking the parsed result and exporting it as a native PHP variable into its own script. When subsequent requests are made for the same configuration file, the script is simply require()’d instead of running through the parsing process again. The service supports automatic refreshing of the cache, but this is disabled by default.

The service itself is separate from the service provider used by Silex. This makes it possible to re-use the whole service for different purposes. This is evident in the Translation adapter that is included with Config. The Translation adapter replaces the loader used in the TranslationServiceProvider bundled with Silex with our own. The new loader uses a separate instance of the Config service to load messages from any of the file formats supported.

Doctrine

The Doctrine service provider is a drop-in replacement for Silex’s DoctrineServiceProvider. My service actually registers the original service, but then adds its own ORM service to the mix. The ORM EntityManager is created using DBAL setup by the original service.

The Doctrine service provider supports all of the caching and mapping classes offered by Doctrine.

Log

The Log service provider registers the Log library with Silex.

Web Application Template

With all that said and done, you still have to glue all the pieces together in order to make Silex really do anything. That’s where this web application template comes in. It’s basically a pre-made Silex web application. At its default setup, all you can do is register routes and services using YAML, and then launch the registered route controllers.

Included with the web application is a service configuration file that has a bunch of defaults. Simply uncomment the services you would like to use, install the package using Composer, and you have a fully functional service. The services configured are:

  • Doctrine (DBAL/ORM)
  • Log
  • Monolog
  • Session
  • Swiftmailer
  • Symfony Bridges
  • Translation (Config)
  • Twig
  • URL Generator
  • Validator (Config)

The goal is to quickly setup your basic web application so you can get the scaffolding setup process out of the way.

Console Application Template

After finishing the web application template, I thought I could do the same with creating command line PHAR applications. Composer was my inspiration for this project, seeing how useful PHARs could be. After only a few hours of coding, I came up with this console application template.

What it can do:

  • Make registering your Symfony Console commands simple
  • Test your application by using it, or running PHPUnit
  • Compile it with all dependencies included

All that is left for you to do is create your commands, update the Application class with your app name, version, and commands, and write your own test cases.

Apr 30

Silex Config Service

Config is a Silex service that uses files to store data in a variety of formats. The service also supports caching, which bypasses the parsing process, giving you a performance boost. The service supports INI, JSON, and YAML formats, but support for other formats can be easily added as needed.

Apr 06

PHP Logging Library

This is a powerful PHP logging library. Its power is derived from its modular design, which allows developers to store log messages in any storage medium and format they desire. If the bundled classes don’t provide the functionality desired, the included interfaces will make creating and integrating new functionality seamless.

Mar 09

Is Internet Explorer crashing on a particular web page with the message “Operation Aborted”?

If you are using jQuery, it is likely that you are attempting to modify the DOM before Internet Explorer is ready. To work around this issue, you will want to have your code execute once the document has finished loading.

$(window).ready(function () {
    /* Your code */
});

Very simple!

Me on Twitter

loading...

Submit

Ask me a question!