practices Collection of great community packages: Symfony, League, PHPDotEnv, etc. Rapid application development Collection of great unique (Illuminate) packages Easy interfaces—contracts and simple, interchangeable mail/queue/cache/session/file/etc. drivers Thriving and positive community Adoption of advanced patterns & practices
Idea. 1. It’s going to take longer than you think. 2. It’s going to take longer than you think. 3. There’s more domain knowledge in your old project than you can imagine. 4. Development on the production site will halt during development. 5. It’s going to take longer than you think.
a legacy codebase… Sneak it in. Test here. DI there. Illuminate component there. • Prove the value before you’re asking anyone to pay for it. • On every task or project, look for one way to make your codebase a little more Laravel-y. • If you’re working on a non-legacy, but non-Laravel, codebase… use the components.
Sandi Metz’ Rules for Developers https://robots.thoughtbot.com/sandi-metz-rules-for-developers 1. Classes can be no longer than one hundred lines of code. 2. Methods can be no longer than five lines of code. 3. Pass no more than four parameters into a method. Hash options are parameters. 4. Controllers can instantiate only one object. Therefore, views can only know about one instance variable and views should only send messages to that object (@object.collaborator.value is not allowed). STEP 1 “You should break these rules only if you have a good reason or your pair lets you.”
it’s 2015) Freenode #laravel / larachat.co You could hang out in #laravel and never have written a line of Laravel code in your life. LEARN FROM LARAVEL STEP 2
Laravel 5! PHP CodeSniffer (PHPStorm, Phil Sturgeon blog post on Sublime Text) PHP-CS-Fixer (Automatically fixes your code) Nitpick.io (comments on your pull requests notifying about PSR-2 violations—tweet @adamwathan for beta access) STEP 3
Laravel-as-a-frontend: Build a modern Laravel app that consumes data from your existing site Laravel-as-a-backend: Build a modern Laravel app that replaces an existing data store STEP 5
Asks for an instance of ClassName; "auto-wiring" // means it resolves this class, even if it's never // been explicitly bound $object = $app->make('ClassName'); Container: make
Bind the ClassName string to run the Closure provided; // every time it's injected, will run Closure again $app->bind('ClassName', function () { return new ClassName; }); $object1 = $app->make('ClassName'); $object2 = $app->make('ClassName'); $object1 !== $object2 Container: bind
Bind the ClassName string to run the Closure provided; // caches the result and returns it every time in the future $app->singleton('ClassName', function () { return new ClassName; }); $object1 = $app->make('ClassName'); $object2 = $app->make('ClassName'); $object1 === $object2 Container: singleton
Teaches the Container that, every time it resolves // this class (after this binding), it should also // perform the following behavior $app->extend('ClassName', function ($app, $class) { $class->setThing('a', 'b'); }); Container: extend
Adds an alias that returns the same output // as an existing Binding $app->alias('OriginalBinding', 'alias'); $app->alias( 'MyConcreteClass', 'MyInterface', ); // Real-life examples: $app->alias( 'files', 'Illuminate\Filesystem\Filesystem', ); Container: alias
'Mitzi']); $names->filter(function ($name) { // Filter out any names which start with "D" return substr($name, 0, 1) !== 'D'; })->map(function ($name) { // Decorate each name return "<i>{$name}</i>"; })->each(function ($name) { // Output each name echo "Collection name: $name\n"; }); // More at http://laravel.com/docs/5.1/collections Support: Collections
$worker = new Illuminate\Queue\Worker($queue->getQueueManager()); // Params list for 'pop': // * Name of the connection to use // * Name of the queue to use // * Number of seconds to delay a job if it fails // * Maximum amount of memory to use // * Time (in seconds) to sleep when no job is returned // * Maximum number of times to retry the given job // before discarding it while (true) { try { $worker->pop('default', 'worker-test', 3, 64, 30, 3); } catch (Exception $e) { // Handle job exception } } Queue: Worker
function get($key); public function put($key, $value, $minutes); public function increment($key, $value = 1); public function decrement($key, $value = 1); public function forever($key, $value); public function forget($key); public function flush(); public function getPrefix(); } Example Contract: Cache
class CacheManager implements FactoryContract { ... public function repository(Store $store) { $repository = new Repository($store); if ($this->app->bound('Illuminate\Contracts\Events\Dispatcher')) { $repository->setEventDispatcher( $this->app['Illuminate\Contracts\Events\Dispatcher'] ); } return $repository; Example Contract Usage: Cache Manager
Applications in PHP Paul Jones Working Effectively with Legacy Code Michael Feathers Refactoring Martin Fowler, Kent Beck, et al. Mastering Object Oriented PHP Brandon Savage