تجذیه و تحلیل یه کلاس مهم

delphii

Member
یه کلاس هست که یه مدت هست که دارم روش کار می کنم ولی هنوز نتونستم تجذیه تحلیلش کنم اگه یکی پیدا بشه و توابع این کلاس رو برام تجذیه و تحلیل کنه و بگه که این توابع چه کار می کنند ممنون میشم.


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;
}
}
 
آخرین ویرایش:

hidensoft

Member
PHP:
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;
}
}
 

yakoza

Well-Known Member
به آقا محمد چه عجب از این ورا

آقا تا اونجا که من فهمیدم این کلاس آدرس یه فایل رو و اسم کلاس رو ازت میگیره در صورت وجود اونو و است لود میکنه

کدشم چیز خاصی نداری ولی هر جاشو متوجه نشدی بگو توضیح بدم

قربانت ناصر
 

delphii

Member
از اقا محمد ممنونم که کد رو مرتب کردن

این کد مربوط به یکی از صفحات joomla میشه . من میخوام بدونم دو تا تابع import ,register دقیقا چه کاری رو انجام میدن .
 

yakoza

Well-Known Member
آقا این کلاس یه جورایی __autoload تو php5
(البته برا اساتید بگم که گفتم یه جورای شبیه به اونه نه خود اون )

هرجاشو نفهمیدی بگو توضیح بدم

موفق باشی
 
آخرین ویرایش:

جدیدترین ارسال ها

بالا