Introduction to OO PHP & Composer

http://slides.com/cweagans/composer-intro/live

https://github.com/cweagans/composer-intro

About Me

  • Principal Software Engineer for NBCUniversal
  • Contributor to Drupal, Laravel, Neovim, and others
  • cweagans pretty much everywhere on the web

Object oriented PHP

  • It's not difficult
  • It doesn't take a CS degree
  • You can (and should) do it

The Wrong Way?

Well...kind of.

*

OOP will not magically make your code better.

As a methodology, OO has issues.

It's still good to know.

Nest Thermostat

Habitat
Thermostat

The "Wrong" Way

Tag: step0

UI Demo (Step 0)

Demo: Step 0 Code

OO Baby Steps

Tag: step1

Step 1 Code Demo

Adding Composer

Tag: step2

Autoloading demo

Common patterns

Front Controller

Front Controller

  • Used in non-OO applications (Drupal, Wordpress, Joomla)
  • One file routes all requests to the code that should handle that request
  • Usually involves some kind of URL munging by the web server

MVC

MVC

  • Models: Represent data your application cares about (sometimes correlates to database tables)
  • Views: Present information to the user (templates)
  • Controllers: Orchestrate the process of getting data from Models and outputting the data via a View

MVC with a front controller

Tag: step3

Step 3 Code Demo

Thanks!

Feedback? Email me@cweagans.net

Made with Slides.com