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; /** * FIXME: * -- PROBLEM: Server and NetBeans don't understand SplEnum type yet; * so it can't be used for now. * -- DUE: 17 Apr. 2014 * -- MOD: 16 Apr. 2014 14:07 THR */ /*** * Enumeration for logging levels of importancy. * * @author Talaeezadeh */ class LogLevel// extends \SplEnum { //const __default = self::NONE; /** * Disable logging * * @var Constatnt(Int) No loggong */ const NONE = 0; /** * Fatal Errors * * @var Constant(Int) Fatal Errors */ const FATAL = 1; /** * Errors that are not fatal * * @var Constant(Int) Normal Errors */ const ERROR = 2; /** * Warnings * * @var Constant(Int) Warnings */ const WARNING = 3; /** * Notifications * * @var Constant(Int) Notifications */ const NOTICE = 4; /** * Informations * * @var Constant(Int) Informations */ const INFO = 5; /** * Everything that are not categorized in previous levels * * @var Constant(Int) Every (other) thing */ const EVERYTHING = 6; } namespace epay; use SplFileObject; use SplQueue; /** * 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__ . __FUNCTION__ . " says: \'Unexpected argument. Escaped!\'"); echo $err[1]; return $err; } elseif ($num_args == 0) { $err = array (LogLevel::WARNING, "WARNING @" . __FILE__ . " line ". __LINE__ .": " . __TRAIT__ . __FUNCTION__ . " 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__ . __FUNCTION__ . " 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__ . __FUNCTION__ . " 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(); $MESSAGES = new SplQueue; $newLogger->Import($MESSAGES);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GLk7p
function name:  (null)
number of ops:  11
compiled vars:  !0 = $newLogger, !1 = $MESSAGES
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   94     0  E >   DECLARE_CLASS                                            'epay%5Clogger'
  454     1        NEW                                              $2      'epay%5CLogger'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $2
  455     4        NEW                                              $5      'SplQueue'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $5
  456     7        INIT_METHOD_CALL                                         !0, 'Import'
          8        SEND_VAR_EX                                              !1
          9        DO_FCALL                                      0          
         10      > RETURN                                                   1

Class epay\LogLevel: [no user functions]
Class epay\Logger:
Function writelog:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/GLk7p
function name:  WriteLog
number of ops:  2
compiled vars:  !0 = $MESSAGES
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  160     0  E >   RECV                                             !0      
  163     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/GLk7p
function name:  Purge
number of ops:  2
compiled vars:  !0 = $MESSAGES
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  177     0  E >   RECV                                             !0      
  180     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/GLk7p
function name:  Export
number of ops:  2
compiled vars:  !0 = $MESSAGES
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  193     0  E >   RECV                                             !0      
  196     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 = 13
