Skip to content

Commit

Permalink
Alter factory to check to make sure the file is readable before inclu…
Browse files Browse the repository at this point in the history
…ding it

git-svn-id: https://svn.php.net/repository/pear/packages/Text_Wiki/trunk@208422 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
Justin Patrin committed Mar 2, 2006
1 parent f6323cc commit ef64889
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions Text/Wiki.php
Expand Up @@ -430,21 +430,27 @@ function &singleton($parser = 'Default', $rules = null)
function &factory($parser = 'Default', $rules = null)
{
$class = 'Text_Wiki_' . $parser;
$file = str_replace('_', '/', $class) . '.php';
if (class_exists($class)) {
$obj =& new $class($rules);
return $obj;
}
if (include_once $file) {
if (class_exists($class)) {
$obj =& new $class($rules);
return $obj;
} else {
$file = str_replace('_', '/', $class).'.php';
if (!class_exists($class)) {
$exists = false;
foreach (split(PATH_SEPARATOR, get_include_path()) as $path) {
if (file_exists($path.'/'.$file)
&& is_readable($path.'/'.$file)) {
$exists = true;
break;
}
}
if (!$exists) {
return PEAR::raiseError('Could not find file '.$file.' in include_path');
}
include_once($file);
if (!class_exists($class)) {
return PEAR::raiseError('Class '.$class.' does not exist after including '.$file);
}
} else {
return PEAR::raiseError('Could not include '.$file);
}

$obj =& new $class($rules);
return $obj;
}

/**
Expand Down

0 comments on commit ef64889

Please sign in to comment.