Slide 1

Slide 1 text

BOOTSTRAPPING YOUR OWN PHP APP WITH COMPOSER 25 March 2014

Slide 2

Slide 2 text

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.

Slide 3

Slide 3 text

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/

Slide 4

Slide 4 text

SAMPLE PROJECT • Requirement: • REST Server • MySQL backend • Logging. ! ! • Consideration: • No need for any views. • Simple CRUD app.

Slide 5

Slide 5 text

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)

Slide 6

Slide 6 text

COMPOSER.JSON {! "require":{! "respect/rest": "0.5.0",! "monolog/monolog": "1.7.0",! "php-activerecord/php-activerecord": "v1.1.2"! },! "require-dev": {! "phpunit/phpunit": "4.0.*",! "guzzle/guzzle": "v3.8.1"! }! }

Slide 7

Slide 7 text

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%

Slide 8

Slide 8 text

UNIT TESTS • Tests folder • bootstrap.php - Setup and server side includes. • phpunit.xml - Config for running PHPUnit. • *Test.php - The tests files.

Slide 9

Slide 9 text

TEST SPEC • API Consumer should be able to: • Get list of blog posts. • Create a new blog post. • Delete the blog post he created.

Slide 10

Slide 10 text

THE IMPLEMENTATION • TDD: Red, Green, Refactor. • Use your own namespace to take advantage of Composer’s autoload mechanism. • Don’t get ahead of yourself.

Slide 11

Slide 11 text

WALK-THRU https://github.com/ sgphpug/sampleblog