How to add a class to Composer for autoloading?

autoloader, composer-php, php

Solution

Here's an example of using composer.

{
  "autoload": {
      "psr-0": {"AppName": "src/"}
  }
}

Set the structure as follows:

 src/
   - AppName/
 vendor/
 composer.json
 index.php

place any classes inside the AppName folder, use a namespace for the class relative to src folder.

Classes should have the same filename as class name starting with a capital, for example a class called Demo in AppName:

<?php namespace AppName;

class Demo {

   public function __construct(){
    echo 'hi';
   }
}

Then in the root create index.php include the autoload from the vendor once composer has been installed.

To use any class call its namespace followed by the class name

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

$demo = new \AppName\Demo();

Problem

I have a class called `class.feed.php`, how do I include it to Composer such that when 'vendor/autoload.php' is included or required in my for example `index.php`, the class will also be included? Note, am still a PHP newbie.

Original source