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

Feature request: Extending plugin classes #230 (Add hability to extend object class) #242

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ function plugin_uninstall_addUninstallTypes($uninstal_types = []) {
function plugin_genericobject_install() {
global $DB;

include_once(GLPI_ROOT."/plugins/genericobject/inc/object.class.php");
include_once(GLPI_ROOT."/plugins/genericobject/inc/baseobject.class.php");
include_once(GLPI_ROOT."/files/_plugins/genericobject/inc/object.class.php");
include_once(GLPI_ROOT."/plugins/genericobject/inc/type.class.php");

$migration = new Migration(PLUGIN_GENERICOBJECT_VERSION);
Expand Down Expand Up @@ -155,7 +156,8 @@ function plugin_genericobject_install() {
function plugin_genericobject_uninstall() {
global $DB;

include_once(GLPI_ROOT."/plugins/genericobject/inc/object.class.php");
include_once(GLPI_ROOT."/plugins/genericobject/inc/baseobject.class.php");
include_once(GLPI_ROOT."/files/_plugins/genericobject/inc/object.class.php");
include_once(GLPI_ROOT."/plugins/genericobject/inc/type.class.php");

//For each type
Expand Down
2 changes: 1 addition & 1 deletion inc/object.class.php → inc/baseobject.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
@since 2009
---------------------------------------------------------------------- */

class PluginGenericobjectObject extends CommonDBTM {
class PluginGenericobjectBaseObject extends CommonDBTM {

protected $objecttype;

Expand Down
34 changes: 34 additions & 0 deletions objects/object_child.class.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/*
This file is part of the genericobject plugin.

Genericobject plugin is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

Genericobject plugin is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Genericobject. If not, see <http://www.gnu.org/licenses/>.
--------------------------------------------------------------------------
@package genericobject
@author the genericobject plugin team
@copyright Copyright (c) 2010-2011 Order plugin team
@license GPLv2+
http://www.gnu.org/licenses/gpl.txt
@link https://forge.indepnet.n$/projects/genericobject
@link http://www.glpi-project.org/
@since 2009
---------------------------------------------------------------------- */
/**
* Users may customize this class at their own risk. No technical support for customizations.
*/
class PluginGenericobjectObject extends PluginGenericobjectBaseObject {
public function __construct() {
parent::__construct();
}
}
19 changes: 19 additions & 0 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,25 @@
if (file_exists(GENERICOBJECT_DIR . "/log_filter.settings.php")) {
include_once(GENERICOBJECT_DIR . "/log_filter.settings.php");
}
// Backward compatible solution for allowing users to extend core plugin classes.
// All file paths are absolute.
// These are the only core classes that can be extended by users.
// REM: Should happen before autoloader initialization.
$child_classes = [
[
'class_name' => 'PluginGenericobjectObject',
'child_path' => GENERICOBJECT_CLASS_PATH.'/object.class.php',
'template_path' => GENERICOBJECT_DIR.'/objects/object_child.class.tpl',
],
];
foreach ($child_classes as $config) {
if (! file_exists($config['child_path'])) {
file_put_contents(
$config['child_path'],
file_get_contents($config['template_path'])
);
}
}

$go_autoloader = new PluginGenericobjectAutoloader([
GENERICOBJECT_CLASS_PATH
Expand Down