2017 © Pedro Peláez
 

library type-validation

Allows to check if a variable is of the expected type, using a type specification string like the ones in PHPDoc blocks (int, \Foo\Bar[], null|string, etc).

image

perf/type-validation

Allows to check if a variable is of the expected type, using a type specification string like the ones in PHPDoc blocks (int, \Foo\Bar[], null|string, etc).

  • Tuesday, September 20, 2016
  • by jmfeurprier
  • Repository
  • 1 Watchers
  • 0 Stars
  • 145 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 9 Versions
  • 0 % Grown

The README.md

type validation

This package allows to check if a variable is of the expected type, using a type specification string like the ones in PHPDoc blocks., (*1)

Type specifications strings can be like the following:, (*2)

- integer
- scalar
- mixed
- string
- float[]
- int[][]
- {string:float}
- {int:\My\Stuff}
- {int:string}[]
- resource
- int|string
- {string:{int:\My\Stuff|int[]}}[]

etc., (*3)

Usage

Static validation with exceptions

<?php

use Jmf\TypeValidation\Type;

// Valid, will not throw an exception.
Type::mustBe('string', 'foo');

// Invalid, will throw an exception.
Type::mustBe('string', 123);

Static validation with booleans

<?php

use Jmf\TypeValidation\Type;

$variable = 'foo';

if (Type::is('string', $variable)) {
    // Valid
} else {
    // Invalid
}

Concrete validation

You can also use a concrete instance of a type validator., (*4)

<?php

use Jmf\TypeValidation\TypeValidator;

$validator = new TypeValidator();

$variable = 'foo';

if ($validator->isValid('string', $variable)) {
    // Valid
} else {
    // Invalid
}

Typical use

<?php

namespace App;

use Jmf\TypeValidation\Type;

class PotatoPeeler
{
    /**
     * @param Potato[] $potatoes
     */
    public function peel(array $potatoes): void
    {
        Type::mustBe('\App\Potato[]', $potatoes);

        // ...
    }
}

The Versions

20/09 2016

2.0.x-dev

2.0.9999999.9999999-dev

Allows to check if a variable is of the expected type, using a type specification string like the ones in PHPDoc blocks (int, \Foo\Bar[], null|string, etc).

  Sources   Download

MIT

The Requires

 

The Development Requires

20/09 2016

2.0.2

2.0.2.0

Allows to check if a variable is of the expected type, using a type specification string like the ones in PHPDoc blocks (int, \Foo\Bar[], null|string, etc).

  Sources   Download

MIT

The Requires

 

The Development Requires

06/08 2016

2.0.1

2.0.1.0

Allows to check if a variable is of the expected type, using a type specification string like the ones in PHPDoc blocks (int, \Foo\Bar[], null|string, etc).

  Sources   Download

MIT

The Requires

 

The Development Requires

13/05 2015

dev-master

9999999-dev

Allows to check if a variable is of the expected type, using a type specification string like the ones in PHPDoc blocks (int, \Foo\Bar[], null|string, etc).

  Sources   Download

MIT

The Requires

 

The Development Requires

12/05 2015

2.0.0

2.0.0.0

Allows to check if a variable is of the expected type, using a type specification string like the ones in PHPDoc blocks (int, \Foo\Bar[], null|string, etc).

  Sources   Download

MIT

The Requires

 

The Development Requires

03/05 2015

1.0.x-dev

1.0.9999999.9999999-dev

Allows to check if a variable is of the expected type, using a type specification string like the ones in PHPDoc blocks (int, \Foo\Bar[], null|string, etc).

  Sources   Download

MIT

The Requires

 

The Development Requires

03/05 2015

1.0.1

1.0.1.0

Allows to check if a variable is of the expected type, using a type specification string like the ones in PHPDoc blocks (int, \Foo\Bar[], null|string, etc).

  Sources   Download

MIT

The Requires

 

The Development Requires

04/04 2015

1.0.0

1.0.0.0

Typing package from perf, the PHP Extensible and Robust Framework

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires

30/03 2015

1.0.0-alpha

1.0.0.0-alpha

Typing package from perf, the PHP Extensible and Robust Framework

  Sources   Download

MIT

The Requires

  • php >=5.3.3

 

The Development Requires