Пример #1
0
 /**
  * Function: setMasterfile
  *
  * Validates the passed filepath to the applications masterfile
  * for existance and readability.
  */
 public function setMasterfile($masterfile)
 {
     if (is_file($masterfile) && is_readable($masterfile)) {
         LogMore::info('Valid file passed');
         $this->masterfile = $masterfile;
     } else {
         LogMore::error('Invalid file passed: %s', $masterfile);
     }
 }
Пример #2
0
 /**
  * Function: open
  *
  * Calling this static method is optional, but recommended.
  * By passing an ident-string to this method, the systems
  * logging daemon is able to filter the following messages
  * easily.
  * For a detailed information please consult the official
  * PHP manual, Chapter "Function Reference", "Other Services",
  * "Network" extension.
  *
  * Parameters:
  * 	$ident - An identification string for the application 
  * 		that uses LogMore
  * 	$option - Indicator for logging options
  * 		Default: LOG_PID | LOG_PERROR
  * 	$facility - Logging facility
  * 		Default: LOG_USER
  *
  * Returns:
  *
  * 	true - on success
  * 	false - on failure
  *
  * See also:
  *
  * 	<close>
  */
 public static function open($ident, $option = null, $facility = null)
 {
     # If log has already been opened
     if (self::$ident) {
         LogMore::info('Ignoring attempt to open log for ident %s', $ident);
         $rc = false;
     } else {
         # Set defaults:
         if (!isset($option)) {
             $option = LOG_PID | LOG_PERROR;
         }
         if (!isset($facility)) {
             $facility = LOG_USER;
         }
         if (!($rc = openlog($ident, $option, $facility))) {
             trigger_error('Failed to open log', E_USER_ERROR);
         }
         # Store ident for future calls of LogMore::open():
         self::$ident = $ident;
     }
     return $rc;
 }
Пример #3
0
 /**
  * Function: parseFile
  *
  * Returns:
  *
  * 	The pretty-printed PHP code
  */
 private function parseFile($file)
 {
     LogMore::debug('Should parse file %s', $file);
     $fileDirectory = dirname($file);
     LogMore::info('File directory: %s', $fileDirectory);
     # Switch to file directory
     $masterDirectory = null;
     if ($fileDirectory && $fileDirectory != '.') {
         LogMore::debug('Switching to directory: %s', $fileDirectory);
         $masterDirectory = $this->switchDirectory($fileDirectory);
         # Strip dirname from file:
         $file = basename($file);
     }
     if (is_file($file)) {
         $statements = file_get_contents($file);
     } else {
         $statements = array();
         LogMore::debug('File could not be opened: %s (cwd: %s)', $file, getcwd());
     }
     # Create Parser
     $parser = new PHPParser_Parser(new PHPParser_Lexer());
     # Create syntax tree
     $syntax_tree = $parser->parse($statements);
     LogMore::debug('Syntax tree parsed');
     # Pretty print syntax tree/convert syntax tree back to PHP statements:
     $code = $this->prettyPrint($syntax_tree);
     # Switch back to master directory:
     if ($masterDirectory) {
         $this->switchDirectory($masterDirectory);
     }
     return $code;
 }