2017 © Pedro Peláez
 

library checked-instance

Being able to create instances from a factory and only return valid instances

image

jankal/checked-instance

Being able to create instances from a factory and only return valid instances

  • Sunday, March 26, 2017
  • by jankal
  • Repository
  • 2 Watchers
  • 0 Stars
  • 7 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Checked Instances

Coverage Status Build Status Scrutinizer Code Quality Latest Stable Version License Total Downloads Latest Unstable Version composer.lock, (*1)

Create instances without the hassle of setting many constructor arguments., (*2)

CheckedInstance\Factory will create an instance of a given class implementing the CheckedInstance\InstanceInterface., (*3)

Factory

Create a newiInstance of TestClass

<?php
$factory = CheckedInstance\Factory::for(TestClass::class);
$object = $factory->make();

OR, (*4)

<?php
$factory = new CheckedInstance\Factory();
$factory->as(TestClass::class);
$object = $factory->make();

OR, (*5)

<?php
$factory = new CheckedInstance\Factory();
$object = $factory->make(TestClass::class);

Create a new instance of TestClass with parameters

<?php
$factory = new CheckedInstance\Factory();
$factory->with('authKey', '84746afg7u789h2');
$object = $factory->make();

Other options according to the examples above!, (*6)

Inject parameters from an \Psr\Container\ContainerInterface

<?php
/** @var $c \Psr\Container\ContainerInterface */
CheckedInstance\Factory::container($c);
$factory = new CheckedInstance\Factory();
$object = $factory->make();

One can also use a prefix that is prepended in front of the actual parameter, (*7)

<?php
/** @var $c \Psr\Container\ContainerInterface */
CheckedInstance\Factory::container($c);
$factory = CheckedInstance\Factory::prefix('test.');
$object = $factory->make();

Instance

A class which can be instantiated by the CheckedInstance\Factory needs to implement the CheckedInstance\InstanceInterface. But it may also inherit from CheckedInstance\Instance., (*8)

<?php
class TestInstance extends CheckedInstance\Instance {
    protected $required = [
        'authKey'
    ];
}

With this the Instance will only be made successfully if the authKey is set like CheckedInstance\Factory->with('authKey', <-value->), (*9)

The Versions

26/03 2017

dev-master

9999999-dev

Being able to create instances from a factory and only return valid instances

  Sources   Download

GPL-3.0

The Requires

 

The Development Requires

by Alexander Jank

07/03 2017

v1.0.0

1.0.0.0

Being able to create instances from a factory and only return valid instances

  Sources   Download

GPL-3.0

The Development Requires

by Alexander Jank