Download the PHP package pinkary-project/type-guard without Composer

On this page you can find all versions of the php package pinkary-project/type-guard. 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 type-guard

GitHub Workflow Status (master) Total Downloads Latest Version License


This library is a work in progress. Please, do not use it in production.

Type Guard module is part of the Pinkary Project, and allows you to narrow down the type of a variable to a more specific type. Using the type function, you can perform specific checks to determine the type of an object and then use that object in a way that is type-safe according to the PHPStan and Psalm static analyzers.

Here is an example, where we use the type function to narrow down the type of a variable that previously had a mixed type:

Here is another example, where we use the type function to narrow down the type of a variable that previously could be null. In the process, zero type information is lost:

And one more example, where we narrow down the type of a variable to a Collection without losing the type information:

Installation

Requires PHP 8.2+

You may use Composer to install Type Guard into your PHP project:

Usage

as

Asserts and narrows down the type of the given variable to a more specific type.

asInt()

Asserts and narrows down the type of the given variable to an integer.

asFloat()

Asserts and narrows down the type of the given variable to a float.

asString()

Asserts and narrows down the type of the given variable to a string.

asBool()

Asserts and narrows down the type of the given variable to a boolean.

asNull()

Asserts and narrows down the type of the given variable to a null.

asCallable()

Asserts and narrows down the type of the given variable to a callable.

not()->null()

Asserts and narrows down the type of the given variable to a non-null value.

asArray()

Asserts and narrows down the type of the given variable to an array.

asIterable()

Asserts and narrows down the type of the given variable to an iterable.


Type Guard is part of the Pinkary Project project. It was created by Nuno Maduro and open-sourced under the MIT license.


All versions of type-guard with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2.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 pinkary-project/type-guard contains the following files

Loading the files please wait ....