2017 © Pedro Peláez
 

library patterns

Common programing patterns

image

evo/patterns

Common programing patterns

  • Wednesday, April 18, 2018
  • by ArtisticPhoenix
  • Repository
  • 1 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Patterns

Common programing patterns for evo, (*1)

  • Singleton (trait and interface)
  • Multiton (trait and interface), (*2)

    If you don't know what a Singlton is I suggest reading about it, (*3)

    https://en.wikipedia.org/wiki/Singleton_pattern, (*4)

    Singleton useage, (*5)

    ``` use evo\pattern\singleton\SingletonTrait; use evo\pattern\singleton\SingletonInterface;, (*6)

    Class Foo implements SingletonInterface{ use Singleton; protected function init(){ //stuff to do on __construct } }, (*7)

Then you can call your class like this (each additional call will return the same instance of the class)

$Foo = Foo:getInstance();, (*8)

Multiton usage

use evo\pattern\singleton\MultitonTrait; use evo\pattern\singleton\MultitonInterface;, (*9)

Class Foo implements MultitonInterface{ use Multiton; protected function init(){ //stuff to do on __construct } } ```, (*10)

Then you can call your class like this, (*11)

$Foo = Foo:getInstance();

The diffrence between them is the Multiton acts more like a container for Singlton instances. So you can call the getInstance method multiple times with diffrent aliases and get multiple copies of the class, each a singleton in it's own right. Becareful using Static proprites on multitons as they can be a bit tricky., (*12)

``` //this will produce two singleton instances of the class $Foo1 = Foo:getInstance('instance1'); $Foo2 = Foo:getInstance('instance2');, (*13)


Install via composer

{ "require" : { "evo/patterns" : "~1.0" } } ``` I plan to add a few more to this, as needed., (*14)

The Versions

18/04 2018

dev-master

9999999-dev

Common programing patterns

  Sources   Download

GPL-3.0

The Requires

  • php >=5.6

 

patterns

01/04 2018

1.0.0

1.0.0.0

Common programing patterns

  Sources   Download

GPL-3.0

The Requires

  • php >=5.6

 

patterns