<?php
class Util {
    public static function getLastSegment($request_uri) {
        // Get the full URI
        $uri = $request_uri;
        
        // Parse the URI to get the path part
        $parsedUrl = parse_url($uri, PHP_URL_PATH);
        
        // Get the last segment of the path
        $lastSegment = basename($parsedUrl);
        
        return $lastSegment;
    }

    public static function decodeIfBase64($string) {
        $decoded = base64_decode($string, true);
        
        // Check if decoding was successful and if the encoded version matches the original string
        if ($decoded !== false && base64_encode($decoded) === $string) {
            return $decoded; // Return decoded Base64
        }

        return $string; // Return original text if not Base64
    }

     public static function isBase64($string) {
        $decoded = base64_decode($string, true);
        
        // Check if decoding was successful and if the encoded version matches the original string
        if ($decoded !== false && base64_encode($decoded) === $string) {
            return true; // Return decoded Base64
        }

        return false; // Return original text if not Base64
    }
}
?>