arefshojaei / kitdash
PHP utility library
2.0.2
2026-08-05 14:04 UTC
Requires
- php: ^8.0
Requires (Dev)
- phpunit/phpunit: ^10
README
KitDash is a lightweight and flexible PHP utility library designed to speed up development by providing reusable, well-tested helper functions and components.
Inspired by Laravel and Lodash.
โจ Features
- ๐ Support Utilities โ Array & String helpers + Binary encoder
- ๐๏ธ Data Structures โ Stack, Queue, HashTable, Tree, Graph
- ๐ File System โ File, Directory, Archive (Zip) utilities
- ๐ Network โ URL parser & HTTP Request client
- ๐ฆ JSON โ Simple encode / decode with validation
- ๐งช Well Tested โ PHPUnit coverage
- โก Zero Dependencies โ Pure PHP 8.0+
- ๐ Clean Architecture โ Interfaces + Traits
๐ฅ Installation
With Composer (Recommended)
composer require arefshojaei/kitdash
Manual Installation
git clone https://github.com/ArefShojaei/KitDash.git
cd KitDash
composer install
๐ Quick Start
Array Utilities
use Kit\Support\Arr; Arr::add(["a" => 1], "b", 2); // ['a' => 1, 'b' => 2] Arr::get(["a" => 1], "a"); // 1 Arr::take([1, 2, 3, 4, 5], 3); // [1, 2, 3] Arr::nth([10, 20, 30], 1); // 20 Arr::drop([1, 2, 3], 1); // [1, 3] or shifted Arr::compact([0, "", false, "hello"]); // ['hello'] Arr::except(["a" => 1, "b" => 2], "a"); // ['b' => 2] Arr::first([1, 2, 3]); // 1 Arr::last([1, 2, 3]); // 3 Arr::only(["a" => 1, "b" => 2], ["a"]); // ['a' => 1] Arr::fill([1, 2, 3], "x"); // ['x', 'x', 'x'] Arr::sort([3, 1, 4]); // [1, 3, 4] Arr::unique([1, 2, 2, 3]); // [1, 2, 3] Arr::concat([1, 2], [3, 4]); // merged array Arr::random([1, 2, 3, 4]); // random element Arr::chunk([1, 2, 3, 4], 2); // [[1,2],[3,4]] Arr::join(["A", "B"], " "); // "A B" Arr::difference([1, 2, 3], [3, 4]); // [1, 2]
String Utilities
use Kit\Support\Str; Str::upper("hello"); // HELLO Str::lower("HELLO"); // hello Str::title("hello world"); // Hello World Str::snake("fooBar"); // foo_bar Str::kebab("fooBar"); // foo-bar Str::camel("foo_bar"); // fooBar Str::limit("hello world", 5); // hello... Str::slug("My Awesome Post"); // My-Awesome-Post Str::contains("hello world", "world"); // true Str::startsWith("hello", "he"); // true Str::endsWith("hello", "lo"); // true Str::toBase64("hello"); // aGVsbG8= Str::e("<script>"); // <script> Str::split("a,b,c", ","); // ['a', 'b', 'c'] Str::repeat("ha", 3); // hahaha Str::reverse("hello"); // olleh
Binary Encoder
use Kit\Support\Binary; $binary = Binary::create("secret-key"); $encoded = $binary->encode("Hello"); $decoded = $binary->decode($encoded); // Hello
Data Structures
Stack (LIFO - Last In First Out)
use Kit\Structure\Stack; $stack = new Stack(); $stack->push("first"); $stack->push("second"); $stack->pop(); // 'second' $stack->isEmpty(); // false $stack->toArray(); // ['first']
Queue (FIFO)
use Kit\Structure\Queue; $queue = new Queue(); $queue->enqueue("first"); $queue->enqueue("second"); $queue->dequeue(); // 'first' $queue->toArray(); // ['second']
HashTable
use Kit\Structure\HashTable; $table = new HashTable(); $table->set("user_1", "John"); $table->get("user_1"); // John $table->has("user_1"); // true
Tree
use Kit\Structure\Tree\Tree; $tree = new Tree("Root"); $tree->add("Child 1"); $tree->add("Child 2"); $tree->toArray();
Graph
use Kit\Structure\Graph\Graph; $graph = new Graph(); $node1 = $graph->addNode("A"); $node2 = $graph->addNode("B"); $graph->addEdge($node1, $node2); $graph->getNode("A");
File System
use Kit\Fs\File; use Kit\Fs\Directory; use Kit\Fs\Archive; // File File::save("file.txt", "content"); File::get("file.txt"); File::has("file.txt"); File::append("file.txt", " more"); File::delete("file.txt"); File::copy("a.txt", "b.txt"); File::size("file.txt"); File::extension("file.txt"); // txt File::hash("file.txt"); // sha256 // Directory Directory::create("path/to/dir"); Directory::files("path"); Directory::directories("path"); Directory::clean("path"); Directory::delete("path"); Directory::size("path"); Directory::isEmpty("path"); // Archive (Zip) $archive = new Archive("backup.zip"); $archive->addFile("file.txt"); $archive->addFromString("readme.md", "# Hello"); $archive->addDirectory("src"); $archive->comment("Backup"); $archive->extract("output"); $archive->close();
Network
use Kit\Net\Url; use Kit\Net\Request; // URL Parser $url = Url::create("https://example.com/path?name=Aref"); $url->host(); // example.com $url->protocol(); // https $url->path(); // /path?name=Aref $url->query(); // ['name' => 'Aref'] $url->origin(); // https://example.com // HTTP Request $posts = Request::get("https://jsonplaceholder.typicode.com/posts"); $post = Request::post("https://jsonplaceholder.typicode.com/posts", [ "title" => "New Post", "body" => "Content", ]);
JSON
use Kit\Json\Json; $json = Json::encode(["name" => "Aref", "age" => 25]); $data = Json::decode($json); // object $data = Json::decode($json, true); // array
Project Structure
src/
โโโ Support/ # Array, String, Binary helpers
โ โโโ Arr.php
โ โโโ Str.php
โ โโโ Binary.php
โ โโโ Interfaces/
โ โโโ Traits/
โ โโโ Array/
โ โโโ String/
โ
โโโ Structure/ # Data Structures
โ โโโ Stack.php
โ โโโ Queue.php
โ โโโ HashTable.php
โ โโโ Tree/
โ โโโ Graph/
โ โโโ Interfaces/
โ
โโโ Fs/ # File System
โ โโโ File.php
โ โโโ Directory.php
โ โโโ Archive.php
โ โโโ Interfaces/
โ
โโโ Net/ # Network utilities
โ โโโ Url.php
โ โโโ Request.php
โ โโโ Http.php
โ โโโ Constants/
โ โโโ Exceptions/
โ โโโ Interfaces/
โ
โโโ Json/ # JSON helpers
โโโ Json.php
โโโ Exceptions/
โโโ Interfaces/
๐ก Practical Examples
Input Data Cleaning
use Kit\Support\{Arr, Str}; $input = [ "name" => " John Doe ", "email" => "JOHN@EXAMPLE.COM", "description" => "", "website" => null, ]; // Clean input $input["name"] = Str::trim($input["name"]); $input["email"] = Str::lower($input["email"]); // Remove empty values $clean = Arr::compact($input); // Result: ['name' => 'John Doe', 'email' => 'john@example.com']
Working with URLs and Slugs
use Kit\Support\Str; $title = "How to Build a PHP Application"; // Create URL-friendly slug $slug = Str::slug($title); // 'how-to-build-a-php-application' // Create filename $filename = $slug . ".md"; // 'how-to-build-a-php-application.md' // Check URL patterns $isValid = Str::startsWith("https://example.com/api", "https://");
Working with Configuration
use Kit\Support\Arr; $config = [ "app" => ["name" => "MyApp", "version" => "1.0"], "db" => ["host" => "localhost", "port" => 3306], "cache" => ["driver" => "redis"], ]; // Get specific values $appName = Arr::get($config, "app"); // Using array keys $dbHost = Arr::get($config, "db"); // Add new config $newConfig = Arr::add($config, "queue", ["driver" => "redis"]); // Get only app config $appConfig = Arr::only($config["app"], ["name", "version"]);
File Operations
use Kit\Fs\File; // Save configuration $config = ["app" => "MyApp", "debug" => true]; File::save("config.json", json_encode($config)); // Read configuration if (File::has("config.json")) { $content = File::get("config.json"); $config = json_decode($content, true); } // Create backup $original = File::get("data.txt"); File::save("data.backup.txt", $original);
Using Data Structures
use Kit\Structure\{Stack, HashTable}; // Undo/Redo functionality with Stack $stack = new Stack(); $stack->push("action1"); $stack->push("action2"); $stack->push("action3"); $lastAction = $stack->pop(); // 'action3' // Cache with HashTable $cache = new HashTable(); $cache->set("user:1", ["name" => "John", "email" => "john@example.com"]); $cache->set("user:2", ["name" => "Jane", "email" => "jane@example.com"]); $user = $cache->get("user:1"); $hasUser = $cache->has("user:1"); // true
๐งช Testing
Install Development Dependencies
composer install
Run All Tests
vendor/bin/phpunit
Run Specific Test
vendor/bin/phpunit --filter "testArrayAdd"
Run Tests in Specific File
vendor/bin/phpunit tests/Unit/Support/ArrTest.php
Generate Code Coverage Report
vendor/bin/phpunit --coverage-html coverage
Run Tests with Verbose Output
vendor/bin/phpunit -v
๐ค Contributing
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a new branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Contributing Guidelines
- All new functions must be tested
- Follow PSR-12 coding standards
- Commit messages should be clear and descriptive
- Update documentation if API changes
- Add examples for new utilities
๐ Performance
KitDash is designed for performance:
- Zero external dependencies - Fast installation and updates
- Static methods - No object instantiation overhead
- Optimized algorithms - Efficient implementations
- Minimal memory footprint - Small library size
Benchmark Results
Array Operations: ~0.001ms per operation
String Operations: ~0.0001ms per operation
File Operations: I/O limited
๐ Security
- No external dependencies - No supply chain vulnerabilities
- Regular security audits - Code reviewed for vulnerabilities
- Input validation - Safe string handling
- Best practices - Follow OWASP guidelines
๐จโ๐ป Author
Aref Shojaei
- ๐ง Email: arefshojaei82@gmail.com
- ๐ GitHub: @ArefShojaei
- ๐ฆ Packagist: arefshojaei/kitdash
๐ Acknowledgments
- Inspired by Laravel Helpers
- Inspired by Lodash
- Thanks to all contributors
๐ Support & Community
Need Help?
- ๐ Documentation - See examples above
- ๐ Found a bug? - Open an Issue
- ๐ฌ Have a question? - Start a Discussion
- ๐ง Email - arefshojaei82@gmail.com
๐ Show Your Support
If this project helped you, please give it a โญ Star on GitHub!
It helps us reach more developers and keep improving the library.