Josheli
  • Home
  • Blog
    • Knob
    • Running
    • Soccer
    • Technology
  • About
Knob , Technology

Laravel, Composer and Optimize

by dv February 18, 2016 No Comments

So I write these little tech snippets mostly as a personal journal for my future self. Anyway, got caught again at work by a weird situation where dev and test/prod environments differed. Well, not really, but kind of. What?

I deployed our main app last month after upgrading it to Laravel 5 and all seemed to be working fine. Was working fine on dev too. Fast forward to today and my tests break on dev with an error about not finding a couple of namespaced classes. Hour or two of sleuthing ensued.

The gist? By default Laravel runs the command “php artisan optimize” after install and update. This command runs “composer dump-autoload –optimize” behind the scenes. That Composer command generates a huge class map of all of your classes, even your PSR classes… unless you tell it not to (which you can do through the Laravel command by passing the “psr” option).

So on dev, I regularly make changes, add/remove classes, and run “composer dump-autoload” after I do. Notice that command I run manually does not contain the “–optimize” option. Thus the huge class map is not created. Thus the two classes that are somewhat non-standard in their location on disk are not found by the PSR autoloader. Thus the error.

I’m not sure why “composer dump-autoload –optimize” can find and map those two classes just fine, but the actual PSR autoload implementation (without a classmap), cannot find those two classes. But it can’t. And it breaks.

So as a final result, I need to remember to add the –optimize flag when I run dump-autoload on dev (because that’s what Laravel does on test/prod). Or I could move those two classes somewhere else, or add their location to the “classmap” key in my composer.json.

Clear as crystal?

Related Content:

  • Migrating a Laravel application to Symfony by Dv April 15, 2019 When I started at the day job about 6.5 years ago, I inherited a jumble of custom PHP/MySql web applications.…
  • Automated Testing with Codeception by Dv February 12, 2016 I gave a little presentation at work the other day on using automated testing in my Laravel project using Codeception.…
  • Laravel: Simple Method for Modules by Dv March 1, 2017 In my day job, I maintain a fairly large-ish Laravel application. It started out as a few separate vanilla PHP…
  • Continuous Deployment: Drupal 8, Composer, Github,… by Dv April 17, 2018 UPDATE: Watch a tech talk I recently gave at work about this process. I've been doing some pretty cool work…
  • Dockerizing PHP apps and deploying to AWS Fargate Part 1 by Dv February 6, 2019 For the day job, I maintain four custom PHP apps in addition to several Drupal sites. Up until a couples…
It's only fair to share...Share on facebook
Facebook
Share on twitter
Twitter
Share on email
Email
  • Previous More Janky Snowboarding Video9 years ago
  • Next Westminster Neighborhood 5K Race Report: It’s Been a Long Time9 years ago

Leave a Reply

Your email address will not be published. Required fields are marked *

Popular Posts

  • Josheli, What Happened? (54,960)
  • Stupidly Simple, Static, Startpage for Self-hosted Services (29,318)
  • Running a Plex Media Server on an Old Laptop (25,685)
  • Simple Google Photos: A WordPress Plugin (22,628)
  • Only Say True Things (22,035)

Random Read

Racing through
I'd like to polish the Knob more often, hopefully this is a start. I still…

Read More

Google Photo
Google Photo
Google Photo
Google Photo

Social Things

  • Family Vance
  • Texas Longhorns News

RSS From Familyvance

  • Snowshoeing at Brainard Lake
  • Fishing and Hiking at Golden Gate Canyon State Park
  • Rainbow Trout Fishing Report at Waneka Lake
  • Weightless Texas-Rig Plastic Worms at Sawhill Ponds and Coot Lake
  • Sawhill Ponds Fishing Report
2025 Josheli. Donna Theme powered by WordPress