update README + notice for filedriver:1.0
This commit is contained in:
parent
e376d1e89e
commit
7ee20c2d17
|
@ -48,7 +48,7 @@ xdrm-framework is based on `all in config` so you will have this structure :
|
|||
- `__CONFIG__` - The absolute `config` folder path
|
||||
|
||||
|
||||
### 3. Modules
|
||||
### 3. Packages
|
||||
|
||||
#### 3.1 API - self-managed API
|
||||
|
||||
|
@ -60,6 +60,10 @@ xdrm-framework is based on `all in config` so you will have this structure :
|
|||
|
||||
> version 1.0 - [documentation](/notice/log/1.0.md)
|
||||
|
||||
#### 3.3 Log - optimized file driver
|
||||
|
||||
> version 1.0 - [documentation](/notice/filedriver/1.0.md)
|
||||
|
||||
|
||||
#### [3.2] error - error system
|
||||
#### [3.3] database - database wrapper and repository manager
|
||||
|
|
|
@ -0,0 +1,76 @@
|
|||
```yaml
|
||||
module: filedriver
|
||||
version: 1.0
|
||||
requires: null
|
||||
```
|
||||
|
||||
Overview
|
||||
----
|
||||
|
||||
##### 1. Introduction
|
||||
The `filedriver` package allows create, read and write files easily and with optimization (cf. SplFileObject).
|
||||
|
||||
To make it easier and generic, all methods are static.
|
||||
|
||||
Setup
|
||||
----
|
||||
> 1. Include the autoloader
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
require_once '../autoloader.php';
|
||||
|
||||
...
|
||||
```
|
||||
|
||||
> 2. Load the `FileDriver` class
|
||||
|
||||
```php
|
||||
<?php
|
||||
|
||||
...
|
||||
|
||||
use \filedriver\core\FileDriver;
|
||||
|
||||
```
|
||||
|
||||
Usage
|
||||
----
|
||||
|
||||
### FileDriver
|
||||
|
||||
##### `create` - creates or empty a file
|
||||
|
||||
> ```php
|
||||
<?php
|
||||
create(String $filename) : bool
|
||||
```
|
||||
|
||||
##### `read` - reads a whole file
|
||||
|
||||
> ```php
|
||||
<?php
|
||||
read(String $filename) : String
|
||||
```
|
||||
|
||||
##### `readline` - reads a specific line
|
||||
|
||||
> ```php
|
||||
<?php
|
||||
readline(String $filename, Integer $line) : String
|
||||
```
|
||||
|
||||
##### `write` - writes content (erase if not empty)
|
||||
|
||||
> ```php
|
||||
<?php
|
||||
write(String $filename, String $content) : bool
|
||||
```
|
||||
|
||||
##### `append` - append content at the end of a file
|
||||
|
||||
> ```php
|
||||
<?php
|
||||
append(String $filename, String $content) : bool
|
||||
```
|
|
@ -76,30 +76,6 @@
|
|||
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
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue