How to inject custom php classes into zend directory

expressive
zend-mvc

#1

hi. does anyone know how to insert custom php classes into zend framework 3 modular structure?!


#2

The module system of ZF2, ZF3 and zend-expressive is very flexible and simple. A module can contain (almost) everything.
Look at the “In-Depth tutorial”, there will you find an example of a blog module. This module includes many “custom” classes.
I hope this will help or do you mean something else?


#3

I have used some custom classes in my document and for the record I studied blog module, but I had to include the classes. i am wondering if there is a way to address the desired custom class like in the zend plugins.


#4

May be you just need to define autoload rules in composer.json for your namespace?
Here is simple example:

"autoload": {
  "psr-4": {
    “AppNs\\ModuleNs\\”: "module/ModuleNs/src"
  }
},
"autoload-dev": {
  "psr-4": {
    “AppNs\\ModuleNs\\”: [
      "module/ModuleNs/test/functional",
      "module/ModuleNs/test/unit"
    ]
  }
},

#5

Please see in the tutorial or in the comment from @merkushin, because the autoloading is done by Composer. (More background infos here: https://getcomposer.org/doc/01-basic-usage.md#autoloading)
That’s all!