1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 117: 118: 119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130: 131: 132: 133: 134: 135: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204: 205: 206: 207:
<?php
/**
* Created by PhpStorm.
* User: samtax
* Date: 08/07/2018
* Time: 7:47 AM
*/
/************************************************
* File Session
************************************************/
require_once(PATH_LIBRARY . 'filesession/FileSession1.php');
$__FILE_SESSION = new FileSession1('default', resources_path_cache().'/file_session/', Config1::DEBUG_MODE);
/**
* @return FileSession1
* @param null $fileName
* @see https://github.com/bendahrooge/PHP-Simple-Database
*
A simple flat-file key/value storage class for PHP. Great for small databases or servers where SQL can't be used. Only 150 lines of code :)
This is not a replacement for SQL or other databases, and it should only be used in smaller applications where a conventional database isn't possbile. It is very inefficient and slow for PHP to keep pulling and overwriting an entire JSON file.
* //Writes Data into file
*
* $fruit->set('fruits', array('apples', 'bananas', 'clementines'));
* //returns TRUE or Error
*
* //Tells if a key is stored in the file
* $fruit->search('fruits');
* //returns TRUE
*
* $fruit->search('prices');
* //returns FALSE
*
* //Returns the value of a key
* $fruit->get('fruits');
* //returns that.object
*
* //Deletes a value in file
* $fruit->del('fruits');
* //returns TRUE
*
*
*/
function file_session($fileName = null){
if($fileName) return new FileSession1($fileName, resources_path_cache().'/file_session/', Config1::DEBUG_MODE);
global $__FILE_SESSION;
return $__FILE_SESSION;
}
/**
* @param $name
* @param $value
* @param bool $forceReplace
* @return bool
*/
function file_session_save($name, $value, $forceReplace = false){
if($forceReplace && file_session()->has($name)) file_session($name)->del($name);
return file_session()->set($name, $value);
}
/**
* @param $name
* @param null $defaultValue
* @return mixed
*/
function file_session_get($name, $defaultValue = null){ return file_session()->get($name, $defaultValue); }
/**
* @param $name
* @return mixed
*/
function file_session_remove($name){ return file_session()->del($name); }
/************************************************
* File Base
************************************************/
FileManager1::loadComposerPackage(PATH_LIBRARY."filebase");
use Filebase\FileBase1;
$__FILE_BASE = new FileBase1([
'dir' => resources_path_cache().'/file_session/',
// 'dir' => 'path/to/__FILE_BASE/dir',
// 'backupLocation' => 'path/to/__FILE_BASE/backup/dir',
// 'format' => \Filebase\Format\Json::class,
// 'cache' => true,
// 'cache_expires' => 1800,
// 'pretty' => true,
// 'safe_filename' => true,
// 'read_only' => false,
// 'validate' => [
// 'name' => [
// 'valid.type' => 'string',
// 'valid.required' => true
// ]
// ]
]);
/**
* @return \Filebase\Document
* @param string $tableName
* @see https://github.com/filebase/Filebase
*
A Simple but Powerful Flat File Database Storage. No need for MySQL or an expensive SQL server, in fact, you just need your current site or application setup. All database entries are stored in files (formatted the way you like).
You can even modify the raw data within the files themselves without ever needing to use the API. And even better you can put all your files in version control and pass them to your team without having out-of-sync SQL databases.
Doesn't that sound awesome?
With Filebase, you are in complete control. Design your data structure the way you want. Use arrays and objects like you know how in PHP. Update and share your data with others and teams using version control. Just remember, upgrading your web/apache server is a lot less than your database server.
Works with PHP 5.6 and PHP 7+
Features
Filebase is simple by design, but has enough features for the more advanced.
Key/Value and Array-based Data Storing
Querying data
Custom filters
Caching (queries)
Database Backups
Formatting (encode/decode)
Validation (on save)
CRUD (method APIs)
File locking (on save)
Intuitive Method Naming
// setting the access and configration to your database
$database = new \Filebase\Database([
'dir' => 'path/to/database/dir'
]);
// in this example, you would search an exact user name
// it would technically be stored as user_name.json in the directories
// if user_name.json doesn't exists get will return new empty Document
$item = $database->get('kingslayer');
// display property values
echo $item->first_name;
echo $item->last_name;
echo $item->email;
// change existing or add new properties
$item->email = 'example@example.com';
$item->tags = ['php','developer','html5'];
// need to save? thats easy!
$item->save();
// check if a record exists and do something if it does or does not
if ($database->has('kingslayer'))
{
// do some action
}
// Need to find all the users that have a tag for "php" ?
$users = $db->query()->where('tags','IN','php')->results();
// Need to search for all the users who use @yahoo.com email addresses?
$users = $db->query()->where('email','LIKE','@yahoo.com')->results();
*
*
*/
function file_base($tableName){
global $__FILE_BASE;
return $__FILE_BASE->get($tableName);
}