Download the PHP package spatie/typed without Composer

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

Improved PHP type system in userland

Latest Version on Packagist Build Status StyleCI Quality Score Total Downloads

This package is a mere proof of concept about what's possible in PHP's userland to improve type checking. It adds support for type inference, generics, union types, typed lists, tuples and structs. Because all is done in userland, there are limitations on what syntax is possible.

Support us

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products.

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

Usage

Type inference

Both collections, tuples and structs support inferred types. This means that all examples are also possible, without manually specifying types. For example:

The following examples all show the manual type configuration. There are some cases where type inference falls short, and you have to fall back on manually defining them. You might also prefer the manual approach, for clarity's sake.

Note that type may be partially inferred. Some fields in tuples or structs may be type definitions, others may be real values. Uninitialised types will throw an error on read.

Typed lists and collections:

It's possible to directly initialise a collection with data after construction.

This package also provides some predefined lists, as shortcuts.

Generics:

Generic types wrap around classes, allowing you to not creating a custom type for every class.

Tuples:

Like lists, a tuple can also be given some data after construction with the set function.

Structs:

Nullable type

A nullable type can be defined in two, functionally identical, ways:

Union Type

A union type means a collection of multiple types.

Union types may also be nullable and contain generics.

What's not included:

Creating your own types

The GenericType or T::generic() can be used to create structures of that type. It is, however, also possible to create your own types without generics. Let's take the example of Post. The generic approach works without adding custom types.

The generic part can be skipped if you create your own type.

Now you can use PostType directly:

You're also free to extend the T helper.

The Nullable trait adds the following simple snippet, so that the type can be made nullable when used.

Note: It's recommended to also implement __toString in your own type classes.

Extending data structures

You're free to extend the existing data structures. For example, you could make shorthand tuples like so:

Why did we build this?

PHP has a very weak type system. This is simultaneously a strength and a weakness. Weak type systems offer a very flexible development platform, while strong type systems can prevent certain bugs from happening at runtime.

In its current state, PHP's type system isn't ready for some of the features many want. Take, for example, a look at some RFC's proposing changes to the current type system.

Some of those are already declined because of runtime performance issues, or implementation difficulties. This package is a thought experiment of what we could do if those features are implemented in PHP, usable with native syntax.

For example, the following syntax would be much more preferable over how this package does it.

Anyways, it's stuff to think about. And maybe PHP's type system is fine as it is now? You can read more about type safety on my blog.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Postcardware

You're free to use this package, but if it makes it to your production environment we highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using.

Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium.

We publish all received postcards on our company website.

Credits

License

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


All versions of typed with dependencies

PHP Build Version
Package Version
Requires php Version ^7.1
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 spatie/typed contains the following files

Loading the files please wait ....