3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ namespace epay; use SplFileObject; /** * TODO * -- ACT: complete all method bodies * -- DUE: 17 Apr. 2014 * -- MOD: 15 Apr. 2014 */ /** * Description of Logger * * @author Talaeedeh */ class Logger { /** * Public * Used for exporting log files. Must be unique per Logger. * * @var String complete output filename (eg. "output.log") */ public $FILENAME; /** * Public * Used for exporting log files. Must be followed by * a \ at the end. * * @var String absolute output path (eg. "C:\\Program Files(x86)\\App\\") */ public $PATH; /** * Protected * The level of importance of logs that will be recorded. * Zero means log nothing * * @var LogLevel (int) Level of log importance */ public $LEVEL; /** * String representation of current message in LogLevel::EVERYTHING. * * @var Array(LogLevel,String) Current message */ protected $CMESSAGE; /** * String representation of messages in LogLevel::EVERYTHING that * are not yet recorded or purged. * * @var SplQueue(Array(LogLevel,String)) last messages */ protected $LMESSAGES; /* MARKED4DEL * -- REASON: Added Log level of current message into current message * using TYPEX String : Array(LogLevel,String) * * /** * * Level of importance of current message * * stored in $CMESSAGE * * * * @var LogLevel(int) CMESSAGE's level of importance * *\/ * protected $CLEVEL; */ /** * Write Log * * Writing the log messages stored in $MESSAGES into the file * specified by $PATH . $FILENAME. * * @param SplQueue(Array(LogLevel,String)) $MESSAGES Pending messages to be written. * @return Array(LogLevel,String) NULL if successful, Error message otherwise. */ protected function WriteLog($MESSAGES) { } /** * Purge Messages * * Purging log messages stored in $MESSAGES permenantly. * * -- !WARNING: Make sure you have written all necessary messages into a file * before purging. Purging is irreversible and all contents in * $MESSAGES will be inaccessible afterwards. * * @param SplQueue(Array(LogLevel,String)) $MESSAGES Pending messages to be written. * @return Array(LogLevel,String) NULL if successful, Error message otherwise. */ protected function Purge(&$MESSAGES) { } /** * Export Messages * * Essentialy writes log messages into the specified file using $PATH . $FILENAME * follows by purging all messages inside $MESSAGES. * * -- !WARNING: Exporting is irreversible. * * @param SplQueue(Array(LogLevel,String)) $MESSAGES Pending messages to be written. * @return Array(LogLevel,String) NULL if successful, Error message otherwise. */ public function Export(&$MESSAGES) { } /** * !FIXME: * -- PROBLEM: @author Talaeezadeh * got tired for today; end of work time at 7:30. * -- DUE: 16 Apr. 2014 * -- MOD: 15 Apr. 2014 */ /** * Import Messages * * Purges all messages inside $MESSAGES and imports a chunk of log-file * specified by $PATH . $FILENAM. * * -- !WARNING: Importing is irreversible. * * @param SplQueue(Array(LogLevel,String)) $MESSAGES Pending messages to be written. * @param Int $BEGIN OPTIONAL: First error no. to be imported. Inclusive. * @param Int $END OPTIONAL: Last error no. to be imported. Exclusive. * @return SplQueue(Array(LogLevel,String)) NULL if successful, Error messages otherwise. */ public function Import(SplQueue &$MESSAGES) { /** * @var Array(LogLevel,String) Error. */ $err = NULL; /** * @var Int Number of arguments. */ $num_args = func_num_args() > 3; /** * Checking for errors in arguments. */ if ($num_args > 3) { $err = array (LogLevel::WARNING, "WARNING @" . __FILE__ . " line". __LINE__ .": " . __TRAIT__ . " says: \'Unexpected argument. Escaped!\'"); echo $err[1]; return $err; } elseif ($num_args == 0) { $err = array (LogLevel::WARNING, "WARNING @" . __FILE__ . " line ". __LINE__ .": " . __TRAIT__ . " says: \'No arguments. Escaped!\'"); echo $err[1]; return $err; } /** * Setting Optional Arguments. */ if ($num_args > 1) { $BEGIN = func_get_arg(1); } if ($num_args > 2) { $END = func_get_arg(2); } /** * Setting up file handler and purge the $MESSAGES. */ /** * @var Resource A resource handler to log file to be processed. */ $fileHNDL = new SplFileObject($this->PATH . $this->FILENAME, 'r'); /** * Check if file exists. If not, returns with the error message. */ if ($fileHNDL === \NULL) { $err = array (LogLevel::ERROR, "ERROR @" . __FILE__ . " line ". __LINE__ .": " . __TRAIT__ . " says: \'File not found. Escaped!\'"); echo $err[1]; return $err; }; /** * Purge the $MESSAGES empty. */ $this->Purge($MESSAGES); /** * Reading desired parts of the file. */ /** * FIXME: * -- PROBLEM: If the user specified begining excedes file length. * -- DUE: 16 Apr. 2014 * -- MOD: 15 Apr. 2014 * -- FIN: 13 Apr. 2014 13:47 THR */ /** * Checking if the user specified begining excedes file length. */ $fileHNDL->seek($BEGIN); if ($fileHNDL->eof()) { $err = array (LogLevel::WARNING, "WARNING @" . __FILE__ . " line ". __LINE__ .": " . __TRAIT__ . " says: \'The line $BEGIN does not exist in current content!\'"); echo $err[1]; return $err; } /** * If there is the $END parameter available by user. */ if (isset($END)) { for ($i = $BEGIN; $i < $END; $i++) { $fileHNDL->seek($i); /** * Unexpected end of file reached. */ if ($fileHNDL->eof()) { break; } /** * @var String Temporary storage for the current line of log being processed. */ $tmpLine = $fileHNDL->current(); /** * TODO: * -- ACT: Extract LogLevel and String Messages from $tmpLine. * and remove stubs: $matchedLevel and $matchedMessage. * -- DUE: 16 Apr. 2014 * -- MOD: 15 Apr. 2014 * -- FIN: 16 Apr. 2014 13:25 THR */ /** * Extracting LogLevel and String Messages from $tmpLine. */ /** * @var Array(String) Temporary storage for current log importance level extraction. */ $tmpMatches = array(); /** * Extraction. Macthes $tmpLine to a RegX explaining uppercase substrings. */ preg_match("/[A-Z]+/", $tmpLine, $tmpMatches); /** * @var LogLevel The importance level of current log entry. */ $matchedLevel = constant("epay\LogLevel::$tmpMatches[0]"); /** * @var String The message contained in the current log entry. */ $matchedMessage = str_replace($tmpMatches[0] . '', "" , $tmpLine); $MESSAGES->enqueue(array($matchedLevel,$matchedMessage)); } } /** * If $End parameter is not provided by user, read until the end of file. */ else { $i = $BEGIN; $fileHNDL->seek($i); do { $tmpLine = $fileHNDL->current(); /** * TODO: * -- ACT: Extract LogLevel and String Messages from $tmpLine. * and remove stubs: $matchedLevel and $matchedMessage. * -- DUE: 16 Apr. 2014 * -- MOD: 15 Apr. 2014 * -- FIN: 16 Apr. 2014 13:25 THR */ /** * Extracting LogLevel and String Messages from $tmpLine. */ /** * @var Array(String) Temporary storage for current log importance level extraction. */ $tmpMatches = array(); /** * Extraction. Macthes $tmpLine to a RegX explaining uppercase substrings. */ preg_match("/[A-Z]+/", $tmpLine, $tmpMatches); /** * @var LogLevel The importance level of current log entry. */ $matchedLevel = constant("epay\LogLevel::$tmpMatches[0]"); /** * @var String The message contained in the current log entry. */ $matchedMessage = str_replace($tmpMatches[0] . '', "" , $tmpLine); $MESSAGES->enqueue(array($matchedLevel,$matchedMessage)); $i++; $fileHNDL->seek($i); } while (!$fileHNDL->eof()); } /** * Freeing up the file handler resource so it could be closed. */ $fileHNDL = \NULL; } /** * This is the Logger's constructor */ public function __construct() { } /** * This is the Logger's destructor */ public function __destruct() { } /** * This is the ToString defult function */ public function __toString() { } } $newLogger = new Logger(); $newLogger->Import($MESSAGES);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5pgKZ
function name:  (null)
number of ops:  8
compiled vars:  !0 = $newLogger, !1 = $MESSAGES
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   25     0  E >   DECLARE_CLASS                                            'epay%5Clogger'
  385     1        NEW                                              $2      'epay%5CLogger'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
  386     4        INIT_METHOD_CALL                                         !0, 'Import'
          5        SEND_VAR_EX                                              !1
          6        DO_FCALL                                      0          
          7      > RETURN                                                   1

