Tag Archives: PHP

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.

Include PropelORM in a PHP project

PropelORM is an open-source Object-Relational Mapping (ORM) for PHP5. It allows you to access your database using a set of objects, providing a simple API for storing and retrieving data.

In this article, I’ll explain how to use PropelORM in an existing PHP project.

Continue reading

No tips yet.
Be the first to tip!

Like this post? Tip me with bitcoin!

1B4Y9jVAvHC2kytvq9HF6xTCKGDp9HzLft

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.

Comics Calendar

I’m an avid comic books reader, mostly from the Marvel franchise (X-Men, Spider-Man, Avengers…), and some DC too (Batman, Superman…). But every series has its own monthly release date, which makes difficult to follow what the current issue is for a series.

That’s why I’ve developed an on-line calendar that regroups the release dates for all new comic books issues. The data are retrieved from ComicVine, which is a huge wiki-based website for comics.

Continue reading

No tips yet.
Be the first to tip!

Like this post? Tip me with bitcoin!

19nHnzpdP3oXKUtEw9J2N6p1SSAFxj1UEY

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.

RSS Reader v.0.2.0

I’ve continued working on my new project, RSS Reader, which is now in version 0.2.0.

The new version brings the following changes:

  • mobile website: I’ve created a mobile version of the website by using jQueryMobile. The mobile version can only be used as read-only (you can’t add new feeds or make any change on the existing ones).
  • sortable feeds list: by using the sortable widget from jQuery UI, you can now re-order your feeds, drag and drop them to another category…
  • when you decide to read an article as the original webpage in an iframe, or as the feed content, your choice is saved for the next times you open this feed.
  • you can now navigate through entries with your keyboard (”N” for the next entry, “P” for the previous one).
  • the application cleans old entries: each time the feeds are updated, it deletes old entries from the database: a maximum of 300 entries / 100 read entries is kept for each feed.

The next functionalities I’d like to implement are:

  • list the entries from a whole category
  • more functionalities on the mobile website (mark as read, unread…)
  • edit an existing feed (change the feed link, the name…)

Don’t hesitate to download, test, fork, and comment on this project, which is released under the MIT License.

No tips yet.
Be the first to tip!

Like this post? Tip me with bitcoin!

12bToS5UTHybpRietNXsuHrZFspWRD1yih

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.

RSS Reader – A self-hosted RSS aggregator and reader

A few weeks ago, Google announced they would stop their service Google Reader on July 1, 2013 (original post). I have never used this service to read my RSS feeds, prefering to use Netvibes, mainly because it’s been developed by a French company, but also because I like the UI better.

But this announce has made me think. Every now and then, we hear about another service being shut down. Google, which regroups a huge part of the webapps used in the world, has his traditionnal Spring Cleaning. Other companies have closed worldwide-used websites. You can never know how long you’ll be able to use a specific service.

This is the reason I’ve decided to develop my own RSS aggregator and reader, to allow me to take control over my personnal data.

Continue reading

No tips yet.
Be the first to tip!

Like this post? Tip me with bitcoin!

1BwpuKTCqv1LTehcYi1RYBqDYgQw3NKF7r

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.