Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion phpdotnet/phd/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static function autoload(string $name): void

return;
}
trigger_error(vsprintf('Cannot find file for %s: %s', [$name, $file ?? $filename]), E_USER_ERROR);
throw new \Error(vsprintf('Cannot find file for %s: %s', [$name, $file ?? $filename]));
}
}

Expand Down
2 changes: 1 addition & 1 deletion phpdotnet/phd/Format/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public final function createFormat($format, ...$formatParams) {
}
return $obj;
}
trigger_error("This format is not supported by this package", E_USER_ERROR);
throw new \Error('This format is not supported by this package');
}

public static final function createFactory($package) {
Expand Down
26 changes: 13 additions & 13 deletions phpdotnet/phd/Options/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,10 +184,10 @@ public function option_d(string $k, mixed $v): array
public function option_docbook(string $k, mixed $v): array
{
if (is_array($v)) {
trigger_error("Can only parse one file at a time", E_USER_ERROR);
throw new \Error('Can only parse one file at a time');
}
if (!file_exists($v) || is_dir($v) || !is_readable($v)) {
trigger_error(sprintf("'%s' is not a readable docbook file", $v), E_USER_ERROR);
throw new \Error(sprintf("'%s' is not a readable docbook file", $v));
}
return [
'xmlRoot' => dirname($v),
Expand All @@ -209,19 +209,19 @@ public function option_o(string $k, mixed $v): array
public function option_output(string $k, mixed $v): array
{
if (is_array($v)) {
trigger_error("Only a single output location can be supplied", E_USER_ERROR);
throw new \Error('Only a single output location can be supplied');
}
if (!file_exists($v)) {
$this->outputHandler->v("Creating output directory..", VERBOSE_MESSAGES);
if (!mkdir($v, 0777, true)) {
trigger_error(vsprintf("Can't create output directory : %s", [$v]), E_USER_ERROR);
throw new \Error(vsprintf("Can't create output directory : %s", [$v]));
}
$this->outputHandler->v("Output directory created", VERBOSE_MESSAGES);
} elseif (!is_dir($v)) {
trigger_error("Output directory is a file?", E_USER_ERROR);
throw new \Error('Output directory is a file?');
}
if (!is_dir($v) || !is_readable($v)) {
trigger_error(sprintf("'%s' is not a valid directory", $v), E_USER_ERROR);
throw new \Error(sprintf("'%s' is not a valid directory", $v));
}
$v = (substr($v, strlen($v) - strlen(DIRECTORY_SEPARATOR)) === DIRECTORY_SEPARATOR) ? $v : ($v . DIRECTORY_SEPARATOR);

Expand All @@ -234,7 +234,7 @@ public function option_output(string $k, mixed $v): array
public function option_outputfilename(string $k, mixed $v): array
{
if (is_array($v)) {
trigger_error("Only a single output location can be supplied", E_USER_ERROR);
throw new \Error('Only a single output location can be supplied');
}
$file = basename($v);

Expand Down Expand Up @@ -281,7 +281,7 @@ public function option_package(string $k, mixed $v): array
foreach((array)$v as $package) {
if (!in_array($package, $this->config->getSupportedPackages())) {
$supported = implode(', ', $this->config->getSupportedPackages());
trigger_error("Invalid Package (Tried: '$package' Supported: '$supported')", E_USER_ERROR);
throw new \Error("Invalid Package (Tried: '$package' Supported: '$supported')");
}
}
return ['package' => (array) $v];
Expand Down Expand Up @@ -341,13 +341,13 @@ public function option_skip(string $k, mixed $v): array
public function option_saveconfig(string $k, mixed $v): array
{
if (is_array($v)) {
trigger_error(sprintf("You cannot pass %s more than once", $k), E_USER_ERROR);
throw new \Error(sprintf('You cannot pass %s more than once', $k));
}

$val = is_bool($v) ? true : self::boolval($v);

if (!is_bool($val)) {
trigger_error("yes/no || on/off || true/false || 1/0 expected", E_USER_ERROR);
throw new \Error('yes/no || on/off || true/false || 1/0 expected');
}

return ['saveConfig' => $val];
Expand Down Expand Up @@ -381,7 +381,7 @@ public function option_verbose(string $k, mixed $v): array
$verbose = max($verbose, 1);
$verbose <<= 1;
} else {
trigger_error("Unknown option passed to --$k, '$const'", E_USER_ERROR);
throw new \Error("Unknown option passed to --$k, '$const'");
}
}
}
Expand Down Expand Up @@ -438,11 +438,11 @@ public function option_c(string $k, mixed $v): array
public function option_color(string $k, mixed $v): array
{
if (is_array($v)) {
trigger_error(sprintf("You cannot pass %s more than once", $k), E_USER_ERROR);
throw new \Error(sprintf('You cannot pass %s more than once', $k));
}
$val = self::boolval($v);
if (!is_bool($val)) {
trigger_error("yes/no || on/off || true/false || 1/0 expected", E_USER_ERROR);
throw new \Error('yes/no || on/off || true/false || 1/0 expected');
}
return ['colorOutput' => $val];
}
Expand Down
8 changes: 4 additions & 4 deletions phpdotnet/phd/Options/Parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ private function validateOptions(): void {
$checkArgv = explode('=', $argv[$i]);
if (substr($checkArgv[0], 0, 2) === '--') {
if (!in_array(substr($checkArgv[0], 2), $long)) {
trigger_error('Invalid long option ' . $argv[$i], E_USER_ERROR);
throw new \Error('Invalid long option ' . $argv[$i]);
}
} elseif (substr($checkArgv[0], 0, 1) === '-') {
if (!in_array(substr($checkArgv[0], 1), $short)) {
trigger_error('Invalid short option ' . $argv[$i], E_USER_ERROR);
throw new \Error('Invalid short option ' . $argv[$i]);
}
}
}
Expand All @@ -98,15 +98,15 @@ public function getopt(): array {

$args = getopt($this->getShortOptions(), $this->getLongOptions());
if ($args === false) {
trigger_error("Something happend with getopt(), please report a bug", E_USER_ERROR);
throw new \Error('Something happend with getopt(), please report a bug');
}

$parsedOptions = [];
foreach ($args as $k => $v) {
$handler = $this->handlerForOption($k);

if (!is_callable($handler)) {
trigger_error("Hmh, something weird has happend, I don't know this option", E_USER_ERROR);
throw new \Error("Hmh, something weird has happend, I don't know this option");
}

$retVal = call_user_func($handler, $k, $v);
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/Generic/ChunkedXHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ public function update($event, $value = null) {
$this->postConstruct();
if (file_exists($this->getOutputDir())) {
if (!is_dir($this->getOutputDir())) {
trigger_error("Output directory is a file?", E_USER_ERROR);
throw new \Error('Output directory is a file?');
}
} else {
if (!mkdir($this->getOutputDir(), 0777, true)) {
trigger_error("Can't create output directory", E_USER_ERROR);
throw new \Error("Can't create output directory");
}
}
if ($this->config->css) {
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/Generic/Manpage.php
Original file line number Diff line number Diff line change
Expand Up @@ -316,11 +316,11 @@ public function update($event, $value = null) {
$this->setOutputDir($this->config->outputDir . strtolower($this->toValidName($this->getFormatName())) . '/');
if (file_exists($this->getOutputDir())) {
if (!is_dir($this->getOutputDir())) {
trigger_error("Output directory is a file?", E_USER_ERROR);
throw new \Error('Output directory is a file?');
}
} else {
if (!mkdir($this->getOutputDir(), 0777, true)) {
trigger_error("Can't create output directory", E_USER_ERROR);
throw new \Error("Can't create output directory");
}
}
break;
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/Generic/TocFeed.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ public function update($event, $value = null)
$dir = $this->getOutputDir();
if (file_exists($dir)) {
if (!is_dir($dir)) {
trigger_error("Output directory is a file?", E_USER_ERROR);
throw new \Error('Output directory is a file?');
}
} else {
if (!mkdir($dir, 0777, true)) {
trigger_error("Can't create output directory", E_USER_ERROR);
throw new \Error("Can't create output directory");
}
}
break;
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/Generic/XHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -678,11 +678,11 @@ protected function fetchStylesheet($name = null) {
$stylesDir .= 'styles/';
if (file_exists($stylesDir)) {
if (!is_dir($stylesDir)) {
trigger_error("The styles/ directory is a file?", E_USER_ERROR);
throw new \Error('The styles/ directory is a file?');
}
} else {
if (!mkdir($stylesDir, 0777, true)) {
trigger_error("Can't create the styles/ directory.", E_USER_ERROR);
throw new \Error("Can't create the styles/ directory.");
}
}
foreach ((array)$this->config->css as $css) {
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/IDE/API.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,10 @@ public function __construct($dir)
: $dir . DIRECTORY_SEPARATOR;
$this->funclist = file($this->dir . self::FUNCLIST_FILE, FILE_IGNORE_NEW_LINES);
} else {
trigger_error('Is the PhD output directory a file?', E_USER_ERROR);
throw new \Error('Is the PhD output directory a file?');
}
} else {
trigger_error('The PhD output directory does not exist.', E_USER_ERROR);
throw new \Error('The PhD output directory does not exist.');
}
}

Expand Down
6 changes: 3 additions & 3 deletions phpdotnet/phd/Package/IDE/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,19 +215,19 @@ public function loadVersionInfo() {
if (file_exists($this->config->phpwebVersionFilename)) {
$this->versions = self::generateVersionInfo($this->config->phpwebVersionFilename);
} else {
trigger_error("Can't load the versions file", E_USER_ERROR);
throw new \Error("Can't load the versions file");
}
}

public function createOutputDirectory() {
$this->setOutputDir($this->config->outputDir . strtolower($this->getFormatName()) . '/');
if (file_exists($this->getOutputDir())) {
if (!is_dir($this->getOutputDir())) {
trigger_error("Output directory is a file?", E_USER_ERROR);
throw new \Error('Output directory is a file?');
}
} else {
if (!mkdir($this->getOutputDir(), 0777, true)) {
trigger_error("Can't create output directory", E_USER_ERROR);
throw new \Error("Can't create output directory");
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions phpdotnet/phd/Package/IDE/demo.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,21 +64,21 @@ function usage()
case 'd':
case 'dir':
if (is_array($v)) {
trigger_error('Is not possible to pass the --dir option more then once', E_USER_ERROR);
throw new \Error('Is not possible to pass the --dir option more then once');
}
$OPTION['dir'] = $v;
break;
case 'f':
case 'function':
if (is_array($v)) {
trigger_error('Is not possible to pass the --function option more then once', E_USER_ERROR);
throw new \Error('Is not possible to pass the --function option more then once');
}
$OPTION['function'] = $v;
break;
case 'c':
case 'class':
if (is_array($v)) {
trigger_error('Is not possible to pass the --class option more then once', E_USER_ERROR);
throw new \Error('Is not possible to pass the --class option more then once');
}
$OPTION['class'] = $v;
break;
Expand Down Expand Up @@ -107,7 +107,7 @@ function usage()
$OPTION['help'] = true;
break;
default:
trigger_error('Invalid Option: ' . $k, E_USER_ERROR);
throw new \Error('Invalid Option: ' . $k);
}
}

Expand All @@ -117,19 +117,19 @@ function usage()
}

if ($OPTION['dir'] == NULL) {
trigger_error('You must specify the PhD output directory with the --dir option.', E_USER_ERROR);
throw new \Error('You must specify the PhD output directory with the --dir option.');
}

if ($OPTION['function'] == NULL && $OPTION['class'] == NULL) {
trigger_error('You must pass either --class or --function options.', E_USER_ERROR);
throw new \Error('You must pass either --class or --function options.');
}

$api = new PhD\Package_IDE_API($OPTION['dir']);

if ($OPTION['class'] != NULL) {
$methods = $api->getMethodsByClass($OPTION['class']);
if ($methods == NULL) {
trigger_error('Invalid Class name: ' . $OPTION['class'], E_USER_ERROR);
throw new \Error('Invalid Class name: ' . $OPTION['class']);
}
foreach ($methods as $method) {
echo $method . PHP_EOL;
Expand All @@ -140,7 +140,7 @@ function usage()
$function = $api->getFunctionByName($OPTION['function']);

if ($function == NULL) {
trigger_error('Invalid Function: ' . $OPTION['function'], E_USER_ERROR);
throw new \Error('Invalid Function: ' . $OPTION['function']);
}

if ($OPTION['signature'] === true) {
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/PEAR/ChunkedXHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,11 +80,11 @@ public function update($event, $value = null) {
$this->postConstruct();
if (file_exists($this->getOutputDir())) {
if (!is_dir($this->getOutputDir())) {
trigger_error("Output directory is a file?", E_USER_ERROR);
throw new \Error('Output directory is a file?');
}
} else {
if (!mkdir($this->getOutputDir(), 0777, true)) {
trigger_error("Can't create output directory", E_USER_ERROR);
throw new \Error("Can't create output directory");
}
}
if ($this->config->css) {
Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/PHP/ChunkedXHTML.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,12 @@ private function mkdir(string $dir): void
{
if (file_exists($dir)) {
if (!is_dir($dir)) {
trigger_error("The specified directory is a file: {$dir}", E_USER_ERROR);
throw new \Error("The specified directory is a file: {$dir}");
}
return;
}
if (!mkdir($dir, 0777, true)) {
trigger_error("Can't create the specified directory: {$dir}", E_USER_ERROR);
throw new \Error("Can't create the specified directory: {$dir}");
}
}

Expand Down
15 changes: 10 additions & 5 deletions phpdotnet/phd/Package/PHP/EnhancedCHM.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,20 @@ public function update($event, $value = null) {
// Use %TEMP%/usernotes as base directory for Usernotes.
$temp = sys_get_temp_dir();
if (!$temp || !is_dir($temp)) {
trigger_error('Unable to locate the systems temporary system directory for EnhancedCHM.', E_USER_ERROR);
throw new \Error('Unable to locate the systems temporary system directory for EnhancedCHM.');
break;
}

$this->userNotesBaseDir = $temp . DIRECTORY_SEPARATOR . 'usernotes' . DIRECTORY_SEPARATOR;

// Make the usernotes directory.
if(!file_exists($this->userNotesBaseDir) || is_file($this->userNotesBaseDir)) {
mkdir($this->userNotesBaseDir, 0777, true) or trigger_error(vsprintf("Can't create the usernotes directory : %s", [$this->userNotesBaseDir]), E_USER_ERROR);
if (!file_exists($this->userNotesBaseDir) || is_file($this->userNotesBaseDir)) {
if (!mkdir($this->userNotesBaseDir, 0777, true)) {
throw new \RuntimeException(sprintf(
"Can't create the usernotes directory: %s",
$this->userNotesBaseDir
));
}
}

// Get the local last-updated value.
Expand All @@ -54,7 +59,7 @@ public function update($event, $value = null) {
}

if (!extension_loaded('bz2')) {
trigger_error('The BZip2 extension is not available.', E_USER_ERROR);
throw new \Error('The BZip2 extension is not available.');
break;
}

Expand All @@ -65,7 +70,7 @@ public function update($event, $value = null) {

// Use a decompression stream filter to save having to store anything locally other than the expanded user notes.
if (false === ($fpNotes = fopen('http://www.php.net/backend/notes/all.bz2', 'rb'))) {
trigger_error('Failed to access the usernotes archive.', E_USER_ERROR);
throw new \Error('Failed to access the usernotes archive.');
break;
}

Expand Down
4 changes: 2 additions & 2 deletions phpdotnet/phd/Package/PHP/HowTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ public function update($event, $value = null) {
$this->postConstruct();
if (file_exists($this->getOutputDir())) {
if (!is_dir($this->getOutputDir())) {
trigger_error("Output directory is a file?", E_USER_ERROR);
throw new \Error('Output directory is a file?');
}
} else {
if (!mkdir($this->getOutputDir(), 0777, true)) {
trigger_error("Can't create output directory", E_USER_ERROR);
throw new \Error("Can't create output directory");
}
}
break;
Expand Down
Loading