Download the PHP package phore/json-patch without Composer

On this page you can find all versions of the php package phore/json-patch. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package json-patch

Phore JSON Patch

Atomic JSON Patch for PHP 8.5+, with RFC 6901 pointers, all six RFC 6902 operations, configurable limits, optimistic conflict checks and an optional stable-ID representation for editing arrays. Runtime dependencies: PHP and JSON only. No AI provider, HTTP client or schema library is required.

Extracted from the deterministic patch core of phore/ai-harness. Typed object hydration, schema validation and AI-generated patch envelopes remain in that package. Public classes now use Phore\JsonPatch\.

Installation

The initial package is being prepared for publication. After it is available on Packagist:

For development before publication, clone this repository and run composer install, composer test and composer examples.

Apply a patch

Operations run sequentially against a detached candidate. Any error aborts the batch without changing the input. Operation values are also copied on construction and access, and copy creates independent values. An optional validator callback receives a separate copy of the final candidate once; returning false or throwing rejects it. This does not roll back external side effects in application callbacks.

JSON objects are stdClass, arrays are PHP lists. JsonValue::decode() preserves that distinction; use (object) [] for {} and [] for []. Associative PHP arrays normalize to objects. Null is a value, distinct from a missing member. test compares object members without ordering, arrays with ordering and numbers numerically; strings and booleans are distinct from numbers.

Pointers and operations

Operation Meaning Required fields
add Insert into a list or create/overwrite an object member op, path, value
remove Remove an existing value op, path
replace Replace an existing value op, path, value
move Remove source, then add at destination op, path, from
copy Copy source by value into destination op, path, from
test Reject the batch unless the existing value is equal op, path, value

JsonPointer::get($document, $pointer) reads a value; JsonPointer::escape($key) escapes a property name. The empty pointer '' addresses the root, / the empty-string property, ~0 a tilde and ~1 a slash. URI fragments and percent decoding are not supported. Array indices must be canonical nonnegative decimal integers without leading zeros. - appends for add destinations, including those of move/copy. Parents must already exist. Array indices always refer to the state after preceding operations; move resolves the destination after removal.

All six operations are implemented. Defaults deliberately allow only add, remove, replace, test, and forbid root mutations. To enable the full operation set and root changes:

Removing the root sets documentExists to false; this differs from JSON null. Only a subsequent root add can recreate it. Moving a path into its own descendant is rejected, including array paths whose indices would shift. fromArray() ignores unrecognized extension members; the typed operation contract rejects a non-null from on add/remove/replace/test and non-null value on remove/move/copy.

Limits and conflict protection

PatchApplyOptions property Default Effect
atomic true Non-atomic application is unsupported.
maxOperations 100 Bounds batch length.
maxPatchBytes 65536 Bounds serialized native patch size.
maxDocumentBytes 4194304 Bounds input and each intermediate document.
maxDepth 64 Bounds documents and pointers.
allowedOperations add, remove, replace, test Explicit operation allowlist.
allowRootReplacement false Enables root mutations.
forbiddenPaths [] Protects overlapping paths and indirect array shifts.
requireTests 'none' 'arrays' guards positional edits; 'all' guards every remove/replace/move source.
expectedHash null Requires the current input hash to match.
dryRun false Returns a validated candidate with dry_run status.

A required guard must be the immediately preceding successful test. It must cover the mutation or an identity/value inside the exact array element being removed/replaced. Guards do not make numeric indices stable. Protected paths block reads as well as mutations, including ancestors and copy/move sources.

Use JsonValue::hash($snapshot) as expectedHash. Hashes sort object keys recursively and preserve list order; this is a local format, not RFC 8785. A missing document hashes as SHA-256 of undefined. Persistence code must compare and swap the expected version/hash in its own transaction; this library only checks the supplied in-memory document. Dry run also leaves the input unchanged.

PatchApplyResult exposes value, documentExists, status, oldHash, newHash, operationCount, changedPaths and patch. Changed paths include explicit no-op replacements and move sources; they are not a minimal semantic diff.

Exceptions derive from PatchValidationException: PatchTestFailedException, PatchLimitException and PatchConflictException. Operation failures expose errorCode, operationIndex (zero-based), op and path, without embedding values in messages. Configuration errors throw InvalidArgumentException.

Stable array addressing

StableArrayView encodes lists into ordinary JSON objects with $order and $values. Patches remain standard JSON Patch; IDs replace positional addressing inside this transport view.

The keys above illustrate the shape. Actual encoding produces opaque deterministic keys from scalar id, key or uuid values. Missing/duplicate automatic identities get request-local ephemeral keys. new StableArrayView(['/items' => '/id']) requires a present, unique scalar identity at that pointer for each item. Explicit identities may use nested pointers such as /metadata/uuid.

  1. Encode the snapshot and retain the generated keys.
  2. Edit /items/$values/<key>/name to change a particular item.
  3. Add/remove both the value entry and its $order reference in the batch.
  4. Replace $order to reorder items, then decode the final candidate.

Business-ID changes do not retarget existing transport keys during a batch. Ephemeral keys have no cross-request meaning. Every nested/new list uses the same wrapper, except $order itself. Decoding rejects duplicate references, missing values, orphan values, malformed wrappers and unwrapped lists. Original objects with reserved $order or $values members cannot use this mode.

Validate the final transport in a callback that calls $codec->decode($candidate) and returns void, as in the executable example. Intermediate steps may temporarily have unmatched references; validation belongs after the batch.

Executable examples and tests

CI executes the suite and examples on PHP 8.5. The package includes the unchanged Apache-2.0 JSON Patch test corpus with its attribution and license; see test/fixtures/json-patch-tests. Runtime source retains the MIT package license.


All versions of json-patch with dependencies

PHP Build Version
Package Version
Requires php Version >=8.5
ext-json Version *
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package phore/json-patch contains the following files

Loading the files please wait ...