Implement an autoloader (#4140)

* Implement an autoloader

When cleaning up classes for psr2, things got a bit unwieldy, so I implemented a class autoloader.
I created a PSR-0 compliant LibreNMS directory and moved all classes there that made sense.
Implemented LibreNMS\ClassLoader which supports adding manual class mappings

This reduces the file includes needed and only loads classes when needed.

* Add teh autoloader to graph.php

* Add a small bit of docs
Fix incomplete class in includes/discovery/functions.inc.php
This commit is contained in:
Tony Murray
2016-08-21 08:07:14 -05:00
committed by Neil Lathwood
parent c2f7602cc5
commit b8e9b2d917
55 changed files with 891 additions and 503 deletions

View File

@ -13,7 +13,6 @@
*/
require_once '../includes/functions.php';
require_once '../includes/component.php';
require_once '../includes/device-groups.inc.php';
if (file_exists('../html/includes/authentication/'.$config['auth_mechanism'].'.inc.php')) {
include '../html/includes/authentication/'.$config['auth_mechanism'].'.inc.php';
@ -513,7 +512,7 @@ function get_components()
// use hostname as device_id if it's all digits
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
$COMPONENT = new component();
$COMPONENT = new LibreNMS\Component();
$components = $COMPONENT->getComponents($device_id, $options);
$output = array(
@ -541,7 +540,7 @@ function add_components()
// use hostname as device_id if it's all digits
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
$COMPONENT = new component();
$COMPONENT = new LibreNMS\Component();
$component = $COMPONENT->createComponent($device_id, $ctype);
$output = array(
@ -566,7 +565,7 @@ function edit_components()
// use hostname as device_id if it's all digits
$device_id = ctype_digit($hostname) ? $hostname : getidbyname($hostname);
$COMPONENT = new component();
$COMPONENT = new LibreNMS\Component();
if ($COMPONENT->setComponentPrefs($device_id, $data)) {
// Edit Success.
@ -599,7 +598,7 @@ function delete_components()
$router = $app->router()->getCurrentRoute()->getParams();
$cid = $router['component'];
$COMPONENT = new component();
$COMPONENT = new LibreNMS\Component();
if ($COMPONENT->deleteComponent($cid)) {
// Edit Success.
$code = 200;