Download the PHP package ashallendesign/type-safe without Composer

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

Latest Version on Packagist Build Status Total Downloads PHP from Packagist GitHub license

Table of Contents

Overview

Type Safe is a lightweight package that you can use in your PHP projects to ensure your variables' types.

If you're interested in reading about why I made this package, check out this blog post.

Installation

You can install the package via Composer:

The package has been developed and tested to work with the following minimum requirements:

Usage

Simple Checks

Validating that a property is an integer:

Validating that a property is a string:

Validating that a property is a boolean:

Validating that a property is a closure:

Validating that a property is an object:

Validating that a property is an array:

Validating that a property is an associative array:

Advanced Checks

Validating that a property is an object of a specific class:

Validating that a property is an array containing specific fields:

Validating that a property is an associative array containing specific fields:

Custom Checks

You might want to use your own custom checks that aren't provided in the package by default. To do this, you can create your own class that implements the AshAllenDesign\TypeSafe\Check interface.

The interface enforces two methods: passes() and message(). The passes() method is used to define your logic that determines if the field is the correct type. The message() method is used to return the message that will be passed to the thrown exception if the validation fails.

For example, if we wanted to create a custom check to assert that our field was a Laravel Collection that only contained User models, it might look something like this:

We could then use that check like so:

`

Skipping Checks

There may be times when you don't want to run the type checks. For example, you might want to disable them in production environments and only run them in local, testing and staging environments. To skip the checks, you can simply use the skipChecks like shown in the example below:

Helpers Methods

There are three different ways that you can use the package to add type safe checks to your code.

The first method is by using the TypeSafe object itself like so:

Alternatively, you can use the safe() helper function that achieves the same thing as the code above. You can use the helper function like so:

The TypeSafe also includes helper methods that you can use for all the simple checks. The example shows how you can validate an integer field:

Testing

To run the tests for the package, you can use the following command:

Security

If you find any security related issues, please contact me directly at [email protected] to report it.

Contribution

If you wish to make any changes or improvements to the package, feel free to make a pull request.

To contribute to this library, please use the following guidelines before submitting your pull request:

Credits

Changelog

Check the CHANGELOG to get more information about the latest changes.

License

The MIT License (MIT). Please see License File for more information.


All versions of type-safe with dependencies

PHP Build Version
Package Version
Requires php Version ^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 ashallendesign/type-safe contains the following files

Loading the files please wait ....