View Issue Details

IDProjectCategoryView StatusLast Update
0021831mantisbtplug-inspublic2016-10-31 07:33
Reportercproensa Assigned To 
PrioritynormalSeverityminorReproducibilityhave not tried
Status newResolutionopen 
Product Version1.3.4 
Summary0021831: Include plugin classes in autoload
Description

For plugins that defines its own classes, it's useful to create an autoload procedure.
By standarizing location and naming conventions, the main autoload can be used to load plugin classes:

  • Define a "classes" directory as the container directory for classes files. This directory sits at the same level as current standard ones like: pages, files, lang, etc

  • In main autoload, for any registered plugin, support the namespace being the same as an existing plugin basename, so that it can search within said plugin's "classes" directory.

This means:
A plugin named "MyPlugin", declares a class "MyClass" within namespace "MyPlugin"
Autoload will search for class "\MyPlugin\MyClass" in:
.../plugins/MyPlugin/classes/MyClass.class.php

Deeper namespaces will locate in said dir:
class: \MyPlugin\Any\MyClass
file: .../plugins/MyPlugin/classes/Any/MyClass.class.php

With the corresponding documentation, plugin developers will be encouraged to namespace their plugin specific code. This avoids collisions between core functions, and even other plugins, which otherwise, are adding functions and classes to the global name space.

A plugin can then share its classes by applying the plugin-named namespace. Any other plugin can now use these classes which will be auto loaded. (The dependency was resolved if indicating "requires x plugin").
In current model, classes and functions are shared by default through the active environment, but there is no way to locate classes if they have not been already included by the main plugin.

--

An alternative to the previous autoload strategy, is to also include non-namespaced classes from plugins.

This means:
class: MyClass
if core autoload fails, and a plugin "MyPlugin" execution is active, search for the file in:
file: .../plugins/MyPlugin/classes/MyClass.class.php

For a namespaced class:
class MyPlugin\MyClass
search in the corresponding plugin directory:
file: .../plugins/MyPlugin/classes/MyPlugin/MyClass.class.php

Still, for classes to be accesible by other plugins, they need to be namespaced with the plugin name, but requires an additional level in "classes" directory to account for this namespace.

TagsNo tags attached.

Activities

dregad

dregad

2016-10-31 07:33

developer   ~0054357

+1

Issue History

Date Modified Username Field Change
2016-10-31 04:49 cproensa New Issue
2016-10-31 07:33 dregad Note Added: 0054357