PHP Classes

File: examples/kernel/enums/debuglevel/debuglevel.example.php

Recommend this page to a friend!
  Packages of Christos Drogidis   Ascoos OS   examples/kernel/enums/debuglevel/debuglevel.example.php   Download  
File: examples/kernel/enums/debuglevel/debuglevel.example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: Ascoos OS
A PHP Web 5.0 Kernel for decentralized web and IoT
Author: By
Last change:
Date: 15 days ago
Size: 3,516 bytes
 

Contents

Class file image Download
<?php
/*
dobu {
    file:id(`example-00000300`) {
        ascoos {
            logo {`
                  __ _ ___ ___ ___ ___ ___ ___ ___
                 / _' |/ / / __/ _ \ / _ \ / / / _ \ / /
                | (_| |\ \| (_| (_) | (_) |\ \ | (_) |\ \
                 \__,_|/__/ \___\___/ \___/ /__/ \___/ /__/
            `},
            name {`ASCOOS OS`},
            version {`1.0.0`},
        },
        example {
            enum {`DebugLevel`},
            source {`kernel/enums/debuglevel/debuglevel.example.php`},
            category:lang {
                en {`Debugging and Error Classification`},
                el {`????????????? ??? ??????????????? ?????????`}
            },
            subcategory:langs {
                en {`Using DebugLevel in Custom Exceptions`},
                el {`????? ??? DebugLevel ?? ?????????????? ??????????`}
            },
            summary:langs {
                en {`Demonstrates how the DebugLevel enum can be used to classify exception messages.`},
                el {`??????? ??? ?? enum DebugLevel ?????? ?? ?????????????? ??? ??? ??????????????? ????????? ??????????.`}
            },
            desc:langs {
                en {`This example shows how a custom exception class can accept a DebugLevel enum value and produce different messages depending on the selected debug level.
                    The match expression maps each DebugLevel case to a specific HTTP?style error message, demonstrating how enums can replace legacy constants and improve type safety in exception handling.`},
                el {`?? ?????????? ??????? ??? ??? ????????????? ????? ????????? ?????? ?? ??????? ??? ???? enum DebugLevel ??? ?? ??????? ??????????? ???????? ??????? ?? ?? ?????????? ??????? ??????????????.
                    ? ??????? match ????????????? ???? case ??? DebugLevel ?? ??? ???????????? ?????? ????????? ????? HTTP, ?????????? ??? ?? enums ??????? ?? ??????????????? ??????? ????? ???????? ??? ?? ?????????? ??? ?????????? ???? ???????? ??????????.`}
            },
            author {`Drogidis Christos`},
            since {`1.0.0`},
            sincePHP {`8.4.0`}
        }
    }
}
*/
declare(strict_types=1);

use
ASCOOS\OS\Kernel\Core\DebugLevel;

$startTime = microtime(true);
$startMem = memory_get_usage();

class
MyException extends Exception {
    function
__construct(private DebugLevel $dbg)
    {
       
match($dbg){
           
DebugLevel::Info => parent::__construct("Bad Request - Information Message", 400),
           
DebugLevel::Warning => parent::__construct("Bad Request - Warning Message", 400),
           
DebugLevel::Error => parent::__construct("Bad Request - Error Message", 400)
        };
    }
}

// Testing my custom exception class
try {
    throw new
MyException(DebugLevel::Info);
} catch (
MyException $e) {
    echo
$e->getMessage(); // Bad Request - Information Message
}

print_stats($startTime, $startMem);
?>