Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Bootstrapping Your Own PHP App with Composer

Bootstrapping Your Own PHP App with Composer

Presented at Singapore PHP Meetup on 25 March 2014.

Michael Cheng

March 25, 2014
Tweet

More Decks by Michael Cheng

Other Decks in Programming

Transcript

  1. WHY? • Other frameworks seems too bloated for your project.

    • Need more visibility/transparency on how the app is put together. • Don’t like the default libraries provided by the other frameworks & no easy way to
 circumvent them.
  2. COMPOSER • Pick and choose libraries you want to put

    together on Packagist (https://packagist.org/). • Compose your own composer.json. • Choose a package namespace for your own project. • Reference: https://getcomposer.org/
  3. SAMPLE PROJECT • Requirement: • REST Server • MySQL backend

    • Logging. ! ! • Consideration: • No need for any views. • Simple CRUD app.
  4. SAMPLE PROJECT • Libraries • Respect/rest - (https://packagist.org/packages/respect/rest) • Monolog

    - (https://packagist.org/packages/monolog/monolog) • PHP-ActiveRecord - (https://packagist.org/packages/php- activerecord/php-activerecord)
  5. INSTALL LIBRARIES $ composer install! ! Loading composer repositories with

    package information! Installing dependencies (including require-dev)! - Installing respect/rest (0.5.0)! Downloading: 100%! ! - Installing psr/log (1.0.0)! Downloading: 100%! ! - Installing monolog/monolog (1.7.0)! Downloading: 100%! ! - Installing php-activerecord/php-activerecord (v1.1.2)! Downloading: 100%
  6. UNIT TESTS • Tests folder • bootstrap.php - Setup and

    server side includes. • phpunit.xml - Config for running PHPUnit. • *Test.php - The tests files.
  7. TEST SPEC • API Consumer should be able to: •

    Get list of blog posts. • Create a new blog post. • Delete the blog post he created.
  8. THE IMPLEMENTATION • TDD: Red, Green, Refactor. • Use your

    own namespace to take advantage of Composer’s autoload mechanism. • Don’t get ahead of yourself.