Download the PHP package jasny/typecast without Composer

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

Jasny TypeCast

Build Status Code Coverage Scrutinizer Code Quality SensioLabsInsight

This library does type casting in PHP.

Type casting is natively supported in PHP. This library adds some basic logic to the process, like triggering a warning when casting a string like "FOO" to an integer.

In contrary to PHP's internal type casting, casting null always results in null.

Installation

The Jasny TypeCast package is available on packagist. Install it using composer:

composer require jasny/typecast

Usage

Alias

You can set aliases in cases where you might need to cast to an interface or abstract class or when you want to cast to a child class.

Errors

By default an E_NOTICE is triggered if a value can't be casted to desired type. Jasny\TypeCast follows stricter rules than PHP for casting values.

Instead of a notice an error of any severity can be triggered. Alternatively any Throwable like an exception or error can be thrown.

Variable name in error

You can use the setName() method to set the property or variable name that is casted. This name will be included in any error triggered when type casting. This can be useful when determining an issue.

Dependency injection

If your application supports dependency injection through containers, create a new TypeCast object and add it to the container as a service.

The value() method will clone the TypeCast object. Settings like any aliases or custom handlers will propagate.

Assume that Container is any PSR-11 compatible container.

Handlers

The Typecast object uses handlers to cast a value. Each handler can cast a value to a specific type. The following handlers are defined:

You may overwrite the handlers when creating the TypeCast object.

Desire

The desire method will return the handler. This is an alternative approach of using the value method. If you need to cast multiple values to the same type, it's recommendable to get the handler once using desire.

Multiple handler

In cast multiple types are specified, the handler will try to guess the type the value should be cast in. This might hurt performance. You may use NoTypeGuess to have the handler give an error if the type can't be determined.


All versions of typecast with dependencies

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

Loading the files please wait ....