Jump to content

problem with multiple _autoload functions


samoht

Recommended Posts

hello all,

 

I have a client that wants to integrate his installer api files into the website that is allowing the download of the software. The problem I have integrating them is that the CMS for the website uses the _autoload function and so does the installer api functions.php

 

i get this error:

Fatal error: Uncaught exception 'LogicException' with message 'Function 'Joomla_Autoload' not found' in /var/www/sin/mywebpage.com/libraries/loader.php:197 Stack trace: #0 /var/www/sin/mywebpage.com/libraries/loader.php(197): spl_autoload_register('Joomla_Autoload') #1 /var/www/sin/mywebpage.com/libraries/joomla/import.php(21): require_once('/var/www/sin/su...') #2 /var/www/sin/mywebpage.com/includes/framework.php(42): require_once('/var/www/sin/su...') #3 /var/www/sin/mywebpage.com/index.php(22): require_once('/var/www/sin/su...') #4 {main} thrown in /var/www/sin/mywebpage.com/libraries/loader.php on line 197

 

and here is the loader.php of the CMS

<?php
if(!defined('DS')) {
define( 'DS', DIRECTORY_SEPARATOR );
}

/**
* @package		Joomla.Framework
*/
class JLoader
{
 /**
 * Loads a class from specified directories.
 *
 * @param string $name	The class name to look for ( dot notation ).
 * @param string $base	Search this directory for the class.
 * @param string $key	String used as a prefix to denote the full path of the file ( dot notation ).
 * @return void
 * @since 1.5
 */
function import( $filePath, $base = null, $key = 'libraries.' )
{
	static $paths;

	if (!isset($paths)) {
		$paths = array();
	}

	$keyPath = $key ? $key . $filePath : $filePath;

	if (!isset($paths[$keyPath]))
	{
		if ( ! $base ) {
			$base =  dirname( __FILE__ );
		}

		$parts = explode( '.', $filePath );

		$classname = array_pop( $parts );
		switch($classname)
		{
			case 'helper' :
				$classname = ucfirst(array_pop( $parts )).ucfirst($classname);
				break;

			default :
				$classname = ucfirst($classname);
				break;
		}

		$path  = str_replace( '.', DS, $filePath );

		if (strpos($filePath, 'joomla') === 0)
		{
			/*
			 * If we are loading a joomla class prepend the classname with a
			 * capital J.
			 */
			$classname	= 'J'.$classname;
			$classes	= JLoader::register($classname, $base.DS.$path.'.php');
			$rs			= isset($classes[strtolower($classname)]);
		}
		else
		{
			/*
			 * If it is not in the joomla namespace then we have no idea if
			 * it uses our pattern for class names/files so just include.
			 */
			$rs   = include($base.DS.$path.'.php');
		}

		$paths[$keyPath] = $rs;
	}

	return $paths[$keyPath];
}

/**
 * Add a class to autoload
 *
 * @param	string $classname	The class name
 * @param	string $file		Full path to the file that holds the class
 * @return	array|boolean  		Array of classes
 * @since 	1.5
 */
function & register ($class = null, $file = null)
{
	static $classes;

	if(!isset($classes)) {
		$classes    = array();
	}

	if($class && is_file($file))
	{
		// Force to lower case.
		$class = strtolower($class);
		$classes[$class] = $file;

		// In php4 we load the class immediately.
		if((version_compare( phpversion(), '5.0' ) < 0)) {
			JLoader::load($class);
		}

	}

	return $classes;
}


/**
 * Load the file for a class
 *
 * @access  public
 * @param   string  $class  The class that will be loaded
 * @return  boolean True on success
 * @since   1.5
 */
function load( $class )
{
	$class = strtolower($class); //force to lower case

	if (class_exists($class)) {
		  return;
	}

	$classes = JLoader::register();
	if(array_key_exists( strtolower($class), $classes)) {
		include($classes[$class]);
		return true;
	}
	return false;
}
}


/**
* When calling a class that hasn't been defined, __autoload will attempt to
* include the correct file for that class.
*
* This function get's called by PHP. Never call this function yourself.
*
* @param 	string 	$class
* @access 	public
* @return  boolean
* @since   1.5
*/
function Joomla__Autoload($class)
{
if(JLoader::load($class)) {
	return true;
}
return false;
}

/**
* Global application exit.
*
* This function provides a single exit point for the framework.
*
* @param mixed Exit code or string. Defaults to zero.
*/
function jexit($message = 0) {
    exit($message);
}

/**
* Intelligent file importer
*
* @access public
* @param string $path A dot syntax path
* @since 1.5
*/
function jimport( $path ) {
return JLoader::import($path);
}

/*** nullify any existing autoloads ***/
spl_autoload_register(null, false);

/*** specify extensions that may be loaded ***/
spl_autoload_extensions('.php, .class.php, .lib.php');

/*** register the loader functions ***/
spl_autoload_register('Joomla_Autoload');

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.