Download the PHP package rcalicdan/ramsey-collection-typephp-extension without Composer

On this page you can find all versions of the php package rcalicdan/ramsey-collection-typephp-extension. 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 ramsey-collection-typephp-extension

Ramsey Collection TypePHP Extension

Enables TypePHP runtime type checking and reified generic enforcement for ramsey/collection.

Latest Version License PHP Version


Overview

The ramsey/collection library provides typed collection structures in PHP. However, because its internal type checking relies on standard string comparisons and instanceof checks against basic class names or primitive types (int, string, object), it cannot enforce complex static analysis annotations at runtime.

This extension bridges TypePHP and ramsey/collection, allowing all collection classes (Collection, Set, Queue, DoubleEndedQueue, TypedMap, etc.) to enforce modern PHPDoc type contracts dynamically without changing their public API.


Native Ramsey Collection Limitations vs. TypePHP Capabilities

Feature Native ramsey/collection With TypePHP Extension
Basic Class Checking Supported (new Collection(User::class)) Supported and reified
Scalar Refinements Unsupported (Only checks broad int or string) Supported (positive-int, non-empty-string, int<1, 100>, numeric-string, etc.)
Union Types Unsupported (Cannot accept Dog \| Cat without base class) Supported (Collection<Dog \| Cat>)
Array Shapes Unsupported (Only checks broad array) Supported (Collection<array{id: positive-int, name: non-empty-string}>)
Intersection & DNF Types Unsupported Supported (Collection<Countable & ArrayAccess>)
Closure Parameter Validation Unsupported (Closure arguments in filter() are not checked) Supported (filter(callable(T): bool))
Runtime Generic Introspection Unsupported (Cannot inspect template T via Reflection) Supported (TypePHP::getGenericType($collection))
Cloning State Preservation Partial Fully preserved and isolated in memory via \WeakMap

Key Capabilities Added to Ramsey Collections

  1. Scalar Refinements within Generics: Native collections can only restrict elements to basic primitives like int or string. With TypePHP, you can restrict collections to positive-int, non-empty-string, int<min, max>, uppercase-string, and bitmasks.
  2. Union Types within Generics: Native collections require all elements to extend a single common ancestor or be marked as object. TypePHP allows heterogeneous union types such as Collection<Dog|Cat>.
  3. Array Shapes within Generics: Validate structured associative arrays and tuples directly when inserted into a collection, ensuring nested keys and values adhere to schema rules.
  4. Higher-Order Closures: Methods like filter() validate incoming elements against the declared callback signature, preventing runtime type mismatches inside closure bodies.
  5. Reified Generic Introspection: Inspect the concrete generic type assigned to any collection instance at runtime using the TypePHP::getGenericType() API.

Installation

Development & Testing (Recommended)

This library is primarily intended as a development dependency for local development, testing suites (Pest, PHPUnit), and CI/CD pipelines:

Production Runtime (Optional)

If your architecture requires strict runtime generic enforcement and input boundary validation in production environments, you may install it as a standard dependency:

Note: In production environments, it is recommended to enable OPcache, JIT, and execute php bin/typephp cache:warm during your deployment pipeline for zero-overhead AST execution.


Configuration

Register the extension in your project's typephp.php configuration file:


Usage Examples

1. Reified Class Generics (Collection<T>)


2. Refined Scalar Constraints (positive-int, non-empty-string)


3. Array Shapes inside Collections


4. Union Generics (Collection<Dog|Cat>)


5. Generic Typed Maps (TypedMap<K, T>)

Enforces both key (K) and value (T) constraints simultaneously:


6. Queues & Double-Ended Queues (Queue<T> & DoubleEndedQueue<T>)


7. Custom Collection Subclassing (@extends AbstractCollection<T>)

When creating your own collection subclasses, TypePHP inherits the generic parameter directly from your class DocBlock:


8. Runtime Generic Introspection & Cloning


Supported Ramsey Collection Classes

Class Generic Parameters Supported Operations
Ramsey\Collection\Collection<T> T add(), offsetSet(), filter(), first(), last(), where(), merge()
Ramsey\Collection\Set<T> T add(), offsetSet(), duplicate rejection with type check
Ramsey\Collection\Queue<T> T add(), offer(), element(), peek(), poll(), remove()
Ramsey\Collection\DoubleEndedQueue<T> T addFirst(), addLast(), offerFirst(), offerLast(), firstElement(), lastElement()
Ramsey\Collection\AbstractArray<T> T Array access, serialization, and iteration
Ramsey\Collection\Map\TypedMap<K, T> K of array-key, T put(), putIfAbsent(), replace(), offsetSet()
Ramsey\Collection\Map\AbstractTypedMap<K, T> K of array-key, T Subclasses inheriting custom typed maps

Testing

Run the test suite using Pest:


License

This project is open-source software licensed under the MIT License.


All versions of ramsey-collection-typephp-extension with dependencies

PHP Build Version
Package Version
Requires typephp/typephp Version ^0.6
ramsey/collection Version ^2.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 rcalicdan/ramsey-collection-typephp-extension contains the following files

Loading the files please wait ...