Skip to content

Commit

Permalink
Add shared code for testing class availability
Browse files Browse the repository at this point in the history
Signed-off-by: Michal Čihař <michal@cihar.com>
  • Loading branch information
nijel committed Feb 22, 2016
1 parent 38482bf commit 9ae4bd5
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 20 deletions.
2 changes: 0 additions & 2 deletions libraries/PDF.php
Expand Up @@ -10,8 +10,6 @@
use TCPDF;
use TCPDF_FONTS;

require_once TCPDF_INC;

/**
* PDF export base class providing basic configuration.
*
Expand Down
16 changes: 16 additions & 0 deletions libraries/Util.php
Expand Up @@ -14,6 +14,7 @@
use SqlParser\Token;
use stdClass;
use SqlParser\Utils\Error as ParserError;
use Composer;

if (! defined('PHPMYADMIN')) {
exit;
Expand Down Expand Up @@ -4982,5 +4983,20 @@ public static function listPHPExtensions()

return $result;
}

/**
* Checks whether given class exists or can be auto loaded.
*/
public static function checkClass($class)
{
if (class_exists($class)) {
return true;
}
$loader = new Composer\Autoload\ClassLoader();
if ($loader->loadClass($class)) {
return true;
}
return false;
}
}

23 changes: 10 additions & 13 deletions libraries/navigation/NodeFactory.php
Expand Up @@ -8,7 +8,7 @@
namespace PMA\libraries\navigation;

use PMA\libraries\navigation\nodes\Node;
use Composer;
use PMA\libraries\Util;

/**
* Node factory - instantiates Node objects or objects derived from the Node class
Expand Down Expand Up @@ -55,18 +55,15 @@ private static function _checkClass($class)
{
$class = sprintf(self::$_namespace, $class);

if (!class_exists($class)) {
$loader = new Composer\Autoload\ClassLoader();
if (!$loader->loadClass($class)) {
$class = sprintf(self::$_namespace, 'Node');
trigger_error(
sprintf(
__('Could not load class "%1$s"'),
$class
),
E_USER_ERROR
);
}
if (! Util::checkClass($class)) {
$class = sprintf(self::$_namespace, 'Node');
trigger_error(
sprintf(
__('Could not load class "%1$s"'),
$class
),
E_USER_ERROR
);
}

return $class;
Expand Down
5 changes: 0 additions & 5 deletions libraries/vendor_config.php
Expand Up @@ -73,11 +73,6 @@
* eg. /usr/share/php/gettext/gettext.inc.
*/
define('GETTEXT_INC', './libraries/php-gettext/gettext.inc');
/**
* Path to tcpdf.php file. Useful when you want to use system tcpdf,
* eg. /usr/share/php/tcpdf/tcpdf.php.
*/
define('TCPDF_INC', './libraries/tcpdf/tcpdf.php');

/**
* Path to files with compiled locales (*.mo)
Expand Down

0 comments on commit 9ae4bd5

Please sign in to comment.