2017 © Pedro Peláez
 

library facade

Facade pattern ready to use

image

mrubiosan/facade

Facade pattern ready to use

  • Saturday, August 19, 2017
  • by mrubiosan
  • Repository
  • 1 Watchers
  • 3 Stars
  • 5,246 Installations
  • PHP
  • 1 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 5 Versions
  • 26 % Grown

The README.md

facade

Facade pattern for PHP, (*1)

Build Status Maintainability Test Coverage, (*2)

As seen in the Laravel framework. You can call a method statically, and it will fetch an object from the container and call its method., (*3)

It's very useful for unbounded services like Logging. You can call it statically but change the underlying implementation(i.e: for testing)., (*4)

Also a good compromise when refactoring code that uses static class access., (*5)

Usage example, (*6)

//First declare your facade class
namespace MyDummyNameSpace;

class Foo extends \Mrubiosan\Facade\FacadeAccessor
{
    public static function getServiceName()
    {
       return 'foo'; //This is the name of the service in your container
    }
}
//Then initialize the facade system
$exampleContainer = new \ArrayObject([
    'foo' => new \DateTime(),
]);
$psrAdaptedContainer = new \Mrubiosan\Facade\ServiceLocatorAdapter\ArrayAccessAdapter($exampleContainer);
\Mrubiosan\Facade\FacadeLoader::init($psrAdaptedContainer, ['FooAlias' => 'MyDummyNameSpace\Foo']);
//Ready to use
echo \MyDummyNameSpace\Foo::getTimestamp();
echo \FooAlias::getTimestamp();

Wiring it up

Step 1

If you're using a PSR11 Container, you can skip this step. Oterwise you'll need to use an adapter: * Mrubiosan\Facade\ServiceLocatorAdapter\ArrayAccessAdapter: if you're using pimple you can use this. * Mrubiosan\Facade\ServiceLocatorAdapter\CallableAdapter: you can provide a callable parameter that will receive the service name it should retrieve., (*7)

Or straight implement Psr\Container\ContainerInterface, (*8)

Step 2

Initialize the facade system, (*9)

Mrubiosan\Facade\FacadeLoader::init($psrContainer);

The Versions

19/08 2017

dev-master

9999999-dev

Facade pattern ready to use

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4.4

 

The Development Requires

silex zend symfony facade

28/12 2016

1.1

1.1.0.0

Facade pattern ready to use

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4.4

 

The Development Requires

silex zend symfony facade

25/09 2016

1.0

1.0.0.0

Facade pattern ready to use

  Sources   Download

GPL-3.0

The Requires

  • php >=5.4.4

 

The Development Requires

silex zend symfony facade

24/05 2016

0.1.1

0.1.1.0

  Sources   Download

The Requires

  • php >=5.4.4

 

The Development Requires

04/08 2015

0.1

0.1.0.0

  Sources   Download

The Requires

  • php >=5.4.4

 

The Development Requires