2017 © Pedro Peláez
 

library type-jail

Enforce type constraints

image

internations/type-jail

Enforce type constraints

  • Thursday, December 21, 2017
  • by lstrojny
  • Repository
  • 30 Watchers
  • 20 Stars
  • 2,565 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 13 Versions
  • 68 % Grown

The README.md

Type Jail Test

Enforce super type contract of an object, (*1)

Usage

use InterNations\Component\TypeJail\Factory\SuperTypeFactory;
use InterNations\Component\TypeJail\Factory\JailFactory;
use InterNations\Component\TypeJail\Factory\SuperTypeJailFactory;

$file = new SplFileObject(__FILE__);


$factory = new JailFactory();
$file = $factory->createInstanceJail($file, 'SplFileInfo');

// Will return true
var_dump($file instanceof SplFileInfo);

// Will return the file path because that method is declared in SplFileInfo
$file->getFilePath();

// Will throw an exception indicating a type violation because that method
// is declared in SplFileObject
$file->flock();


$factory = new SuperTypeJailFactory();
$file = $factory->createInstanceJail($file, 'SplFileInfo');

// Will return false
var_dump($file instanceof SplFileInfo);

// Will return the file path because that method is declared in SplFileInfo
$file->getFilePath();

// Will throw an exception indicating a type violation because that method
// is declared in SplFileObject
$file->flock();


$factory = new SuperTypeFactory();
$file = $factory->createInstanceJail($file, 'SplFileInfo');

// Will return false
var_dump($file instanceof SplFileInfo);

// Will return the file path because that method is declared in SplFileInfo
$file->getFilePath();

// Fatal error: method not found
$file->flock();

Acknowledgement

Standing on the shoulders of ocramius/proxy-manager by Marco Pivetta that makes it super-duper easy to work with proxies., (*2)

The Versions

21/12 2017
21/12 2017
19/02 2017
19/02 2017
15/02 2017