Category Archives: Development

Moving a PHP project to Composer

A few months ago, I’ve discovered Composer, which is a dependency manager for PHP (you can compare it to Maven, for Java). With Composer, you can simply checkout the main project, and install the dependencies.

The transition to a Composer project is very easy, so I decided to start using Composer in my ComicsCalendar project. In this post, I’ll explain how you can migrate to Composer for a very simple project (in this case, using PropelORM to access your databases).

The project structure at the start of this work is:

- comicslist
    - application
        + build
        + config
        + controllers
        + helper
        - plugins
            + propel
              recaptchalib.php
        + views
          build.properties
          propel-gen
          runtime-conf.xml
          schema.xml
    + static
    + system
      .gitignore
      .gitmodules
      .htaccess
      index.php

1. Install Composer

It’s really easy to install Composer. Just follow the instructions on the official documentation.

In the following commands, I’ll assume that you’ve installed Composer so you can run it with:

$ composer

2. Create the setup file

Each Composer project requires a composer.json file. This file (equivalent to the pom.xml file for Maven), contains a list or the project dependencies (and lots of other things I won’t mention here).

Create a composer.json file at the root of your project:

{
    "require": {
        "propel/propel1": "1.7.1"
    }
}

As you can guess, this will install version 1.7.1 of PropelORM.

This is the only dependency you will install right now (Composer automatically installs the dependencies of your dependencies).

3. Install the dependencies

To install the dependencies, run from the project root:

$ composer install

This command created the vendor folder (if it doesn’t exist), and the vendor/autoload.php file, which contains the list of files to include into the project.

4. Include the dependencies in the project

The work is almost done, you just need to include the dependencies in your project. As I just explained, the file vendor/autoload.php contains the dependencies you need to include.

Just include this file in any “global” PHP file:

<?php
require_once('vendor/autoload.php');

5. Clean-up the project

The last action is to clean-up the project from the previous Propel installation. Remove the application/plugins/propel folder (which contains the old Propel classes), the .gitmodules file (which contains references to the Git sub-modules), as well as the reference to the main Propel script (which is now referenced in the autoload.php file).

6. Configure Git

If you’re using Git to track your sources, you’ll need to add a few changes to your project.

Add a .gitignore file at the root of the vendor folder, containing:

*
!.gitignore

This will allow you to commit the vendor folder, without any sub-folders (those will be re-created when running $ composer install).

You also need to add the composer.json and composer.lock files. The composer.lock file contains the actual versions of all your dependencies (since you can specify ranges in the versions), so someone who installs the dependencies will have the same versions as you do.


You’re now ready to keep using PropelORM, and add new dependencies that could help you (yes Monolog, I’m looking at you…).

No tips yet.
Be the first to tip!

Like this post? Tip me with bitcoin!

16XaKtprp6XZkfnND1cFRxqewmpEvahiLz

If you enjoyed reading this post, please consider tipping me using Bitcoin. Each post gets its own unique Bitcoin address so by tipping you're not only making my continued efforts possible but telling me what you liked.

Customer

Good customer relation – Snipt

Some time ago, I signed up on Snipt, a website that allows you to store snippets. It was a free account, that I probably used once, to test the service (only because this was not something I needed).

But yesterday I received an email from them, announcing that they will move away from free accounts. This is a fair enough decision, I can understand the need for a stable income.

Lots of services start with free accounts, and then cancel them (see my recent post on DynDNS). But the email I received from Snipt was written to keep good relations with all users, the ones that will upgrade to a paying account, and the ones that don’t have the need or the will to do it:

I’m an existing user. What happens to my data?

Nothing. As an existing user, your snipts will remain intact and usable even if you decide not to upgrade. You can edit your existing snipts, delete, embed, etc. If you would like to create new Snipts, you’ll need to upgrade to the paid plan.

That’s a very good decision. You don’t lose anything that you’ve stored with them, you don’t need to save everything before it’s deleted… Other companies should have a look and learn something…

But what made my day was this part:

Can you suggest an alternative to Snipt?

Gist is an excellent alternative to Snipt.

For me, this is the sign that this company wants what’s best for its users. It’s not only about the money, it’s about allowing users to get the best service for what they’re ready to pay. “We could say that no free service is any good, but we won’t. We’re moving to paying accounts, but if you don’t want to, you can use this other good service.”

Thank you Snipt!

Photo: Customer, by 10ch via Flickr (CC BY)

No tips yet.
Be the first to tip!

Like this post? Tip me with bitcoin!

19E63z6v5d8mrbMD7NMSmhBizYnf1AfWf8

If you enjoyed reading this post, please consider tipping me using Bitcoin. Each post gets its own unique Bitcoin address so by tipping you're not only making my continued efforts possible but telling me what you liked.

RSSReader 0.3

I’ve released a new version of my RSS reader.

You can find all the information about this release here.

No tips yet.
Be the first to tip!

Like this post? Tip me with bitcoin!

1LgT3P9b6cemk4cZ53NFY5eiFNaAWhYv7H

If you enjoyed reading this post, please consider tipping me using Bitcoin. Each post gets its own unique Bitcoin address so by tipping you're not only making my continued efforts possible but telling me what you liked.

Play! Framework and Heroku

I’m currently developing a web application in Java. To do so, I’m using the Play! Framework, which is a

High Velocity Web Framework For Java and Scala

This framework allows you to quickly build web applications with Java (and Scala, but I’m sticking to Java for now).

You can find the tutorial for a todo list application here. This tutorial allows you to create a very basic application and deploy it in less than an hour (excluding the framework and tools download and installation time).

The application I’m working on is a Kanban board, similar to Trello, that you can host on your personal server, or, in my case, on Heroku.

Heroku is a cloud application platform, based on Amazon AWS, which allows you to deploy and host applications with git. They offer a free hosting option, which includes 1 dyno (their own unit of computing power), and a PostGreSQL database that can contain 10k rows. This should be enough for you to test your application, and a free option is always welcome. You can then pay for additional dynos, DB options, and add-ons (data stores, logging, emails,…). See the pricing details here.

My application is still in development. I’m trying to learn how to use Play!, and also playing with the UI. You can find it here.

No tips yet.
Be the first to tip!

Like this post? Tip me with bitcoin!

1837rfz2wvTw7PnZWvk6zaK6Eoq7Jt26Zj

If you enjoyed reading this post, please consider tipping me using Bitcoin. Each post gets its own unique Bitcoin address so by tipping you're not only making my continued efforts possible but telling me what you liked.

Reset a Heroku database

I’m currently developing a Play! application, and I use Heroku to deploy and test it.

But sometimes when deploying it, the application crashes when trying to start up. What happens is that the database contains data that are in conflict with the new schema that I’ve deployed (eg. new required foreign keys that don’t have a value…).

To fix this, the easiest way I’ve found is to reset my Heroku database. When connected to Heroku (with the Heroku Toolbelt), just run

heroku pg

which will display the list of your databases, then run

heroku pg:reset HEROKU_DATABASE_SOMEBASE

which will reset your database HEROKU_DATABASE_SOMEBASE.

Then you can restart your application with

heroku restart

and everything should be working fine.

No tips yet.
Be the first to tip!

Like this post? Tip me with bitcoin!

16dVFMiAWZ8kFY4QqTQewTQsbJUqzhWtPa

If you enjoyed reading this post, please consider tipping me using Bitcoin. Each post gets its own unique Bitcoin address so by tipping you're not only making my continued efforts possible but telling me what you liked.