Download the PHP package serger/typecaster without Composer

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

Typecaster

Simple typecasting for PHP arrays, with no external dependencies.

Typecaster coerces scalar values in an array to expected types — handy for normalizing request or form data before validation or persistence.

The library works on flat arrays only — it does not recurse into nested arrays (see Usage below). This makes it a good fit for casting single-row results from a database query, where every column is already a scalar; for deeply nested structures you'd call scalarArrayValues() separately per nested array.

Requirements

Installation

Usage

scalarArrayValues(array $arr, array $keys): array

Returns a copy of $arr with the keys listed in $keys coerced to the given type. Keys not present in $arr are left absent unless the spec has a default (see below), and non-scalar values are left untouched.

Each entry in $keys is either:

If a value is null, it is left as null when the spec allows it ('null' => true); otherwise it is coerced like any other value.

If a key is missing from $arr entirely and its spec has a default, that default is written to the result as-is — it is not coerced, so it should already match the declared type. default only applies to missing keys; a key present with an explicit null value is governed by 'null' instead, not by default.

Supported types

Type Notes
trim trim((string) $value)
string (string) $value
float See floatval() below; supports precision, min, max
int, integer, intval Same as float with precision = 0, then cast to int
bool, boolean, boolval boolval($value); an empty string becomes null if 'null' => true
json Decodes a JSON string; supports as_array

For json, empty strings become null only if 'null' => true, and a failed decode (json_decode returning null) is only written back when 'null' => true — otherwise the original string is kept.

floatval($value, ?int $precision = null, ?float $min = null, ?float $max = null, bool $nullable = false): ?float

Shared numeric coercion helper used internally by the float and int types, and also usable directly:

License

Released under the MIT License.


All versions of typecaster with dependencies

PHP Build Version
Package Version
Requires php Version >=7.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 serger/typecaster contains the following files

Loading the files please wait ...