I have been working with phalcon for pretty long time and I belive I came to some point at which I think I can make it public.
Previously I have made this topic: https://forum.phalcon.io/discussion/17365/phalcon-is-not-trully-modular-framework-and-how-to-solve-it
Work done so far:
- Absolutely no code leaves modules directory
- Configuration files are in json (tho it wouldn't be a problem to make them yaml/xml etc)
- CLI support with option to add your own task (there are few built in tasks like generating modules, dumping routes etc)
- Migrations are inside modules, format is pretty much unchanged
- Router works differently than in phalcon, routes are read from configuration file
- All modules have option to inject services, initialize code etc.
- Modules are not simple arrays anymore, meaning you can get instance of any (or active) module class And much more
This is how app directory looks like: https://i.imgur.com/JhoJK6J.png (I probably should change plural to singular for some directories)
Each module needs to have a short definition:
{
"name": "core",
"version": "1.0.0",
"enabled": true,
"priority": 0
}
Modules are loaded by priority (i plan to add dependencies to them)
Each modules have their own migrations which are executed automatically based on what is set in module_versions
in database
There is Acl and Auth module which implements basic auth and acl for:
- Routes
- Entities
Uses twig instead of volt because of few reasons:
- Nesting
- Namespaces (yes you can include templates from another module by:
include '@modulename/some/template.twig'
- Overriding templates (crud generates twig template on the fly instead of relaying on templates)
But the biggest change is in routing because in phalcon, only the active module gets loaded. It isnt the case in my app.
All modules are being loaded but only active one is executed. And routes are being kept in routes.json
:
{
"inventory": {
"type": "crud",
"prefix": "/inventory",
"controller": "inventory",
"children": {
"import_from_tme": {
"path": "/import-from-the-supplier",
"action": "importFromTheSupplier"
},
"stocktaking": {
"path": "/stocktaking/export",
"action": "exportStocktaking"
}
}
},
"inventory_changelog": {
"type": "crud",
"prefix": "/inventory-changelog",
"controller": "changelog"
},
"supplier": {
"type": "crud",
"prefix": "/supplier",
"controller": "supplier"
}
}
yes you can generate routes by name, there are 3 different types of routes like 'normal', 'crud', 'include'
Long story short: I think I have made phalcon trully modular, it needs some work to make it more proper and if anyone is interested in development of a skeleton let me know