Skip to content

Commit

Permalink
Merge pull request #140 from znframework/5.9
Browse files Browse the repository at this point in the history
Fixed protected ZN\Exceptions::getTemplateWizardErrorData() method.
  • Loading branch information
ozanuykun committed Sep 3, 2018
2 parents 7c5be2f + cbddd7a commit 8ab86f7
Showing 1 changed file with 43 additions and 29 deletions.
72 changes: 43 additions & 29 deletions ErrorHandling/Exceptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,14 @@ private static function importExceptionTemplate($msg, $file, $line, $no, $trace)
return false;
}

$wizardErrorData = self::getTemplateWizardErrorData();
$wizardErrorData = self::getTemplateWizardErrorData($file, $line);

$exceptionData =
[
'type' => self::$errorCodes[$no] ?? 'ERROR',
'message' => $msg,
'file' => $wizardErrorData->file ?: $file,
'line' => $wizardErrorData->line ?: $line,
'file' => $wizardErrorData->file,
'line' => $wizardErrorData->line,
'trace' => $trace
];

Expand Down Expand Up @@ -292,20 +292,39 @@ protected static function throwFinder($trace, $p1 = 3, $p2 = 5)
*
* @return string|null
*/
protected static function getTemplateWizardErrorData()
protected static function getTemplateWizardErrorData($file, $line)
{
$trace = debug_backtrace()[6]['args'] ?? [NULL];
$args = debug_backtrace()[1]['args'][4] ?? [];
if( strstr($file, DS . 'Buffering.php') )
{
$trace = debug_backtrace()[6]['args'] ?? [NULL];
$args = debug_backtrace()[1]['args'][4] ?? [];

self::searchErrorWizardFile($args, $file, $line);

self::isWizardOrStandartFileExists($file, $trace);
}

return (object)
[
'file' => $file,
'line' => $line
];
}

/**
* Protected search error wizard file
*/
protected static function searchErrorWizardFile($args, &$file, &$line)
{
foreach( $args as $key => $value )
{
if( ! isset($line) && isset($value['file']) && stristr($value['file'], DS . 'Buffering.php') )
{
$line = $value['line'] ?? NULL;
}

if( is_array($value) )
{
if( ! isset($line) && isset($value['file']) && stristr($value['file'], DS . 'Buffering.php') )
{
$line = $value['line'] ?? NULL;
}

$find = $value['args'][0] ?? NULL;

if( is_string($find) && preg_match('/(Views\/)*.*?\.\wizard(\.php)*/', $find) )
Expand All @@ -316,29 +335,14 @@ protected static function getTemplateWizardErrorData()
}
}
}

$file = $file ?? $trace[0] ?? NULL;

if( is_object($file) )
{
$file = VIEWS_DIR . CURRENT_CONTROLLER . '/' . CURRENT_CFUNCTION . '.wizard.php';
}

self::isWizardOrStandartFileExists($file);

return (object)
[
'file' => $file,
'line' => $line ?? NULL
];
}

/**
* Protected is wizard or standart file exists
*/
protected static function isWizardOrStandartFileExists(&$file)
protected static function isWizardOrStandartFileExists(&$file, $trace)
{
if( $file !== NULL && is_string($file) )
if( ! is_file($file) )
{
$file = Base::prefix($file, VIEWS_DIR);

Expand All @@ -348,7 +352,17 @@ protected static function isWizardOrStandartFileExists(&$file)
{
if( ! is_file($rfile = $file . '.wizard.php') )
{
$file = NULL;
if( isset($trace[0]) && is_file($rfile = Base::suffix(Base::prefix($trace[0], VIEWS_DIR), '.php')) )
{
$file = $rfile;
}
else
{
if( ! is_file($rfile) )
{
$file = VIEWS_DIR . CURRENT_CONTROLLER . '/' . CURRENT_CFUNCTION . '.wizard.php';
}
}
}
else
{
Expand Down

0 comments on commit 8ab86f7

Please sign in to comment.