AutoLoad¶
Aim : use autoload / stop using NEEDED_ITEM
Study of roadmap for this feature.¶
- Clean class names and file names
- Class Name = table name in singular (ex : glpi_computers -> Computer, glpi_contactstypes -> ContactsType, glpi_ocsadmininfoslinks -> OcsAdminInfosLink)
- remi ContactsType of ContactType, Link between table / class name seems less critical as we have the Class->table property
- MoYo I prefer ContactsType which can be read Contact's Type. Maybe the link table / class name is less critical but if we setup a naming convention, it must be used.
- Case of links : glpi_contacts_suppliers -> ContactSupplier or Contact_Supplier ? _ saying relation.
- filename : classname.class.php
- TODO: Rename classes / split into correct files, use temporary include to preserve actual inclusions / clean include and empty files at the end
- remi even for multiple classes ? (Software/Version/Licence, Job/Followup, and the big one : Dropdown)
- MoYo yes for all classes. autoload process must to be simple. It will be possible only if a class = a file
- remi ContactsType of ContactType, Link between table / class name seems less critical as we have the Class->table property
- Plugin Naming convention and storage convention
- PluginPluginnameClassname store in plugin/pluginname/inc/classname.class.php
- See special section at the end for a complete example / study
- TODO: correct plugins
- remi : PluginPdfProfile => plugin/pdf/inc/profile.class.php seems ok
- MoYo : Plugin name must not have capital letters inside.
- PluginPluginnameClassname store in plugin/pluginname/inc/classname.class.php
- Class Name = table name in singular (ex : glpi_computers -> Computer, glpi_contactstypes -> ContactsType, glpi_ocsadmininfoslinks -> OcsAdminInfosLink)
- Delete CommonItem
- Change itemtype management : integer -> string = Class Name
- TODO: update DB for core (plugins need to do for their types) / replace constants by ClassName (temporary solution)
- functions of CommonItem -> CommonDBTM
- TODO: migrate datas to CommonDBTM / Delete CommonItem usage / Delete CommonItem
- Change itemtype management : integer -> string = Class Name
- Stop using constants : LINK_ID_TABLE INFOFORM_PAGES SEARCH_PAGES
- LINK_ID_TABLE : use table attribute of the object / class name -> tablename
- INFOFORM_PAGES : classname.form.php
- SEARCH_PAGES : classname.php
- Remark : classname and classname.form will be merge and/or deleted in the future (see framework)
- remi how can we share same form for multiple Class. Proposal Class->get{Search|Form}Page whith a default in CommonDBTM
- MoYo For the moment I think that the solution is the same that the one used for rules engine. But when we have a global controller (see framework), it will be really easy to do it using class hierarchy.
- TODO : clean usage / delete config array
- All functions in classes
- TODO: just do it, rename functions if needed, clean code if needed
- remi : remove ID option ? (just add a $ID=$this->field['id'] as first line for simplicity), add getFromDB in "tabs" (at least the can call will force the DB read) ?
- MoYo yes it could be done but not mandatory for autoload.
- remi : where to put cron_xxx fonction (Crontask::cron_xxx ou XXX::cron, second not always possible, ex session) ?
- MoYo
- prefer the second one XXX:cron. Will be easy to manage plugin cron jobs.
- for session : may be create a specific object or add it to Auth class ?
- other problem : several cron jobs for a single object
- another idea : keep cron functions / not attached to an object
- Solution : a task define by its class name and its method name
- MoYo
- remi : remove ID option ? (just add a $ID=$this->field['id'] as first line for simplicity), add getFromDB in "tabs" (at least the can call will force the DB read) ?
- Problems : How to manage ?
- search engine functions -> class Search ? or inside CommonDBTM classes
- common functions in classes ? String class ? Security / Sanitize ? Display ? Install/Update ? System ? Database ?
- TODO: just do it, rename functions if needed, clean code if needed
- remi set CommonDBTM as abstract with at least 1 abstract method to be sure all sub class are fixed ? proposal (already used in Dropdown)
abstract static function getTypeName ($plurial=false);
- MoYo abstract lead that this function must be defined in each sub classes. Not sure it is a good idea.
More clean¶
- Try to clean the maximum config variables which can be done using classes : ex : $CFG_GLPI["recursive_type"]
- TODO: ...
- remi carefull $CFG_GLPI["recursive_type"] (is recursive field) is different than Class->may_be_recursive (from parent)
- MoYo need to add a new field : use_recursive_search for example
- remi carefull $CFG_GLPI["recursive_type"] (is recursive field) is different than Class->may_be_recursive (from parent)
- TODO: ...
- Clean haveRight functions : need to be included in classes
- TODO: ...
- Do the same job : clean type for rules engine / put criterias, actions in classes
- TODO: Need to add a condition filter in CommonDBTM to filter by subtype access to the DB tables (getFromDB...)
- Move RELATION to classes : manage link clean in CommonDBTM
Naming Convention Study¶
- itemtype = ClassName
- a simple object :
- class Computer
- table glpi_computers
- file inc/computer.class.php
- link field : computers_id
- a link objet :
- class Computer_SoftwaresVersion
- table glpi_computers_softwaresversions
- file inc/computer_softwaresversion.class.php
- link field : computers_softwaresversions_id
- Plugins
- PluginNameoftheplugin define only the plugin "namespace" / (we could use real namespace on PHP 5.3.0)
- an simple object
- First example :
- class PluginWebapplicationsProfile
- table glpi_plugin_webapplications_profiles
- file plugins/webapplications/inc/profile.class.php
- link field : plugin_webapplications_profiles_id
- Second Example
- class PluginWebapplicationsTest
- table glpi_plugin_webapplications_tests
- file plugins/webapplications/inc/test.class.php
- link field : plugin_webapplications_tests_id
- case of main class : to be discussed
- Case 1 : need to manage an exception
- class PluginWebapplications
- table glpi_plugin_webapplications
- file plugins/webapplications/inc/webapplications.class.php
- link field : plugin_webapplications_id
- Case 2 : standard case (MoYo 1 point)
- class PluginWebapplicationsWebapplication
- table glpi_plugin_webapplications_webapplications
- file plugins/webapplications/inc/webapplication.class.php
- link field : plugin_webapplications_webapplications_id
- Case 1 : need to manage an exception
- First example :
- Links
- a link object inside a plugins
- class PluginWebapplicationsProfile_Test
- table glpi_plugin_webapplications_profiles_tests
- file plugins/webapplications/inc/profile_test.class.php
- link field : plugin_webapplications_profiles_tests_id
- a second object inside a plugins
- class PluginWebapplicationsWebapplication_Xyz
- table glpi_plugin_webapplications_webapplications_xyzs
- file plugins/webapplications/inc/webapplication_xyz.class.php
- link field plugin_webapplications_webapplications_xyzs_id
- a link with a core object
- class PluginWebapplicationsComputer_Profile
- table glpi_plugin_webapplications_computers_profiles
- file plugins/webapplications/inc/computer_profile.class.php
- link field plugin_webapplications_computers_profiles_id
- a link with an object on another plugin named Toto
- class PluginWebapplicationsProfile_Xyz
- table glpi_plugin_webapplications_profiles_xyzs
- file plugins/webapplications/inc/profile_xyz.class.php
- link field plugin_webapplications_profiles_xyzs_id
- a link object inside a plugins