GithubHelp home page GithubHelp logo

caldera-containers's Introduction

Caldera Containers

A collection of useful containers for Caldera (or your) development.

Install

composer require calderawp/caldera-containers

Requires PHP 5.6+

Containers

  • calderawp\CalderaContainers\Container Basic PSR-11 compatible container decorating Pimple.

    • Is abstract.
    • Converts to arrays. calderawp\CalderaContainers\Interfaces\Arrayable
    • Converts to JSON. JsonSerializable
  • calderawp\CalderaContainers\ControlledContainer Extends the base container but only allows in specified attributes.

    • Is abstract
  • calderawp\CalderaContainers\Service\Coantainer A basic service container, with provider bindings, lazy-loaded objects, and singletons.

Usage

calderawp\CalderaContainers\Container

@todo

calderawp\CalderaContainers\ControlledContainer

@todo

calderawp\CalderaContainers\Service\Container

Binding As Factory

Add a binding that returns a new object of the same class using the alias std

$container = new \calderawp\CalderaContainers\Service\Container();
$container->bind( 'std', function (){
     $obj = new \stdClass();
     $obj->foo = rand();
     return $obj;
});

//$obj1->foo !== $obj2->foo
$obj1 = $container->make('std');
$obj2 = $container->make('std');

Binding A Singleton

Add a binding that returns a the same object of the same class using the alias std. You MUST instantiate class before binding.

$container = new \calderawp\CalderaContainers\Service\Container();
$obj = new \stdClass();
$obj->foo = rand();
$container->singleton( 'std', $obj );

//$obj1->foo === $obj2->foo
$obj1 = $container->make('std');
$obj2 = $container->make('std');

Binding A Lazy-Loaded Singleton

Add a binding that returns a the same object of the same class using the alias std. Class is instantiated 1 times, but is not instantiated until used, if ever.

$container = new \calderawp\CalderaContainers\Service\Container();
$container->singleton( 'std', function (){
     $obj = new \stdClass();
     $obj->foo = rand();
     return $obj;
});

//$obj1->foo === $obj2->foo
$obj1 = $container->make('std');
$obj2 = $container->make('std');

## Stuff.
Copyright 2018 CalderaWP LLC. License: GPL v2 or later.

caldera-containers's People

Contributors

kainuk avatar shelob9 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.