44
55namespace PhpMyAdmin \SqlParser ;
66
7- use PhpMyAdmin \SqlParser \Exceptions \LoaderException ;
8-
97use function class_exists ;
108use function explode ;
119use function in_array ;
@@ -526,9 +524,9 @@ public static function isSeparator(string $string): bool
526524 *
527525 * @param string $context name of the context or full class name that defines the context
528526 *
529- * @throws LoaderException if the specified context doesn't exist.
527+ * @return bool true if the context was loaded, false otherwise
530528 */
531- public static function load (string $ context = '' ): void
529+ public static function load (string $ context = '' ): bool
532530 {
533531 if (empty ($ context )) {
534532 $ context = self ::$ defaultContext ;
@@ -540,11 +538,13 @@ public static function load(string $context = ''): void
540538 }
541539
542540 if (! class_exists ($ context )) {
543- throw @ new LoaderException ( ' Specified context (" ' . $ context . ' ") does not exist. ' , $ context ) ;
541+ return false ;
544542 }
545543
546544 self ::$ loadedContext = $ context ;
547545 self ::$ keywords = $ context ::$ keywords ;
546+
547+ return true ;
548548 }
549549
550550 /**
@@ -563,24 +563,22 @@ public static function loadClosest(string $context = ''): ?string
563563 {
564564 $ length = strlen ($ context );
565565 for ($ i = $ length ; $ i > 0 ;) {
566- try {
567- /* Trying to load the new context */
568- static ::load ($ context );
569-
566+ /* Trying to load the new context */
567+ if (static ::load ($ context )) {
570568 return $ context ;
571- } catch (LoaderException $ e ) {
572- /* Replace last two non zero digits by zeroes */
573- do {
574- $ i -= 2 ;
575- $ part = substr ($ context , $ i , 2 );
576- /* No more numeric parts to strip */
577- if (! is_numeric ($ part )) {
578- break 2 ;
579- }
580- } while (intval ($ part ) === 0 && $ i > 0 );
581-
582- $ context = substr ($ context , 0 , $ i ) . '00 ' . substr ($ context , $ i + 2 );
583569 }
570+
571+ /* Replace last two non zero digits by zeroes */
572+ do {
573+ $ i -= 2 ;
574+ $ part = substr ($ context , $ i , 2 );
575+ /* No more numeric parts to strip */
576+ if (! is_numeric ($ part )) {
577+ break 2 ;
578+ }
579+ } while (intval ($ part ) === 0 && $ i > 0 );
580+
581+ $ context = substr ($ context , 0 , $ i ) . '00 ' . substr ($ context , $ i + 2 );
584582 }
585583
586584 /* Fallback to loading at least matching engine */
0 commit comments