JsonShelter

**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.

1
0
PHP

๐Ÿ—„๏ธ JsonShelter - Your Friendly PHP JSON Manager

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! ๐Ÿš€

Installation โš™๏ธ

You can bring JsonShelter into your project using one of the methods below:

Method 1: Install via Composer ๐ŸŽต

Use Composer to include the package seamlessly in your project:

composer require almhdy/json-shelter

Method 2: Clone the Repository ๐Ÿฅณ

Prefer to have a local copy? Clone the repository directly from GitHub:

git clone https://github.com/almhdy24/JsonShelter.git

Method 3: Download as Archive ๐Ÿ“ฆ

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.

Usage ๐Ÿ“–

Using JsonShelter in your project is easy-peasy! Include the class by using Composer or directly. Letโ€™s walk through it!

Option 1: Using Composer ๐Ÿฅ‡

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);

Option 2: Directly Including the File ๐ŸŒŸ

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);

Encryption ๐Ÿ›ก๏ธ

You can easily enable or disable encryption for your records. This is a handy feature to keep your data secure!

  • Enable Encryption:
$db->enableEncryption();
  • Disable Encryption:
$db->disableEncryption();

Record Operations ๐Ÿ“‹

You can perform CRUD operations (Create, Read, Update, Delete) with the following methods:

  • Create a record: โœ๏ธ
// Create a new record in 'myTable'
$db->create('myTable', ['name' => 'John', 'age' => 30]);
  • Read a record: ๐Ÿ”
// 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: ๐Ÿ”„
// Update a record in 'myTable' by ID
$db->update('myTable', 1, ['age' => 31]); // Increment age
  • Delete a record: โŒ
// Delete a record from 'myTable' by ID
$db->delete('myTable', 1); // Replace 1 with the record ID

๐ŸŒŸ Additional Methods Overview

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. ๐Ÿ’ผโœจ

1. ๐Ÿ“‚ Check Directory Status

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);

Purpose ๐Ÿ•ต๏ธโ€โ™‚๏ธ

  • Readability: Ensures you can easily read files from the directory. ๐Ÿ“–
  • Writability: Confirms that you can create or modify files without a hitch! โœ๏ธ

Expected Output ๐ŸŽ‰

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! ๐Ÿ› ๏ธ


2. ๐Ÿ—„๏ธ Get Size and Permissions of JSON Files

Curious about your JSON files? This method gives you the lowdown on their size and permissions:

$directoryInfo = $db->getJsonFilesInfo();
print_r($directoryInfo);

Purpose ๐Ÿ“Š

  • File Size: See how much space your JSON files are taking up! ๐Ÿš€
  • File Permissions: Check the permissions for each fileโ€”crucial for security! ๐Ÿ”’

Expected Output ๐Ÿฅณ

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! ๐Ÿ“


3. ๐Ÿ›ก๏ธ Set Best Permissions for JSON Files

Letโ€™s tighten up security! This method automatically sets the best permissions for your JSON files:

$permissionResults = $db->setBestPermissionsForJsonFiles();
print_r($permissionResults);

Purpose ๐Ÿ”

  • Security Boost: Ensures your JSON files have just the right permissions, keeping unwanted eyes away! ๐Ÿ‘€
  • Standardization: Applies uniform permission settings across all filesโ€”cohesion is key! ๐Ÿ”—

Expected Output ๐ŸŽŠ

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! ๐ŸŒŸโœจ

Conclusion ๐ŸŽ‰

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! ๐Ÿ˜„๐Ÿ’ปโœจ