Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added information #145

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open

Added information #145

wants to merge 7 commits into from

Conversation

DonutsNL
Copy link

@DonutsNL DonutsNL commented Jul 6, 2023

  1. About how to use namespaces and composer autoloader in Plugins.

  2. Maybe add information about future support. Will namespaces be the standard and will /inc be deprecated?

  3. I also think it is wise to add the instruction somewhere to "NOT" use existing GLPI classnames inside the plugin namespace or renaming them using: use GlpiPlugins\Namespace\ExistingObjectName as SomethingElse;. I noticed doing so with extends on other existing GLPI objects like CommonDropdown will make the resulting functionality pretty flaky. It should be easy to come up with unique class names.

Added some additional information on using the Composer autoloader and /src/ in the Directory structure. Please review my interpretation maybe add something on LTS, will old /inc/ be deprecated in the future?
Created an actual RST table :S and added code examples
Should not be in the pull request.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to add .vscode to .gitignore obviously xD sorry.

Copy link
Contributor

@cconard96 cconard96 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a review of the wording/grammar of the new text.

Also, some of this seems like duplicated information from the other recent PR regarding this change:
#139

POST GLPI 10
+++++++++++

In GLPI 10 and newer installations you are adviced to use namespaces and composer autoloader. Objectfiles using namespaces are no longer loaded by the old autoload.function.php but by the newer Composer autoloader. In order to use the composer autoloader in your plugin must place your classfiles in the `/src` directory instead of the `/inc`. In this scenario the `/inc` directory should no longer be present in the plugin folder structure.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
In GLPI 10 and newer installations you are adviced to use namespaces and composer autoloader. Objectfiles using namespaces are no longer loaded by the old autoload.function.php but by the newer Composer autoloader. In order to use the composer autoloader in your plugin must place your classfiles in the `/src` directory instead of the `/inc`. In this scenario the `/inc` directory should no longer be present in the plugin folder structure.
In GLPI 10 and newer installations you are advised to use namespaces and the Composer PSR-4 autoloader. Classes using namespaces are no longer loaded by the old autoload.function.php but by the newer Composer autoloader. In order to use the Composer autoloader in your plugin, must place your PHP class files in the `/src` directory instead of `/inc`. In this scenario the `/inc` directory should no longer be present in the plugin folder structure.


In GLPI 10 and newer installations you are adviced to use namespaces and composer autoloader. Objectfiles using namespaces are no longer loaded by the old autoload.function.php but by the newer Composer autoloader. In order to use the composer autoloader in your plugin must place your classfiles in the `/src` directory instead of the `/inc`. In this scenario the `/inc` directory should no longer be present in the plugin folder structure.

The the convention to be used is (Case sensitive): `namespace GlpiPlugin\Myplugin;`. The namespace should be added to every classfile in the `/src` directory and should be PHP convention be placed in the top of your classfile. Classfiles using the `GlpiPlugin\Myplugin\` namespaces will be loaded from: `GLPI_ROOT\Plugins\myplugin\src\ClassName.php`. To include folders inside the `/src` directory simply add them to your namespace and use keywords i.e. `namespace GlpiPlugin\Myplugin\SubFolder\` will load `GLPI_ROOT\Plugins\myplugin\src\SubFolder\ClassName.php`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The the convention to be used is (Case sensitive): `namespace GlpiPlugin\Myplugin;`. The namespace should be added to every classfile in the `/src` directory and should be PHP convention be placed in the top of your classfile. Classfiles using the `GlpiPlugin\Myplugin\` namespaces will be loaded from: `GLPI_ROOT\Plugins\myplugin\src\ClassName.php`. To include folders inside the `/src` directory simply add them to your namespace and use keywords i.e. `namespace GlpiPlugin\Myplugin\SubFolder\` will load `GLPI_ROOT\Plugins\myplugin\src\SubFolder\ClassName.php`.
The convention to be used is (Case sensitive): `namespace GlpiPlugin\Myplugin;`. The namespace should be added to every class in the `/src` directory and per the PSR-12 PHP convention be placed in the top of your class. Classes using the `GlpiPlugin\Myplugin\` namespaces will be loaded from: `GLPI_ROOT\plugins\myplugin\src\`. To include folders inside the `/src` directory simply add them to your namespace and use keywords i.e. `namespace GlpiPlugin\Myplugin\SubFolder\` will load from `GLPI_ROOT\plugins\myplugin\src\SubFolder\`.

Copy link
Author

@DonutsNL DonutsNL Jul 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are correct. Documenting this with the folder structure feels like a more natural place. Maybe place a reference back to the plugin structure paragraph somewhere in the 'adding and managing' objects paragraph.

I also tried to make it a bit more verbose for readers to understand whats going on so they are less likely to make typo mistakes and open issues because of this. Sorry for my roughly typed english ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants