Reply New Topic
2019/5/15 0:44:20
#1
Offline
Webmaster

Defining modules and plugins in a composer world

in all ImpressCMS versions until now, (1.4) we are basing ourselves on the file location to determine whether a folder contains a module, a theme, a translation or a plugin. Autoloading and composer have allowed us to look into changing that concept a bit.

With composer, it is perfectly possible to change from one library to a fork, while keeping the same development interface. All packages are bundled under the 'vendor' folder now, without indication what type of library they are.

In the case mentioned above, it could be that that fork is more actively maintained, or contains specific code that didn't make it into the main library. Moving to another maintainer of the library makes that the file location of your library will change under 'vendor'. Fortunately, autoloader takes care of the discovery aspect for you : you just tell it that you need class X, and the autoloader matches that with the file that needs to be loaded to make class X available, without you needing to knpw the name of the file on beforehand.

If we take the same concept and apply it to modules, themes and plugins, ImpressCMS still looks in specific locations for certain addon types. we look for modules by reading the icms_info.php files in the subfolders of the 'modules' folder, we look for themes by checking if there is a theme.html in te subfolders of 'themes', and so on for translations and editors.

One place where this is problematic, is with plugins. For example, the sitemap module has plugins for a long list of external modules, to help it understand the content of those other modules, and construct a correct sitemap from them. At the moment, those plugins are bundled with the sitemap module, and they are stored in a subfolder of the sitemap module folder. 

That poses a problem if we want to add a plugin for the sitemap module from another module without resorting to copying files from one location to another, or having specific 'registration' routines. Here, the PHP Reflection API comes to our rescue. It allows us to scan all the classes in the system, and identify the class interconnexions. Which class is a subclass of ipf_module, for example, and which class is a subclass of ipf_module_sitemap. Have a look at StackOverflow for an example.

Perhaps this is worth looking into for future versions, to make management of the different addons and other packages easier and decoupled from the file system.


_________________

Me on OpenHub


2019/5/26 10:13:39
#2
Offline
Just can not stay away

Re: Defining modules and plugins in a composer world

Probably if we could fix our events system we could make modules do stuff that we trying todo with plugins. F.e. module that can use sitemap functionality could trigger some events that could be handled by sitemap module. If there are no such module, these events will be ignored.



2019/5/27 4:12:52
#3
Offline
Webmaster

Re: Defining modules and plugins in a composer world

Interesting point, in a way we would use events to do some kind of observer pattern, am I correct?


_________________

Me on OpenHub


2019/5/28 3:46:10
#4
Offline
Just can not stay away

Re: Defining modules and plugins in a composer world

yeah... probably that is so called.



Reply New Topic extras
 Previous Topic   Next Topic
You can view topic.
You can start a new topic.
You can reply to posts.
You cannot edit your posts.
You cannot delete your posts.
You cannot add new polls.
You cannot vote in polls.
You cannot attach files to posts.
You can post without approval.