Slide 1

Slide 1 text

Sharing Laravel Laravel’s Best Assets @stauffermatt Bringing To Any Project

Slide 2

Slide 2 text

Sharing Laravel @stauffermatt Matt Stauffer @stauffermatt Partner, Technical Director Tighten Co. tighten.co

Slide 3

Slide 3 text

Sharing Laravel @stauffermatt Gainesville I’m going to say y’all a lot ( )

Slide 4

Slide 4 text

Sharing Laravel @stauffermatt Why is this talk necessary?

Slide 5

Slide 5 text

Sharing Laravel @stauffermatt Most Laravel tutorials assume a blank slate. greenfield, adj: a project that lacks any constraints imposed by prior work.

Slide 6

Slide 6 text

Sharing Laravel @stauffermatt The problem: Most of our work is on
 existing codebases. FREEDOM Old Code

Slide 7

Slide 7 text

Sharing Laravel @stauffermatt The solution: Learn how to bring the best assets of the Laravel world to non-Laravel projects.

Slide 8

Slide 8 text

Sharing Laravel @stauffermatt The disclaimers: • Going to cover a lot, shallowly, so please ask me questions afterward • Much of this talk isn’t unique to Laravel

Slide 9

Slide 9 text

Sharing Laravel @stauffermatt WHAT MAKES LARAVEL SO GREAT?

Slide 10

Slide 10 text

Sharing Laravel @stauffermatt What will Laravel add to my project? Modern coding practices Rapid development Collection of great community (Symfony, etc.) packages Collection of great unique (Illuminate) packages Thriving and positive community Adoption of advanced patterns & practices Potential for future growth—unique foresight

Slide 11

Slide 11 text

Sharing Laravel @stauffermatt but Matt, my project is in CodeIgniter/etc. … what do I do? You, dear audience member

Slide 12

Slide 12 text

Sharing Laravel @stauffermatt WHY DON’T WE JUST REWRITE IT IN LARAVEL?

Slide 13

Slide 13 text

Sharing Laravel @stauffermatt WHY DON’T WE JUST REWRITE IT IN LARAVEL? TERRIBLE IDEA

Slide 14

Slide 14 text

Sharing Laravel @stauffermatt response to legacy code: trash it. Sharing Laravel @stauffermatt or, more likely, “KILL IT WITH FIRE”

Slide 15

Slide 15 text

Sharing Laravel @stauffermatt Nuking your old project is a Bad 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.

Slide 16

Slide 16 text

Sharing Laravel @stauffermatt The incremental approach

Slide 17

Slide 17 text

Sharing Laravel @stauffermatt UNDERCOVER LARAVEL

Slide 18

Slide 18 text

Sharing Laravel @stauffermatt UNDERCOVER LARAVEL • Recognizing that an all-out rebuild is not wise or, likely, in line with the budget… • Still wanting to bring the Best Of Laravel to your project… • Become a Laravel secret agent.
 Sneak it in where it’s least expected. • 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.

Slide 19

Slide 19 text

Sharing Laravel @stauffermatt The 7 steps to “Laravel-izing” your coding and your legacy codebase

Slide 20

Slide 20 text

Sharing Laravel @stauffermatt Learn the basics STEP 1

Slide 21

Slide 21 text

Sharing Laravel @stauffermatt Crap code
 wrapped in Laravel
 is still crap code.

Slide 22

Slide 22 text

Sharing Laravel @stauffermatt LEARN THE BASICS OOP best practices SOLID Law of Demeter Loose coupling Not just wrapping procedural code in classes (ahem CodeIgniter ahem) STEP 1

Slide 23

Slide 23 text

Sharing Laravel @stauffermatt LEARN THE BASICS Design patterns Identifying best-practice, commonly-used patterns; giving each a name; and suggesting situations in which each will (and won’t) prove useful STEP 1

Slide 24

Slide 24 text

Sharing Laravel @stauffermatt LEARN THE BASICS Design patterns Examples: • Adapter Pattern • Singleton Pattern • Observer Pattern • Many more… STEP 1

Slide 25

Slide 25 text

Sharing Laravel @stauffermatt LEARN THE BASICS Architecture patterns Hexagonal Architecture Domain Driven Design STEP 1

Slide 26

Slide 26 text

Sharing Laravel @stauffermatt Learn from Laravel STEP 2

Slide 27

Slide 27 text

Sharing Laravel @stauffermatt LEARN FROM LARAVEL Subscribe to Laracasts STEP 2

Slide 28

Slide 28 text

Sharing Laravel @stauffermatt Read the books Code Bright
 Dayle Rees From Apprentice to Artisan
 Taylor Otwell Implementing Laravel
 Chris Fidao Other Books I haven’t read yet
 http://wiki.laravel.io/books LEARN FROM LARAVEL STEP 2

Slide 29

Slide 29 text

Sharing Laravel @stauffermatt LEARN FROM LARAVEL Go read the accepted PSRs PSR-0: Old Autoloading PSR-1 & PSR-2: Code styles PSR-3: Logging PSR-4: Autoloading STEP 2

Slide 30

Slide 30 text

Sharing Laravel @stauffermatt IRC like it’s 1999 #laravel You could hang out in #laravel and never have written a line of Laravel code in your life. LEARN FROM LARAVEL STEP 2

Slide 31

Slide 31 text

Sharing Laravel @stauffermatt Read the source LEARN FROM LARAVEL STEP 2

Slide 32

Slide 32 text

Sharing Laravel @stauffermatt Modernize your foundation STEP 3

Slide 33

Slide 33 text

Sharing Laravel @stauffermatt MODERNIZE YOUR FOUNDATION Code standards PHP CodeSniffer (PHPStorm, Phil Sturgeon blog post on Sublime Text) PHP-CS-Fixer (Automatically fixes your code) PSR2-ish (tabs not spaces, control braces on new lines) Scrutinizer config: 
 https://github.com/laravel/framework/blob/4.2/.scrutinizer.yml STEP 3

Slide 34

Slide 34 text

Sharing Laravel @stauffermatt Stay Classy Procedural code/functions -> methods on classes -> retroactive designed OOP Namespaces & autoloading STEP 3 MODERNIZE YOUR FOUNDATION

Slide 35

Slide 35 text

Sharing Laravel @stauffermatt Autoloading & PSR-4 Autoload your classes PSR-4 autoloading Drop as many includes/requires as possible STEP 3 MODERNIZE YOUR FOUNDATION

Slide 36

Slide 36 text

Sharing Laravel @stauffermatt Bug-driven testing For every bug reported… Write a (failing) test. Then fix the bug by writing code that makes the test pass. Repeat. STEP 3 MODERNIZE YOUR FOUNDATION

Slide 37

Slide 37 text

Sharing Laravel @stauffermatt Learn more STEP 3 https://speakerdeck.com/mattstauffer/
 why-modern-php-is-awesome-and-how-you-can-use-it-today MODERNIZE YOUR FOUNDATION

Slide 38

Slide 38 text

Sharing Laravel @stauffermatt Compose all the things STEP 4

Slide 39

Slide 39 text

Sharing Laravel @stauffermatt COMPOSE ALL THE THINGS What is
 Composer? Dependency manager for PHP (Like Ruby Gems, Node Package Manager, etc.) STEP 4

Slide 40

Slide 40 text

Sharing Laravel @stauffermatt Community packages Packagist Symfony PHP League DIY COMPOSE ALL THE THINGS STEP 4

Slide 41

Slide 41 text

Sharing Laravel @stauffermatt Illuminate your project STEP 5

Slide 42

Slide 42 text

Sharing Laravel @stauffermatt ILLUMINATE YOUR PROJECT Illuminate packages Mail Auth Queue Config Cache Session Workbench Validation Translation Support Routing Remote Pagination Log Http Html Hashing Events Database Cookie STEP 5 Commonly exported: • Database (Eloquent) • Config • Cache • Session • Support (Collections, array helpers, etc.) • Pagination (Because Phil Sturgeon) • Many more…

Slide 43

Slide 43 text

Sharing Laravel @stauffermatt TITLE FOR STEP 1 github.com/ mattstauffer/ illuminateNonLaravel ILLUMINATE YOUR PROJECT STEP 5

Slide 44

Slide 44 text