Branch analysis from position: 8
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 19
Branch analysis from position: 15
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 25
Branch analysis from position: 21
2 jumps found. (Code = 43) Position 1 = 27, Position 2 = 31
Branch analysis from position: 27
2 jumps found. (Code = 43) Position 1 = 41, Position 2 = 45
Branch analysis from position: 41
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 45
2 jumps found. (Code = 43) Position 1 = 54, Position 2 = 64
Branch analysis from position: 54
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 64
2 jumps found. (Code = 43) Position 1 = 66, Position 2 = 108
Branch analysis from position: 66
1 jumps found. (Code = 42) Position 1 = 105
Branch analysis from position: 105
2 jumps found. (Code = 44) Position 1 = 107, Position 2 = 68
Branch analysis from position: 107
1 jumps found. (Code = 42) Position 1 = 149
Branch analysis from position: 149
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 68
2 jumps found. (Code = 43) Position 1 = 74, Position 2 = 75
Branch analysis from position: 74
1 jumps found. (Code = 42) Position 1 = 107
Branch analysis from position: 107
Branch analysis from position: 75
2 jumps found. (Code = 44) Position 1 = 107, Position 2 = 68
Branch analysis from position: 107
Branch analysis from position: 68
Branch analysis from position: 108
2 jumps found. (Code = 44) Position 1 = 149, Position 2 = 112
Branch analysis from position: 149
Branch analysis from position: 112
Branch analysis from position: 31
Branch analysis from position: 25
filename:       /in/GLk7p
function name:  Import
number of ops:  151
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
-------------------------------------------------------------------------------------
  219     0  E >   RECV                                             !0      
  224     1        ASSIGN                                                   !1, null
  229     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
  234     6        IS_SMALLER                                               3, !2
          7      > JMPZ                                                     ~15, ->13
  236     8    >   ASSIGN                                                   !1, <array>
  239     9        FETCH_DIM_R                                      ~17     !1, 1
         10        ECHO                                                     ~17
  240    11      > RETURN                                                   !1
         12*       JMP                                                      ->19
  242    13    >   IS_EQUAL                                                 !2, 0
         14      > JMPZ                                                     ~18, ->19
  244    15    >   ASSIGN                                                   !1, <array>
  247    16        FETCH_DIM_R                                      ~20     !1, 1
         17        ECHO                                                     ~20
  248    18      > RETURN                                                   !1
  254    19    >   IS_SMALLER                                               1, !2
         20      > JMPZ                                                     ~21, ->25
  256    21    >   INIT_NS_FCALL_BY_NAME                                    'epay%5Cfunc_get_arg'
         22        SEND_VAL_EX                                              1
         23        DO_FCALL                                      0  $22     
         24        ASSIGN                                                   !3, $22
  258    25    >   IS_SMALLER                                               2, !2
         26      > JMPZ                                                     ~24, ->31
  260    27    >   INIT_NS_FCALL_BY_NAME                                    'epay%5Cfunc_get_arg'
         28        SEND_VAL_EX                                              2
         29        DO_FCALL                                      0  $25     
         30        ASSIGN                                                   !4, $25
  270    31    >   NEW                                              $27     'SplFileObject'
         32        FETCH_OBJ_R                                      ~28     'PATH'
         33        FETCH_OBJ_R                                      ~29     'FILENAME'
         34        CONCAT                                           ~30     ~28, ~29
         35        SEND_VAL_EX                                              ~30
         36        SEND_VAL_EX                                              'r'
         37        DO_FCALL                                      0          
         38        ASSIGN                                                   !5, $27
  275    39        TYPE_CHECK                                    2          !5
         40      > JMPZ                                                     ~33, ->45
  277    41    >   ASSIGN                                                   !1, <array>
  280    42        FETCH_DIM_R                                      ~35     !1, 1
         43        ECHO                                                     ~35
  281    44      > RETURN                                                   !1
  287    45    >   INIT_METHOD_CALL                                         'Purge'
         46        SEND_VAR_EX                                              !0
         47        DO_FCALL                                      0          
  304    48        INIT_METHOD_CALL                                         !5, 'seek'
         49        SEND_VAR_EX                                              !3
         50        DO_FCALL                                      0          
  305    51        INIT_METHOD_CALL                                         !5, 'eof'
         52        DO_FCALL                                      0  $38     
         53      > JMPZ                                                     $38, ->64
  307    54    >   INIT_ARRAY                                       ~39     3
  309    55        ROPE_INIT                                     3  ~41     '+says%3A+%5C%27The+line+'
         56        ROPE_ADD                                      1  ~41     ~41, !3
         57        ROPE_END                                      2  ~40     ~41, '+does+not+exist+in+current+content%21%5C%27'
         58        CONCAT                                           ~43     'WARNING+%40%2Fin%2FGLk7p+line+308%3A+Import', ~40
         59        ADD_ARRAY_ELEMENT                                ~39     ~43
  307    60        ASSIGN                                                   !1, ~39
  310    61        FETCH_DIM_R                                      ~45     !1, 1
         62        ECHO                                                     ~45
  311    63      > RETURN                                                   !1
  317    64    >   ISSET_ISEMPTY_CV                                         !4
         65      > JMPZ                                                     ~46, ->108
  319    66    >   ASSIGN                                                   !6, !3
         67      > JMP                                                      ->105
  321    68    >   INIT_METHOD_CALL                                         !5, 'seek'
         69        SEND_VAR_EX                                              !6
         70        DO_FCALL                                      0          
  326    71        INIT_METHOD_CALL                                         !5, 'eof'
         72        DO_FCALL                                      0  $49     
         73      > JMPZ                                                     $49, ->75
  328    74    > > JMP                                                      ->107
  334    75    >   INIT_METHOD_CALL                                         !5, 'current'
         76        DO_FCALL                                      0  $50     
         77        ASSIGN                                                   !7, $50
  353    78        ASSIGN                                                   !8, <array>
  358    79        INIT_NS_FCALL_BY_NAME                                    'epay%5Cpreg_match'
         80        SEND_VAL_EX                                              '%2F%5BA-Z%5D%2B%2F'
         81        SEND_VAR_EX                                              !7
         82        SEND_VAR_EX                                              !8
         83        DO_FCALL                                      0          
  363    84        INIT_NS_FCALL_BY_NAME                                    'epay%5Cconstant'
         85        NOP                                                      
         86        FETCH_DIM_R                                      ~54     !8, 0
         87        FAST_CONCAT                                      ~55     'epay%5CLogLevel%3A%3A', ~54
         88        SEND_VAL_EX                                              ~55
         89        DO_FCALL                                      0  $56     
         90        ASSIGN                                                   !9, $56
  368    91        INIT_NS_FCALL_BY_NAME                                    'epay%5Cstr_replace'
         92        FETCH_DIM_R                                      ~58     !8, 0
         93        CONCAT                                           ~59     ~58, ''
         94        SEND_VAL_EX                                              ~59
         95        SEND_VAL_EX                                              ''
         96        SEND_VAR_EX                                              !7
         97        DO_FCALL                                      0  $60     
         98        ASSIGN                                                   !10, $60
  370    99        INIT_METHOD_CALL                                         !0, 'enqueue'
        100        INIT_ARRAY                                       ~62     !9
        101        ADD_ARRAY_ELEMENT                                ~62     !10
        102        SEND_VAL_EX                                              ~62
        103        DO_FCALL                                      0          
  319   104        PRE_INC                                                  !6
        105    >   IS_SMALLER                                               !6, !4
        106      > JMPNZ                                                    ~65, ->68
        107    > > JMP                                                      ->149
  379   108    >   ASSIGN                                                   !6, !3
  380   109        INIT_METHOD_CALL                                         !5, 'seek'
        110        SEND_VAR_EX                                              !6
        111        DO_FCALL                                      0          
  383   112    >   INIT_METHOD_CALL                                         !5, 'current'
        113        DO_FCALL                                      0  $68     
        114        ASSIGN                                                   !7, $68
  401   115        ASSIGN                                                   !8, <array>
  406   116        INIT_NS_FCALL_BY_NAME                                    'epay%5Cpreg_match'
        117        SEND_VAL_EX                                              '%2F%5BA-Z%5D%2B%2F'
        118        SEND_VAR_EX                                              !7
        119        SEND_VAR_EX                                              !8
        120        DO_FCALL                                      0          
  411   121        INIT_NS_FCALL_BY_NAME                                    'epay%5Cconstant'
        122        NOP                                                      
        123        FETCH_DIM_R                                      ~72     !8, 0
        124        FAST_CONCAT                                      ~73     'epay%5CLogLevel%3A%3A', ~72
        125        SEND_VAL_EX                                              ~73
        126        DO_FCALL                                      0  $74     
        127        ASSIGN                                                   !9, $74
  416   128        INIT_NS_FCALL_BY_NAME                                    'epay%5Cstr_replace'
        129        FETCH_DIM_R                                      ~76     !8, 0
        130        CONCAT                                           ~77     ~76, ''
        131        SEND_VAL_EX                                              ~77
        132        SEND_VAL_EX                                              ''
        133        SEND_VAR_EX                                              !7
        134        DO_FCALL                                      0  $78     
        135        ASSIGN                                                   !10, $78
  418   136        INIT_METHOD_CALL                                         !0, 'enqueue'
        137        INIT_ARRAY                                       ~80     !9
        138        ADD_ARRAY_ELEMENT                                ~80     !10
        139        SEND_VAL_EX                                              ~80
        140        DO_FCALL                                      0          
  420   141        PRE_INC                                                  !6
  421   142        INIT_METHOD_CALL                                         !5, 'seek'
        143        SEND_VAR_EX                                              !6
        144        DO_FCALL                                      0          
  423   145        INIT_METHOD_CALL                                         !5, 'eof'
        146        DO_FCALL                                      0  $84     
        147        BOOL_NOT                                         ~85     $84
        148      > JMPNZ                                                    ~85, ->112
  429   149    >   ASSIGN                                                   !5, null
  430   150      > 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/GLk7p
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  437     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/GLk7p
function name:  __destruct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  444     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/GLk7p
function name:  __toString
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
  451     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:
159.53 ms | 1404 KiB | 23 Q