getFile(); if ( \darkphp\string\DwString::startWith( $exceptionFile ,"data://" ) ) $exceptionFileStr = "data"; else $exceptionFileStr = $exceptionFile; $exceptionLine = $exception->getLine(); $throwToStr.= $exceptionFileStr." line:{$exceptionLine} code:".$exception->getCode().\PHP_EOL; $fileContent = \darkphp\autoLoad\DwAutoLoad::decodeFile( $exceptionFile ); $throwToStr.= "\t object '".( DwSource::codeToNs( $fileContent ). "\\" . DwSource::codeToClass( $fileContent ) )."'".\PHP_EOL; $throwToStr.= DwSource::formatFileLine( $exceptionFile ,$exceptionLine ).\PHP_EOL.\PHP_EOL; $excptMsg = $exception->getMessage(); // $excptMsgStackTrace = null; if ( preg_match( '/(.*)Stack trace:(.*)/' ,$excptMsg ,$matches ) ) { $excptMsg = $matches[1]; $excptMsgStackTrace = $matches[2]; } $excptMsgInside = null; if ( preg_match( '/(.*on line \d+)( and at .*)/' ,$excptMsg ,$matches ) ) { $excptMsg = $matches[1]; $excptMsgInside = $matches[2]; } // Extraction de la source encodée if ( preg_match( '/(.*)in data:\/\/.*?,([^ ]+) on line (\d+)/' ,$excptMsg ,$matches ) ) { $coreMsg=$matches[1]; $encoded = $matches[2]; $line = \intval($matches[3]); $decoded = \urldecode($encoded); $exceptionMessage = "$coreMsg in object '".( DwSource::codeToNs( $decoded ). "\\" . DwSource::codeToClass( $decoded ) )."' ligne:{$line}"; } else $exceptionMessage = $excptMsg; $throwToStr.= "\t msg:".\PHP_EOL.$exceptionMessage.\PHP_EOL; //DwSource::getLine( DwAutoLoad::decodeFile( $exception->getFile() ) ,$exception->getLine() ); if ( is_null( $excptMsgStackTrace ) ) { $backTraceArray = $exception->getTrace(); if ( \is_array( $backTraceArray ) ) { $throwToStr.= "---- TRACE".\PHP_EOL; $cpt=0; foreach( $backTraceArray as $index => $backTrace ) { $throwToStr.= DwTrace::traceError( $backTrace ).\PHP_EOL; $cpt++; if ( $cpt > 15 ) { $throwToStr.="!!!!!!!!!!!!!!!!!!!!! cpt break [{$cpt}]".\PHP_EOL; break; } } $throwToStr.= "---- END TRACE".\PHP_EOL; } } else { $throwToStr.= "---- TRACE".\PHP_EOL; $throwToStr.= strlen( $excptMsgStackTrace ).\PHP_EOL; $throwToStr.= "---- END TRACE".\PHP_EOL; } $previous = $exception->getPrevious(); if ( \is_object( $previous ) ) $throwToStr.="PREVIOUS ".self::exceptionToString( $previous ); } else $throwToStr.= $exception.\PHP_EOL; return $throwToStr; } //\darkphp\error\DwException::getDataCode( int $line , string $content ) : array; public static function getDataCode( int $line, string $content) : array { $response=array(); $lineCpt=0; //$response["code-lineno"] = $line; foreach( preg_split( "/((\r?\n)|(\r\n?))/" ,$content ) as $lineStr ) { $lineCpt++; if ( is_string ( strstr( $lineStr, "namespace " ) ) ) $response["c-namespace"]=$lineStr; if ( is_string ( strstr( $lineStr, "class " ) ) ) { if ( isset($response["c-className"]) ) { if ( is_string( $response["c-className"] ) ) { $firstLine = $response["c-className"]; $response["c-className"]=array(); $response["c-className"][]=$firstLine; } $response["c-className"][]="{$lineStr}"; } else $response["c-className"]="{$lineStr}"; } if ( ! isset($response["c-line"]) ) $response["c-line"]=array(); for( $delta=-2; $delta<3; $delta++ ) { if ( $lineCpt == ( $line + $delta ) ) { $response["c-line"][$lineCpt.( $lineCpt == $line ? "!" : "" )]= trim($lineStr); //break; } } } return $response; } /* private static $ignoreError = array( "msg_send(): msgsnd failed: Resource temporarily unavailable" ); public static function error_handle(int $errno, string $errstr, string $errfile = "file?", int $errline = -1, array $errcontext = null) : bool { if ( array_search( $errstr, self::$ignoreError ) === false ) { echo "=================== DwException->error_handle(".getmypid().")\r\n"; echo "l:{$errline}[{$errno}]:$errstr"."\r\n"; echo self::print_r( self::getDataCode( $errline ,self::decodeFile($errfile) ) )."\r\n"; echo json_encode( $errcontext )."\r\n"; } return false; } /* public function getMessage(); // Exception message public function getCode(); // User-defined Exception code public function getFile(); // Source filename public function getLine(); // Source line public function getTrace(); // An array of the backtrace() public static function throwable_handle(\Throwable $exception) : void { try { echo "=================== throwable_handle\r\n"; echo $exception->getMessage()."\r\n".$exception->getCode()."\r\n"; echo DwObject::print_r( self::getDataCode($exception->getLine() ,self::decodeFile($exception->getFile())) ,5)."\r\n"; echo DwObject::print_r( DwException::formatBackTrace( $exception->getTrace() ), 5)."\r\n"; } catch(Exception $anException) { self::$sLog->error("exception [".$this->getClassName()."]"); throw $anException; } catch(Error $anError) { self::$sLog->error("error [".$this->getClassName()."]"); throw $anError; } } */ /* //\bakuba\kernel\logger\darkphp\error\DwException::exceptionToString(); public static function throwableToMessage( $exception ) : string { $throwToStr = "=================== throwableToMessage\r\n"; if ( is_object( $exception ) && method_exists( $exception, "getMessage" ) ) { $throwToStr.= $exception->getMessage()."\r\n".$exception->getCode()."\r\n"; $throwToStr.= DwObject::print_r( DwException::getDataCode( $exception->getLine() ,\darkphp\autoLoad\DwAutoLoad::decodeFile( $exception->getFile() ) ) ,5 )."\r\n"; $backTraceArray = $exception->getTrace(); if (is_array( $backTraceArray ) ) { $cpt=0; foreach( $backTraceArray as $index => $backTrace ) { $throwToStr.= DwObject::print_r( DwException::formatBackTrace( $backTrace ), 7 )."\r\n"; $cpt++; if ( $cpt > 15 ) break; } } } else $throwToStr.= DwObject::print_r( self::formatBackTrace( debug_backtrace( DEBUG_BACKTRACE_IGNORE_ARGS ) ), 7)."\r\n"; return $throwToStr; } //*/ }