OpenSencillo  2015.002
log Class Reference
+ Inheritance diagram for log:

Public Member Functions

 __construct ($path='', $file='log.txt', $maxLine=100, $useFile=true, $mysql=null)
 saveToLog ($data)
 getLog ()
 vd ($var)

Protected Attributes

 $name
 $file
 $path
 $current
 $store = array()
 $maxLine = 0
 $useFile

Private Member Functions

 getContent ()

Detailed Description

Log class

Definition at line 5 of file test.tool.framework.php.


Constructor & Destructor Documentation

__construct ( path = '',
file = 'log.txt',
maxLine = 100,
useFile = true,
mysql = null 
) [final]
Parameters:
string$path
string$file
number$maxLine
bool$useFile

Definition at line 21 of file test.tool.framework.php.

        {
            $this->file = $path.$file;
            $this->path = $path;
            $this->name = $file;
            $this->maxLine = $maxLine;
            $this->useFile = $useFile;
            $this->store['mysql'] = $mysql;
        }

Member Function Documentation

getContent ( ) [private]

Read log file

Definition at line 72 of file test.tool.framework.php.

        {
                if($this->useFile)
                {
                        $this->current = fopen($this->file, "r");
                    $i=0;
                    while(($buffer = fgets($this->current, 4096)) !== false)
                    {
                            $this->store[$i++] = sscanf($buffer, "%s\t%s\t%s\t%s\t%s\t%s\n");
                    }
                        fclose($this->current);
                }
                else
                {
                        return $this->output("`id`>0","`id` DESC",$this->maxLine);
                }
        }
getLog ( )

Load from log

Returns:
array

Definition at line 94 of file test.tool.framework.php.

        {
                $this->getContent();
                return $this->store;
        }
saveToLog ( data) [final]

Save to log

Parameters:
string$data

Definition at line 35 of file test.tool.framework.php.

        {
                if($this->useFile)
                {
                    $this->getContent();
                    $this->current = fopen($this->file, "w");
                    fprintf($this->current, "%s\t%s\t%s\t%s\t%s\t%s\n",date('Y-m-d'),date('H:i:s'),$data[0],$data[1],$data[2],$data[3]);
                    foreach ($this->store as $val)
                    {
                        fprintf($this->current, "%s\t%s\t%s\t%s\t%s\t%s\n",$val[0],$val[1],$val[2],$val[3],$val[4],$val[5]);
                    }
                    
                    fclose($this->current);
                    
                    if($this->maxLine<sizeof($this->store))
                    {
                        rename($_SERVER['DOCUMENT_ROOT'] . $this->file,$_SERVER['DOCUMENT_ROOT'] . $this->path ."old_" . $this->name);
                    }
                }
                else
                {
                    $name=explode('.',$this->name);
                    $this->store['mysql']->newColumn('date','VARCHAR(10)');
                    $this->store['mysql']->newColumn('time','VARCHAR(8)');
                    $this->store['mysql']->newColumn('data0','TEXT');
                    $this->store['mysql']->newColumn('data1','TEXT');
                    $this->store['mysql']->newColumn('data2','TEXT');
                    $this->store['mysql']->newColumn('data3','TEXT');
                    $this->store['mysql']->createTable($name[0].'_log');
                    $this->store['mysql']->openTable($name[0].'_log');
                    $this->store['mysql']->insert('\''.date('Y-m-d').'\',\''.date('H:i:s').'\',\''.$data[0].'\',\''.$data[1].'\',\''.$data[2].'\',\''.$data[3].'\'');
                }
        }
vd ( var)

Get formated var_dump to string

Definition at line 103 of file test.tool.framework.php.

        {
                ob_start();
            var_dump($var);
            $result = ob_get_clean();
            $result = highlight_string($result,true);
            $result = str_replace('=&gt;<br />&nbsp;&nbsp;&nbsp;','<b>=&gt;</b>',$result);
            $result = str_replace(')&nbsp;"',')&nbsp;"<font color="blue">',$result);
            $result = str_replace('"<br />','</font>"<br />',$result);
            echo $result;
            return $result;
        }

Field Documentation

$current [protected]

Definition at line 10 of file test.tool.framework.php.

$file [protected]

Definition at line 8 of file test.tool.framework.php.

$maxLine = 0 [protected]

Definition at line 12 of file test.tool.framework.php.

$name [protected]

Definition at line 7 of file test.tool.framework.php.

$path [protected]

Definition at line 9 of file test.tool.framework.php.

$store = array() [protected]

Definition at line 11 of file test.tool.framework.php.

$useFile [protected]

Definition at line 13 of file test.tool.framework.php.


The documentation for this class was generated from the following file:
 All Data Structures Files Functions Variables