javascriptobfuscator / jso-protector
PHP client for the JavaScript Obfuscator HTTP API. Companion to the jso-protector npm CLI.
Package info
github.com/javascriptobfuscator-com/jso-protector-php
pkg:composer/javascriptobfuscator/jso-protector
Requires
- php: >=7.4
Requires (Dev)
- phpunit/phpunit: ^9.6 || ^10.5
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is auto-updated.
Last update: 2026-09-15 18:46:04 UTC
README
PHP Composer package for the JavaScript Obfuscator HTTP API. Mirrors the protect() surface of the Node / Python / Go / .NET / Ruby clients so behavior stays in lockstep across runtimes.
PHP ≥7.4. Uses ext-curl when available; otherwise falls back to a stream-context wrapper. Zero third-party runtime dependency.
Install
composer require javascriptobfuscator/jso-protector
Quick start
require __DIR__ . '/vendor/autoload.php'; $client = new \JsoProtector\Client(); $result = $client->protect([ 'files' => ['app.js' => file_get_contents('dist/app.js')], 'preset' => 'balanced', 'label' => getenv('GIT_COMMIT') ?: null, // apiKey/apiPassword default to JSO_API_KEY / JSO_API_PASSWORD env vars. ]); foreach ($result->files as $name => $code) { file_put_contents("dist-protected/$name", $code); } echo "BuildId: {$result->buildId}\n"; echo "Fingerprint: {$result->polymorphismFingerprint}\n";
Laravel artisan command example
// app/Console/Commands/ProtectJs.php namespace App\Console\Commands; use Illuminate\Console\Command; use JsoProtector\Client; use JsoProtector\Exception as JsoException; class ProtectJs extends Command { protected $signature = 'js:protect {input} {output} {--preset=balanced}'; public function handle(): int { try { $result = (new Client())->protect([ 'files' => ['app.js' => file_get_contents($this->argument('input'))], 'preset' => $this->option('preset'), 'label' => trim((string)exec('git rev-parse HEAD')), ]); file_put_contents($this->argument('output'), $result->files['app.js']); $this->info("Protected. BuildId={$result->buildId} fp={$result->polymorphismFingerprint}"); return self::SUCCESS; } catch (JsoException $e) { $this->error("JSO failed: {$e->getMessage()} (type={$e->type})"); return self::FAILURE; } } }
Credentials
Reads JSO_API_KEY / JSO_API_PASSWORD (or the long-form JAVASCRIPT_OBFUSCATOR_API_KEY / JAVASCRIPT_OBFUSCATOR_API_PASSWORD) from the environment before falling back to the apiKey / apiPassword keys. Use env vars on shared machines.
Presets
Same shape as every other JSO language client. See Client::PRESETS for the exact option list.
Custom transport (for tests)
$client = new \JsoProtector\Client(function (string $endpoint, string $body): array { return ['status' => 200, 'body' => '{"Type":"Succeed","Items":[...]}']; });
Tests
composer install vendor/bin/phpunit tests
License
UNLICENSED. Free companion to the JSO service.