public function readFile (string $logFile=NULL, array $keys=[], string $order="desc", string $delimeter="|")
    {
		$this->readResult 	= [];
		$this->logFile 		= $logFile;
		$this->keys 		= $keys;
		$this->delimeter 	= $delimeter;

    	// Validates Log File
        if ($this->validateAttribute("logFile") == FALSE) return $this;
    	// Validates Delimeter
        if ($this->validateAttribute("delimeter") == FALSE) return $this;
    	// Validates Keys
        if ($this->validateAttribute("keys") == FALSE) return $this;

        if (!file_exists($logFile)):
			$this->error = "Specified file: '$logFile' doesn't exist.";
			return $this;
		endif;

	    $logs 	= [];
	    $handle = fopen($logFile, "r");
	    if (!$handle):
			$this->error 		= "Error opening the file '$logFile'.";
			$this->readResult 	= [];
			return $this;
	    endif;
        while (($line = fgets($handle)) !== FALSE)
        {
        	if (!empty(trim($line))):
	            $logObject  	= (object) [];
	            $logAttributes 	= explode($delimeter, $line);
	            for ($i = 0; $i < count($keys); $i++):
	                $key 				= $keys[$i] 			?? "";
	                $logAttribute 		= $logAttributes[$i] 	?? "";
	                $logObject->$key 	= trim($logAttribute);
	            endfor;
	            $logs[] = $logObject;
	        endif;
        }
        fclose($handle);
        $order = empty($order) || !in_array(strtolower($order), ['asc', 'desc']) ? "desc" : strtolower($order);
        if (!empty($logs) && $order == "desc") krsort($logs);
		$this->readResult 		= $logs;
		$this->filteredResult 	= $logs;
		$this->result 			= $logs;
		return $this;
    }
public function readFile (string $logFile=NULL, array $keys=[], string $order="desc", string $delimeter="|")
    {
		$this->readResult 	= [];
		$this->logFile 		= $logFile;
		$this->keys 		= $keys;
		$this->delimeter 	= $delimeter;

    	// Validates Log File
        if ($this->validateAttribute("logFile") == FALSE) return $this;
    	// Validates Delimeter
        if ($this->validateAttribute("delimeter") == FALSE) return $this;
    	// Validates Keys
        if ($this->validateAttribute("keys") == FALSE) return $this;

        if (!file_exists($logFile)):
			$this->error = "Specified file: '$logFile' doesn't exist.";
			return $this;
		endif;

	    $logs 	= [];
	    $handle = fopen($logFile, "r");
	    if (!$handle):
			$this->error 		= "Error opening the file '$logFile'.";
			$this->readResult 	= [];
			return $this;
	    endif;
        while (($line = fgets($handle)) !== FALSE)
        {
        	if (!empty(trim($line))):
	            $logObject  	= (object) [];
	            $logAttributes 	= explode($delimeter, $line);
	            for ($i = 0; $i < count($keys); $i++):
	                $key 				= $keys[$i] 			?? "";
	                $logAttribute 		= $logAttributes[$i] 	?? "";
	                $logObject->$key 	= trim($logAttribute);
	            endfor;
	            $logs[] = $logObject;
	        endif;
        }
        fclose($handle);
        $order = empty($order) || !in_array(strtolower($order), ['asc', 'desc']) ? "desc" : strtolower($order);
        if (!empty($logs) && $order == "desc") krsort($logs);
		$this->readResult 		= $logs;
		$this->filteredResult 	= $logs;
		$this->result 			= $logs;
		return $this;
    }
public function readFile ( string $ logFile = NULL , array $ keys = [ ] , string $ order = "desc" , string $ delimeter = "|" ) { $ this -> readResult = [ ] ; $ this -> logFile = $ logFile ; $ this -> keys = $ keys ; $ this -> delimeter = $ delimeter ; // Validates Log File if ( $ this -> validateAttribute ( "logFile" ) == FALSE ) return $ this ; // Validates Delimeter if ( $ this -> validateAttribute ( "delimeter" ) == FALSE ) return $ this ; // Validates Keys if ( $ this -> validateAttribute ( "keys" ) == FALSE ) return $ this ; if ( ! file_exists ( $ logFile ) ) : $ this -> error = "Specified file: '$logFile' doesn't exist." ; return $ this ; endif ; $ logs = [ ] ; $ handle = fopen ( $ logFile , "r" ) ; if ( ! $ handle ) : $ this -> error = "Error opening the file '$logFile'." ; $ this -> readResult = [ ] ; return $ this ; endif ; while ( ( $ line = fgets ( $ handle ) ) !== FALSE ) { if ( ! empty ( trim ( $ line ) ) ) : $ logObject = ( object ) [ ] ; $ logAttributes = explode ( $ delimeter , $ line ) ; for ( $ i = 0 ; $ i < count ( $ keys ) ; $ i ++ ) : $ key = $ keys [ $ i ] ?? "" ; $ logAttribute = $ logAttributes [ $ i ] ?? "" ; $ logObject -> $ key = trim ( $ logAttribute ) ; endfor ; $ logs [ ] = $ logObject ; endif ; } fclose ( $ handle ) ; $ order = empty ( $ order ) || ! in_array ( strtolower ( $ order ) , [ 'asc' , 'desc' ] ) ? "desc" : strtolower ( $ order ) ; if ( ! empty ( $ logs ) && $ order == "desc" ) krsort ( $ logs ) ; $ this -> readResult = $ logs ; $ this -> filteredResult = $ logs ; $ this -> result = $ logs ; return $ this ; }
Read log file and return this
@param string $logFile
@param array $keys
@param string $order
@param string $delimeter
@return this
Read log file and return this