**JsonShelter** is a lightweight JSON database library for PHP, enabling easy CRUD operations for structured data. Simple file-based storage, intuitive interface, and unique record management make data handling effortless. Perfect for prototypes and small applications.
Welcome to JsonShelter! This is a nifty PHP library designed to help you store and manage your JSON data with ease. Letโs dive into the installation and usage instructions! ๐
You can bring JsonShelter into your project using one of the methods below:
Use Composer to include the package seamlessly in your project:
composer require almhdy/json-shelter
Prefer to have a local copy? Clone the repository directly from GitHub:
git clone https://github.com/almhdy24/JsonShelter.git
You can also download a release archive from GitHub. Simply visit the releases page and grab the latest version as a ZIP file. Extract it to your project directory afterward.
Using JsonShelter in your project is easy-peasy! Include the class by using Composer or directly. Letโs walk through it!
If you used Composer, just include the autoload file and get started! Hereโs an example:
// Include Composer's autoload file
require 'vendor/autoload.php';
// Use the JsonShelter namespace
use Almhdy\JsonShelter\JsonShelter;
// Create a new JsonShelter instance
$baseDir = "myDatabase"; // Base directory path
$secretKey = "your_secret_key"; // Your secret key
$secretIv = "your_secret_iv"; // Your secret IV
$db = new JsonShelter($baseDir, $secretKey, $secretIv);
If you cloned the repo or downloaded the archive, include the JsonShelter.php
file directly. Adjust the path as needed!
// Include the JsonShelter class file
require 'path/to/JsonShelter.php'; // Set the correct path
// Use the JsonShelter namespace
use Almhdy\JsonShelter\JsonShelter;
// Create a new JsonShelter instance
$baseDir = "myDatabase"; // Base directory path
$secretKey = "your_secret_key"; // Your secret key
$secretIv = "your_secret_iv"; // Your secret IV
$db = new JsonShelter($baseDir, $secretKey, $secretIv);
You can easily enable or disable encryption for your records. This is a handy feature to keep your data secure!
$db->enableEncryption();
$db->disableEncryption();
You can perform CRUD operations (Create, Read, Update, Delete) with the following methods:
// Create a new record in 'myTable'
$db->create('myTable', ['name' => 'John', 'age' => 30]);
// Read a record from 'myTable' by ID
$record = $db->read('myTable', 1); // Replace 1 with the record ID
print_r($record); // Display the retrieved record
// Update a record in 'myTable' by ID
$db->update('myTable', 1, ['age' => 31]); // Increment age
// Delete a record from 'myTable' by ID
$db->delete('myTable', 1); // Replace 1 with the record ID
Our database manager ๐, now affectionately called โdb,โ comes packed with handy extra methods ๐ that make managing JSON files and checking their directory status a breeze! Letโs explore these features with a touch of flair. ๐ผโจ
Before diving into the JSON realm, make sure your directory is in tip-top shape! This method checks if itโs readable and writable:
$status = $db->checkDirectoryStatus();
print_r($status);
Youโll receive an associative array detailing the directoryโs read and write capabilities! This is a developerโs best friend for troubleshooting permission issues! ๐ ๏ธ
Curious about your JSON files? This method gives you the lowdown on their size and permissions:
$directoryInfo = $db->getJsonFilesInfo();
print_r($directoryInfo);
Youโll get an array where each JSON file is highlighted, showcasing its size and permissions. Itโs like a report card for your files! ๐
Letโs tighten up security! This method automatically sets the best permissions for your JSON files:
$permissionResults = $db->setBestPermissionsForJsonFiles();
print_r($permissionResults);
Youโll receive an array reflecting the results of all the nifty permission adjustments made. Verify that everythingโs shipshape and ready to go! โ๏ธ
With these vibrant methods ๐, managing your JSON files becomes not just easy, but enjoyable! Embrace the elegance of efficient code and let db do the heavy lifting, making your application shine like a star! ๐โจ
And thatโs a wrap! ๐ Youโve now unlocked the power of JsonShelter, making it super simple to integrate into your PHP applications! ๐ With just a few easy steps, youโre ready to harness the full potential of JSON management.
Remember, every line of code brings you closer to your goals. Embrace the journey and happy coding! ๐๐ปโจ