trentonmaki/complex-types

Adds strongly typed lists and maps

Installs: 6

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

pkg:composer/trentonmaki/complex-types

1.1.0 2015-08-19 18:27 UTC

This package is not auto-updated.

Last update: 2026-02-01 01:17:54 UTC


README

Complex list and map types for PHP

API

The TypedMap and TypedList API support almost the same interface as an Array (see (ArrayObject)[http://php.net/manual/en/class.arrayobject.php] for an example of this) the differences are in the key values these two types allow and the icompatability with the array_* functions

Usage

Simple subclass TypedList or TypedMap for each kind of list or map you want, then write the isType() or keyType() and valueType() methods.

Example:

class StringList extends TypedList
    {

      /**
       * @param mixed $val
       * @return bool
       */
      protected function isType($val)
      {
          return is_string($val);
      }
  }

You can now use StringList as you would a normal array. If someone attempts to put a non string in your list, an exception will be thrown immediately.