Class epay\Logger:
Function writelog:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5pgKZ
function name:  WriteLog
number of ops:  2
compiled vars:  !0 = $MESSAGES
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   91     0  E >   RECV                                             !0      
   94     1      > RETURN                                                   null

End of function writelog

Function purge:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5pgKZ
function name:  Purge
number of ops:  2
compiled vars:  !0 = $MESSAGES
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  108     0  E >   RECV                                             !0      
  111     1      > RETURN                                                   null

End of function purge

Function export:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5pgKZ
function name:  Export
number of ops:  2
compiled vars:  !0 = $MESSAGES
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  124     0  E >   RECV                                             !0      
  127     1      > RETURN                                                   null

End of function export

Function import:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 8, Position 2 = 16
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 18, Position 2 = 25
Branch analysis from position: 18
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 25
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 31
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 33, Position 2 = 37
Branch analysis from position: 33
2 jumps found. (Code = 43) Position 1 = 47, Position 2 = 54
Branch analysis from position: 47
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 54
2 jumps found. (Code = 43) Position 1 = 63, Position 2 = 74
Branch analysis from position: 63
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 74
2 jumps found. (Code = 43) Position 1 = 76, Position 2 = 118
Branch analysis from position: 76
1 jumps found. (Code = 42) Position 1 = 115
Branch analysis from position: 115
2 jumps found. (Code = 44) Position 1 = 117, Position 2 = 78
Branch analysis from position: 117
1 jumps found. (Code = 42) Position 1 = 159
Branch analysis from position: 159
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 78
2 jumps found. (Code = 43) Position 1 = 84, Position 2 = 85
Branch analysis from position: 84
1 jumps found. (Code = 42) Position 1 = 117
Branch analysis from position: 117
Branch analysis from position: 85
2 jumps found. (Code = 44) Position 1 = 117, Position 2 = 78
Branch analysis from position: 117
Branch analysis from position: 78
Branch analysis from position: 118
2 jumps found. (Code = 44) Position 1 = 159, Position 2 = 122
Branch analysis from position: 159
Branch analysis from position: 122
Branch analysis from position: 37
Branch analysis from position: 31
filename:       /in/5pgKZ
function name:  Import
number of ops:  161
compiled vars:  !0 = $MESSAGES, !1 = $err, !2 = $num_args, !3 = $BEGIN, !4 = $END, !5 = $fileHNDL, !6 = $i, !7 = $tmpLine, !8 = $tmpMatches, !9 = $matchedLevel, !10 = $matchedMessage
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  150     0  E >   RECV                                             !0      
  155     1        ASSIGN                                                   !1, null
  160     2        INIT_NS_FCALL_BY_NAME                                    'epay%5Cfunc_num_args'
          3        DO_FCALL                                      0  $12     
          4        IS_SMALLER                                       ~13     3, $12
          5        ASSIGN                                                   !2, ~13
  165     6        IS_SMALLER                                               3, !2
          7      > JMPZ                                                     ~15, ->16
  167     8    >   FETCH_CLASS_CONSTANT                             ~16     'epay%5CLogLevel', 'WARNING'
          9        INIT_ARRAY                                       ~17     ~16
         10        ADD_ARRAY_ELEMENT                                ~17     'WARNING+%40%2Fin%2F5pgKZ+line168%3A++says%3A+%5C%27Unexpected+argument.+Escaped%21%5C%27'
         11        ASSIGN                                                   !1, ~17
  170    12        FETCH_DIM_R                                      ~19     !1, 1
         13        ECHO                                                     ~19
  171    14      > RETURN                                                   !1
         15*       JMP                                                      ->25
  173    16    >   IS_EQUAL                                                 !2, 0
         17      > JMPZ                                                     ~20, ->25
  175    18    >   FETCH_CLASS_CONSTANT                             ~21     'epay%5CLogLevel', 'WARNING'
         19        INIT_ARRAY                                       ~22     ~21
         20        ADD_ARRAY_ELEMENT                                ~22     'WARNING+%40%2Fin%2F5pgKZ+line+176%3A++says%3A+%5C%27No+arguments.+Escaped%21%5C%27'
         21        ASSIGN                                                   !1, ~22
  178    22        FETCH_DIM_R                                      ~24     !1, 1
         23        ECHO                                                     ~24
  179    24      > RETURN                                                   !1
  185    25    >   IS_SMALLER                                               1, !2
         26      > JMPZ                                                     ~25, ->31
  187    27    >   INIT_NS_FCALL_BY_NAME                                    'epay%5Cfunc_get_arg'
         28        SEND_VAL_EX                                              1
         29        DO_FCALL                                      0  $26     
         30        ASSIGN                                                   !3, $26
  189    31    >   IS_SMALLER                                               2, !2
         32      > JMPZ                                                     ~28, ->37
  191    33    >   INIT_NS_FCALL_BY_NAME                                    'epay%5Cfunc_get_arg'
         34        SEND_VAL_EX                                              2
         35        DO_FCALL                                      0  $29     
         36        ASSIGN                                                   !4, $29
  201    37    >   NEW                                              $31     'SplFileObject'
         38        FETCH_OBJ_R                                      ~32     'PATH'
         39        FETCH_OBJ_R                                      ~33     'FILENAME'
         40        CONCAT                                           ~34     ~32, ~33
         41        SEND_VAL_EX                                              ~34
         42        SEND_VAL_EX                                              'r'
         43        DO_FCALL                                      0          
         44        ASSIGN                                                   !5, $31
  206    45        TYPE_CHECK                                    2          !5
         46      > JMPZ                                                     ~37, ->54
  208    47    >   FETCH_CLASS_CONSTANT                             ~38     'epay%5CLogLevel', 'ERROR'
         48        INIT_ARRAY                                       ~39     ~38
         49        ADD_ARRAY_ELEMENT                                ~39     'ERROR+%40%2Fin%2F5pgKZ+line+209%3A++says%3A+%5C%27File+not+found.+Escaped%21%5C%27'
         50        ASSIGN                                                   !1, ~39
  211    51        FETCH_DIM_R                                      ~41     !1, 1
         52        ECHO                                                     ~41
  212    53      > RETURN                                                   !1
  218    54    >   INIT_METHOD_CALL                                         'Purge'
         55        SEND_VAR_EX                                              !0
         56        DO_FCALL                                      0          
  235    57        INIT_METHOD_CALL                                         !5, 'seek'
         58        SEND_VAR_EX                                              !3
         59        DO_FCALL                                      0          
  236    60        INIT_METHOD_CALL                                         !5, 'eof'
         61        DO_FCALL                                      0  $44     
         62      > JMPZ                                                     $44, ->74
  238    63    >   FETCH_CLASS_CONSTANT                             ~45     'epay%5CLogLevel', 'WARNING'
         64        INIT_ARRAY                                       ~46     ~45
  240    65        ROPE_INIT                                     3  ~48     '+says%3A+%5C%27The+line+'
         66        ROPE_ADD                                      1  ~48     ~48, !3
         67        ROPE_END                                      2  ~47     ~48, '+does+not+exist+in+current+content%21%5C%27'
         68        CONCAT                                           ~50     'WARNING+%40%2Fin%2F5pgKZ+line+239%3A+', ~47
         69        ADD_ARRAY_ELEMENT                                ~46     ~50
  238    70        ASSIGN                                                   !1, ~46
  241    71        FETCH_DIM_R                                      ~52     !1, 1
         72        ECHO                                                     ~52
  242    73      > RETURN                                                   !1
  248    74    >   ISSET_ISEMPTY_CV                                         !4
         75      > JMPZ                                                     ~53, ->118
  250    76    >   ASSIGN                                                   !6, !3
         77      > JMP                                                      ->115
  252    78    >   INIT_METHOD_CALL                                         !5, 'seek'
         79        SEND_VAR_EX                                              !6
         80        DO_FCALL                                      0          
  257    81        INIT_METHOD_CALL                                         !5, 'eof'
         82        DO_FCALL                                      0  $56     
         83      > JMPZ                                                     $56, ->85
  259    84    > > JMP                                                      ->117
  265    85    >   INIT_METHOD_CALL                                         !5, 'current'
         86        DO_FCALL                                      0  $57     
         87        ASSIGN                                                   !7, $57
  284    88        ASSIGN                                                   !8, <array>
  289    89        INIT_NS_FCALL_BY_NAME                                    'epay%5Cpreg_match'
         90        SEND_VAL_EX                                              '%2F%5BA-Z%5D%2B%2F'
         91        SEND_VAR_EX                                              !7
         92        SEND_VAR_EX                                              !8
         93        DO_FCALL                                      0          
  294    94        INIT_NS_FCALL_BY_NAME                                    'epay%5Cconstant'
         95        NOP                                                      
         96        FETCH_DIM_R                                      ~61     !8, 0
         97        FAST_CONCAT                                      ~62     'epay%5CLogLevel%3A%3A', ~61
         98        SEND_VAL_EX                                              ~62
         99        DO_FCALL                                      0  $63     
        100        ASSIGN                                                   !9, $63
  299   101        INIT_NS_FCALL_BY_NAME                                    'epay%5Cstr_replace'
        102        FETCH_DIM_R                                      ~65     !8, 0
        103        CONCAT                                           ~66     ~65, ''
        104        SEND_VAL_EX                                              ~66
        105        SEND_VAL_EX                                              ''
        106        SEND_VAR_EX                                              !7
        107        DO_FCALL                                      0  $67     
        108        ASSIGN                                                   !10, $67
  301   109        INIT_METHOD_CALL                                         !0, 'enqueue'
        110        INIT_ARRAY                                       ~69     !9
        111        ADD_ARRAY_ELEMENT                                ~69     !10
        112        SEND_VAL_EX                                              ~69
        113        DO_FCALL                                      0          
  250   114        PRE_INC                                                  !6
        115    >   IS_SMALLER                                               !6, !4
        116      > JMPNZ                                                    ~72, ->78
        117    > > JMP                                                      ->159
  310   118    >   ASSIGN                                                   !6, !3
  311   119        INIT_METHOD_CALL                                         !5, 'seek'
        120        SEND_VAR_EX                                              !6
        121        DO_FCALL                                      0          
  314   122    >   INIT_METHOD_CALL                                         !5, 'current'
        123        DO_FCALL                                      0  $75     
        124        ASSIGN                                                   !7, $75
  332   125        ASSIGN                                                   !8, <array>
  337   126        INIT_NS_FCALL_BY_NAME                                    'epay%5Cpreg_match'
        127        SEND_VAL_EX                                              '%2F%5BA-Z%5D%2B%2F'
        128        SEND_VAR_EX                                              !7
        129        SEND_VAR_EX                                              !8
        130        DO_FCALL                                      0          
  342   131        INIT_NS_FCALL_BY_NAME                                    'epay%5Cconstant'
        132        NOP                                                      
        133        FETCH_DIM_R                                      ~79     !8, 0
        134        FAST_CONCAT                                      ~80     'epay%5CLogLevel%3A%3A', ~79
        135        SEND_VAL_EX                                              ~80
        136        DO_FCALL                                      0  $81     
        137        ASSIGN                                                   !9, $81
  347   138        INIT_NS_FCALL_BY_NAME                                    'epay%5Cstr_replace'
        139        FETCH_DIM_R                                      ~83     !8, 0
        140        CONCAT                                           ~84     ~83, ''
        141        SEND_VAL_EX                                              ~84
        142        SEND_VAL_EX                                              ''
        143        SEND_VAR_EX                                              !7
        144        DO_FCALL                                      0  $85     
        145        ASSIGN                                                   !10, $85
  349   146        INIT_METHOD_CALL                                         !0, 'enqueue'
        147        INIT_ARRAY                                       ~87     !9
        148        ADD_ARRAY_ELEMENT                                ~87     !10
        149        SEND_VAL_EX                                              ~87
        150        DO_FCALL                                      0          
  351   151        PRE_INC                                                  !6
  352   152        INIT_METHOD_CALL                                         !5, 'seek'
        153        SEND_VAR_EX                                              !6
        154        DO_FCALL                                      0          
  354   155        INIT_METHOD_CALL                                         !5, 'eof'
        156        DO_FCALL                                      0  $91     
        157        BOOL_NOT                                         ~92     $91
        158      > JMPNZ                                                    ~92, ->122
  360   159    >   ASSIGN                                                   !5, null
  361   160      > RETURN                                                   null

End of function import

Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5pgKZ
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  368     0  E > > RETURN                                                   null

End of function __construct

Function __destruct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5pgKZ
function name:  __destruct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  375     0  E > > RETURN                                                   null

End of function __destruct

Function __tostring:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/5pgKZ
function name:  __toString
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  382     0  E >   VERIFY_RETURN_TYPE                                       
          1      > RETURN                                                   null

End of function __tostring

End of class epay\Logger.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
156.58 ms | 1416 KiB | 23 Q