2017 © Pedro Peláez
 

library instanciate

A high order function to instanciate classes passing parameters

image

enalquiler/instanciate

A high order function to instanciate classes passing parameters

  • Thursday, September 7, 2017
  • by enalquiler
  • Repository
  • 3 Watchers
  • 0 Stars
  • 82 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 52 % Grown

The README.md

instanciate

A high order function to instanciate classes passing parameters., (*1)

Installation

composer require enalquiler/instanciate

Usage

A simple example, (*2)


use DateTimeImmutable; use function Enalquiler\Functional\instanciate; $fn = instanciate(DateTimeImmutable::class, 'now'); $dateTimeImmutableInstance = $fn(); // Returns an instance of DateTimeImmutable class

A more complex example combining the lazy middleware function, compose function to compose functions, and the awesome functional PHP library to build middleware pipelines using Zend Stratigility, (*3)

use Http\Factory\Diactoros\ResponseFactory;
use Zend\Diactoros\Response;
use Zend\Stratigility\MiddlewarePipe;
use function igorw\pipeline;
use function Functional\partial_right;

require_once __DIR__ . '/../vendor/autoload.php';

$pipe = new MiddlewarePipe();
$pipe->setResponsePrototype(new Response());

$lazyMiddleware = partial_right(
    pipeline(
        'Enalquiler\Functional\instanciate',
        'Enalquiler\Middleware\lazy'
    ),
    new ResponseFactory()
);

$pipe
    ->pipe($lazyMiddleware(LocaleMiddleware::class))
    ->pipe($lazyMiddleware(SessionMiddleware::class, new \PredisSessionStorage()))
    ->pipe($lazyMiddleware(RedirectionsMiddleware::class))
    ->pipe($lazyMiddleware(AdminMiddleware::class))
    ->pipe($lazyMiddleware(WebMiddleware::class))
    ->pipe($lazyMiddleware(NotFoundMiddleware::class))
;

$server = Server::createServer($app, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
$server->listen(new Zend\Stratigility\NoopFinalHandler());

Running the tests

php vendor/bin/phpunit

Authors

  • Christian Soronellas
  • Enalquiler Engineering

See also the list of contributors who participated in this project., (*4)

License

This project is licensed under the MIT License - see the LICENSE.md file for details, (*5)

The Versions

07/09 2017

dev-master

9999999-dev

A high order function to instanciate classes passing parameters

  Sources   Download

MIT

The Development Requires

by Christian Soronellas

07/09 2017

1.0.0

1.0.0.0

A high order function to instanciate classes passing parameters

  Sources   Download

MIT

The Development Requires

by Christian Soronellas