Download the PHP package dmitrijs-brujevs/data-object without Composer

On this page you can find all versions of the php package dmitrijs-brujevs/data-object. 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 data-object

DataObject

CI Latest Version PHP Version

A lightweight, path-based in-memory data container for PHP 8.2+.

Stores data in a nested array and provides access via slash-separated node paths. No dependencies. No magic beyond what is documented.


Why this library?


Requirements

Installation


Quick Start


Creating an Instance

Use the explicit factory methods when the input format is known:

The constructor also accepts all three formats via auto-detection:

An InvalidArgumentException is thrown if the string is neither valid JSON nor a serialized array.


Path Notation

Each segment of a path corresponds to a key in the nested structure. The default delimiter is /, customisable per instance.


API Reference

get(string $node = ''): mixed

Returns the value at the given path.

null vs missing: get() returns null for both a missing path and an explicit null value. Use has() to distinguish them, or use getOrDefault().


getOrDefault(string $node, mixed $default = null): mixed

Returns the value at the given path, or $default if the node does not exist.

Unlike get(), this correctly distinguishes between a missing node and an explicit null value:


has(string $node): bool

Returns true if the node exists, regardless of its value. Uses array_key_exists semantics.


is(string $node, mixed $value): bool

Strict equality check (===). Returns false if the node does not exist.

Note: is('missing', null) returns false (changed in 2.1.0 — previously returned true). Use has() or getOrDefault() if the old behaviour was relied upon.


set(string|int $node, mixed $value): static

Sets a value at the given path. Intermediate nodes are created automatically. If an intermediate node holds a non-array value, it is replaced with an array. Returns $this for fluent chaining.


add(array $array, string $node = ''): static

Recursively merges a nested array into the object. Existing values at the same paths are overwritten. Empty arrays are stored as-is — get() on that path returns an empty DataObject.


delete(string $node): static

Removes the value at the given path. Only the final segment is removed; parent nodes and siblings remain intact. No-op for non-existent paths.


toArray(): array

Returns the internal storage as a plain nested PHP array.


toJson(int $flags, int $depth): string

Returns the data encoded as a JSON string. Default flags: JSON_THROW_ON_ERROR | JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES.


serialize(): string

Returns the data as a PHP serialized string.


Magic camelCase Methods

Any method prefixed with get, set, has, is, or delete is resolved by __call() at runtime. The name is split on uppercase letters and joined with the delimiter to form a path.

Unknown prefixes throw BadMethodCallException (changed in 2.1.0 — previously returned null).

Limitations:


Iteration

DataObject implements Iterator. Nested arrays are automatically wrapped in DataObject instances at each level.


Custom Delimiter


Subclassing

DataObject is designed to be subclassed. All factory methods and internal wrapping use new static(), so nested arrays and iterator values are wrapped in the concrete subclass.

Public method overrides in subclasses take full precedence — PHP routes them directly without going through __call().


Security — Serialized Input

fromSerialized() and the constructor's auto-detection both use unserialize($data, ['allowed_classes' => false]).

This means:

Only pass serialized data from sources you control. Even with allowed_classes = false, deserializing untrusted user input is not recommended practice.


Running Locally


License

MIT


All versions of data-object with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
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 dmitrijs-brujevs/data-object contains the following files

Loading the files please wait ...