How to autoload helper files with composer?

Composer: How to autoload helper files with composer?

You can tell composer's autoload function to automatically include certain PHP files on every load. This is useful if you want to have a file with helper functions.

Add a files array to composer.json, within the autoload section. For example, add the middle section from the code below:

  1.           "autoload": {
  2.         "classmap": [
  3.             "database\/seeds",
  4.             "database\/factories"
  5.         ],
  6.  
  7.         //// COPY THE BELOW LINES - start copying from below this line (do not include this comment)
  8.  
  9.         "files": [
  10.             "app\/Helpers\/MyHelpers.php",
  11.             "ANY_OTHER_FILE_GOES_HERE_TOO"
  12.         ],
  13.  
  14.         //// UNTIL HERE - stop copying (and do not include this comment)
  15.  
  16.         "psr-4": {
  17.             "App\": "app\/"
  18.        }
  19.    },

webdevetc profile pic
webdevetc

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This (webdevetc.com) is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.



More...


Comments and discussion about How to autoload helper files with composer?

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the Composer language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to make multiple routes share the same URL structure or URL parameters

How to review blog posts (written by other users) before they get published on your WordPress blog?

Set PHP config Variables (like ini_set) with .htaccess

How to do comments in Blade files?

How to block IP addresses in Apache by using regular expressions (regex) in .htaccess

How to add the CSRF (Cross-site request forgery) token in Laravel?

How to undelete a soft deleted Eloquent row?

What is an example of an object literal?

How to sort an array in javascript?

How to enable the rewrite engine in .htaccess?