Josheli
  • Home
  • Blog
    • Knob
    • Running
    • Soccer
    • Technology
  • Projects
    • Overview
    • No Instagram
    • Google Photos WordPress Plugin
    • Plex Channels
    • Sh***y Game
    • Soccer In Colorado
    • Statrat
    • The Dot Game
    • Vox cPanel Hacks
    • WW Points Calculator
  • 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…
  • Looping back by Dv June 4, 2008 Sorely lacking in the Knob department, but my goal for the immediate future is to at least post short snippets…
  • Previous More Janky Snowboarding Video5 years ago
  • Next Westminster Neighborhood 5K Race Report: It’s Been a Long Time5 years ago

Leave a Reply Cancel reply

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

Popular Posts

  • Josheli, What Happened? (11,868)
  • Install Ubuntu on HP Laptop with UEFI and new SSD Hard Drive (9,769)
  • Running a Plex Media Server on an Old Laptop (9,425)
  • More Janky Snowboarding Video (7,228)
  • Simple Google Photos: A WordPress Plugin (6,745)

Random Read

A run
After much back and forth, I decided to do the 7-mile run this morning that…

Read More

Google Photo
Google Photo
Google Photo
Google Photo

Social Things

  • Family Photos
  • Juiskie’s Instagram
  • Scooter’s Facebook
  • Scooter’s Instagram
  • YouTube Videos
  • DV’s Github
  • Tweet Tweet

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
2021 Josheli. Donna Theme powered by WordPress