Download the PHP package minvws/icore-php-typearray without Composer

On this page you can find all versions of the php package minvws/icore-php-typearray. 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 icore-php-typearray

Typed Array

Typed Array provides runtime-checked access to values in PHP arrays. It uses Symfony PropertyAccess paths to read nested data and returns values with explicit PHP types.

This is useful when working with decoded JSON or other arrays containing mixed values. The package validates values when they are read and does not cast them to the requested type.

Dependencies

Installation

Install the package with Composer:

Quick start

The values assigned above have the types string, int, bool, and string respectively.

The examples below use the Composer autoloader and TypeArray import from this quick start.

Usage

Reading typed values

TypeArray provides getters for the most common PHP value types:

Method Return type
getString() string
getInt() int
getFloat() float
getBool() bool
getTypeArray() TypeArray

The requested value must have the exact PHP type. For example, getInt() does not convert a numeric string such as "42" to an integer.

Paths

Paths use the Symfony PropertyAccess syntax. Wrap each array key in square brackets and append brackets to read nested values:

See the Symfony PropertyAccess documentation for the complete path syntax and escaping rules.

Default and nullable values

getString(), getInt(), getFloat(), and getTypeArray() accept an optional default value. The default is returned when the path does not exist or contains null:

The nullable getters return null when a path does not exist:

getBool() returns false by default for a missing or null value. Pass a different default as its second argument when needed.

An existing null value passed to getTypeArrayOrNull() produces an empty TypeArray. A missing path returns null.

Nested arrays and iteration

Use getTypeArray() to keep reading a nested array with typed getters:

When getIterable() encounters a nested array, it yields that value as a TypeArray instance. Other values are yielded unchanged.

JSON and array conversion

Create a TypeArray directly from JSON:

Use toArray() to retrieve the wrapped array. TypeArray also implements JsonSerializable, so it can be passed directly to json_encode():

Invalid JSON passed to fromJson() throws JsonException.

Inspecting values

Exceptions

A missing path passed to getString(), getInt(), getFloat(), or getTypeArray() without a default throws InvalidIndexException. A value with the wrong PHP type throws IncorrectDataTypeException:

Doctrine DBAL

The package includes the optional type_array type for Doctrine DBAL. Install DBAL separately when using this integration:

Register the type during application startup:

The type stores a TypeArray as JSON and converts database values back to a TypeArray. See the Doctrine DBAL custom mapping type documentation for integration details.

Development

Install the development dependencies:

Testing

Run the coding-style checks, static analysis, and unit tests with:

License

This package is available under the BSD 3-Clause License.

Part of iCore

This package is part of the iCore project.


All versions of icore-php-typearray with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
symfony/property-access Version ^6.0 || ^7.0 || ^8.0
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 minvws/icore-php-typearray contains the following files

Loading the files please wait ...