php - Autoload with composer of classes inside a single file -


i'm trying use library uses namespaces has part of code auto-generated generate more 1 class in single file.

we use composer , tried add namespace define in psr-4 this

"name\space\preffix\": "folder/where/the/file/is" 

but there's 1 file contains classes inside autoload doesn't find classes as, imagine, searches file same name class trying load. there way make composer autoload aware of situation , use autoload classes ?

you have 2 other options besides psr-4 (or psr-0):

  1. classmap - scan directories or files classes contained, , result put php array in file. requires dump autoloader whenever there change being made files being scanned.
  2. files - mentioned file(s) included whenever composer autoloader included.

so either add file autogenerated classes scanned classmap autoloader, load file on first usage of of classes in there, or add files autoloading, included, no matter if classes being used or not.

if considering performance, first alternative preferred unless amount of classes huge , amount of code in classes tiny. having plenty of tiny classes in classmap more overhead loading them in first place.

having plenty of code in these classes, , not used, amount or memory saved not loading them might faster.

if in doubt: measure it. , consider split classes single files , use psr-4 if of performance penalty.


Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -