added filedriver:1.0 + initialized log:1.0

This commit is contained in:
xdrm-brackets 2016-12-11 22:31:06 +01:00
parent 6497d18168
commit 5676d618ae
4 changed files with 246 additions and 75 deletions

View File

@ -1,74 +1,80 @@
{
"available": {
"session": {
"1.0": []
},
"error": {
"1.0": [],
"2.0": []
},
"http": {
"1.0": []
},
"api": {
"1.0": {
"error": [
"1.0"
]
},
"2.0": {
"error": [
"2.0"
]
},
"2.2": {
"error": [
"2.0"
],
"http": [
"1.0"
]
}
},
"orm": {
"0.8.1": {
"database": [
"1.0"
]
},
"0.8.2": {
"database": [
"2.0"
]
}
},
"database": {
"1.0": {
"error": [
"1.0"
]
},
"2.0": {
"error": [
"2.0"
]
}
},
"lightdb": {
"1.0": []
},
"router": {
"1.0": [],
"2.0": []
}
},
"installed": {
"api": "2.2",
"error": "2.0",
"http": "1.0",
"orm": "0.8.2",
"database": "2.0",
"router": "2.0",
"session": "1.0"
}
}
"available": {
"session": {
"1.0": []
},
"filedriver": {
"1.0": []
},
"log": {
"1.0": []
},
"error": {
"1.0": [],
"2.0": []
},
"http": {
"1.0": []
},
"api": {
"1.0": {
"error": [
"1.0"
]
},
"2.0": {
"error": [
"2.0"
]
},
"2.2": {
"error": [
"2.0"
],
"http": [
"1.0"
]
}
},
"orm": {
"0.8.1": {
"database": [
"1.0"
]
},
"0.8.2": {
"database": [
"2.0"
]
}
},
"database": {
"1.0": {
"error": [
"1.0"
]
},
"2.0": {
"error": [
"2.0"
]
}
},
"lightdb": {
"1.0": []
},
"router": {
"1.0": [],
"2.0": []
}
},
"installed": {
"api": "2.2",
"error": "2.0",
"http": "1.0",
"orm": "0.8.2",
"database": "2.0",
"router": "2.0",
"session": "1.0"
}
}

View File

@ -0,0 +1,159 @@
<?php
namespace filedriver\core;
class FileDriver{
/* CREATES A FILE WITH ITS NEEDED DIRECTORIES
*
* @path<String> Path of the needed file
*
* @return created<Boolean> If the file has been created successfully
*
*/
public static function create($file){
/* (0) Checks arguments */
if( !is_string($file) || is_dir($file) )
return false;
/* (1) Creates file */
try{
fclose( fopen($file, 'w') );
return true;
}catch(\Exception $e){ return false; }
}
/* READS FILE'S CONTENT
*
* @file<String> File to read
*
*/
public static function read($file){
/* (0) Checks arguments */
if( !is_string($file) )
throw new \Exception('Wrong argument for read(<String>).');
/* (1) Initializing driver on file (read-flag) */
$driver = new \SplFileObject($file, 'r');
/* (2) Read lines */
$read = '';
$line = 0;
while( $driver->current() ){
$read .= $driver->current();
$driver->next();
}
/* (3) Returns result */
return $read;
}
/* READS A FILE'S SPECIFIC LINE
*
* @file<String> File to read
* @line<int> Line to read
*
*/
public static function readline($file, $line){
/* (0) Checks arguments */
if( !is_string($file) || intval($line) !== $line )
throw new \Exception('Wrong argument for readline(<String>, <int>).');
/* (1) Initializing driver on file (read-flag) */
$driver = new \SplFileObject($file, 'r');
/* (2) Goto specific line */
$driver->seek($line);
/* (3) Return line's content */
if( $driver->key() == $line )
return $driver->current();
else
return null;
}
/* WRITES A FILE'S SPECIFIC LINE
*
* @file<String> File to read
* @line<int> Line to read
*
*/
public static function writeline($file, $line){
/* (0) Checks arguments */
if( !is_string($file) || intval($line) !== $line )
throw new \Exception('Wrong argument for writeline(<String>, <int>).');
/* (1) Initializing driver on file (read-flag) */
$driver = new \SplFileObject($file, 'r');
/* (2) Goto specific line */
$driver->seek($line);
/* (3) Return line's content */
if( $driver->key() == $line )
return $driver->current();
else
return null;
}
/* WRITES CONTENT TO A FILE
*
* @file<String> File to write to
* @content<String> Content to write
*
* @return written<Boolean> Returns if the content have been written successfully
*
* @note: Creates file if it is possible with `fopen()`
*
*/
public static function write($file, $content){
/* (0) Checks arguments */
if( !is_string($file) || !is_string($content) )
return false;
/* (1) Erase file */
try{
fclose( fopen($file, 'w') );
}catch(\Exception $e){ return false; }
/* (2) Get driver (write-flag) */
$driver = new \SplFileObject($file, 'r+');
/* (3) Writes content */
return !is_null( $driver->fwrite($content) );
}
/* APPENDS CONTENT TO A FILE
*
* @file<String> File to append content to
* @content<String> Content to append
*
* @return append<Boolean> Returns if the content have been append successfully
*
* @note: If file doesn't exists, returns false
*
*/
public static function append($file, $content){
/* (0) Checks arguments */
if( !is_file($file) || !is_string($content) )
return false;
/* (1) Get driver (append-flag) */
$driver = new \SplFileObject($file, 'a');
/* (2) append content */
return !is_null( $driver->fwrite($content.PHP_EOL) );
}
}
?>

8
src/packages/log/1.0/core/Log.php vendored Normal file
View File

@ -0,0 +1,8 @@
<?php
namespace log\core;
class Log{
}

2
xfw
View File

@ -1,2 +0,0 @@
#!/bin/sh
php exporter/main.php $*