Sharing Laravel @stauffermatt each(function($person) { echo "Well, howdy $person!
"; }); Simple Use Example

Slide 45

Slide 45 text

Sharing Laravel @stauffermatt addConnection([ 'driver' => 'mysql', 'host' => 'localhost', 'database' => 'database', 'username' => 'root', 'password' => 'supersecret!', 'charset' => 'utf8', 'collation' => 'utf8_unicode_ci', 'prefix' => '' ]); $capsule->bootEloquent(); ! // Other file class User extends Illuminate\Database\Eloquent\Model {} $user = User::find(1); Using the Capsule

Slide 46

Slide 46 text

Sharing Laravel @stauffermatt $app = new Illuminate\Container\Container; $app->bind('app', $app); ! $providers = [ 'Illuminate\Queues\QueueServiceProvider', 'Illuminate\Events\EventServiceProvider' ]; ! foreach ($providers as $provider) { with (new $provider($app))->register(); } ! $aliases = [ 'Queue' => 'Illuminate\Support\Facades\Queue', 'Config' => 'Illuminate\Support\Facades\Config', ]; ! foreach ($aliases as $alias => $class) { class_alias($class, $alias); } ! Illuminate\Support\Facades\Facade::setFacadeApplication($app); Bootstrapping Illuminate

Slide 47

Slide 47 text

Sharing Laravel @stauffermatt Contribute please! ILLUMINATE YOUR PROJECT STEP 5

Slide 48

Slide 48 text

Sharing Laravel @stauffermatt Get SaaS-y STEP 6

Slide 49

Slide 49 text

Sharing Laravel @stauffermatt Transactional Email Sendgrid Mailgun Mandrill etc. GET SAAS-Y STEP 6

Slide 50

Slide 50 text

Sharing Laravel @stauffermatt Logs Papertrail Bugsnag/Sentry/Airbrake/etc. GET SAAS-Y STEP 6

Slide 51

Slide 51 text

Sharing Laravel @stauffermatt GET SAAS-Y Code quality Scrutinizer Sensio Labs Insights CodeClimate STEP 6

Slide 52

Slide 52 text

Sharing Laravel @stauffermatt Continuous Integration/ Deployment Codeship Jenkins Travis Semaphore Scrutinizer GET SAAS-Y STEP 6

Slide 53

Slide 53 text

Sharing Laravel @stauffermatt Laravel-as-a- component STEP 7

Slide 54

Slide 54 text

Sharing Laravel @stauffermatt LARAVEL-AS-A-COMPONENT Just a little bit of Laravel 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 7

Slide 55

Slide 55 text

Sharing Laravel @stauffermatt Craft API CraftCMS is based on Yii; like Laravel’s CMS step-brother Craft API plugin (in development) Example: @mattgreen110 LARAVEL-AS-A-COMPONENT STEP 7

Slide 56

Slide 56 text

Sharing Laravel @stauffermatt “The Right Toolbox” Anthony Colangelo at HappyCog Eloquent objects to describe your Craft database structure https://speakerdeck.com/ acolangelo/the-right-toolbox LARAVEL-AS-A-COMPONENT STEP 7

Slide 57

Slide 57 text

Sharing Laravel @stauffermatt https://speakerdeck.com/acolangelo/the-right-toolbox

Slide 58

Slide 58 text

Sharing Laravel @stauffermatt DEEP/OpenAPI/Export It Same thing, but for ExpressionEngine https://github.com/rsanchez/Deep https://github.com/putyourlightson/open-api https://www.mithra62.com/ (Export It) LARAVEL-AS-A-COMPONENT STEP 7

Slide 59

Slide 59 text

Sharing Laravel @stauffermatt Conclusie

Slide 60

Slide 60 text

Sharing Laravel @stauffermatt Know why you’re here What is it about Laravel that brought you to this conference?

Slide 61

Slide 61 text

Sharing Laravel @stauffermatt (other than this mug)

Slide 62

Slide 62 text

Sharing Laravel @stauffermatt Bring that, incrementally, to legacy apps • Undercover Laravel • OOP & Design/Architecture Patterns • Modernize codebase • Composer & Illuminate Packages • Get Saas-y • Laravel as a Component

Slide 63

Slide 63 text

Sharing Laravel @stauffermatt Additional resources Modernizing Legacy 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

Slide 64

Slide 64 text

Sharing Laravel @stauffermatt Compelling action slide