JsPhp
JsPhp copied to clipboard
A php library for implementing Array, Object, String methods in JavaScript way.
Why this library?
While using php Array methods it feels troublesome because of their unstructured patterns.
For example, you are using the array_map and the array_filter methods of php. At the time of using, you may notice that for the array_map method, the $callback comes as the first parameter of the method, then the $array but for the array_filter method, the $array comes first then the $callback. And this mixed structure exists everywhere.
Then I've discovered that the JavaScript uses a good pattern for these cases and I am also a big fan of JavaScript. That's why I've decided to build this library. I can say that the JavaScript lovers can get the pure feelings of JavaScript by using this and the JavaScript non-lovers also get the advantage of the good structure of array manipulations.
Future Journey
Currently I've covered only the array methods. In near future I will add the object and string methods.
Installation
composer is needed for installing the package. If you have composer installed then run the command.
composer require ahamed/jsphp
Usage
After successful installation, include the library into your project.
require_once __DIR__ . '/vendor/autoload.php';
use Ahamed\JsPhp\JsArray;
$data = [1, 2, 3, 4, 5];
$array = new JsArray($data);
$square = $array->map(
function ($item) {
return $item * $item;
}
);
print_r($square);
Documentation
For writing this documentation I've followed the MDN a lot. Thanks to MDN, this site helps me to learn a lot of JS.
Follow the wiki pages for the details documentation.
Testing
You can run PHPUnit testing and PHP_CodeSniffer.
- For running unit test
composer run-script test - For running phpcs test
composer run-script phpcs