2017 © Pedro Peláez
 

library cable-container

Container Component for CableFramework

image

cable/cable-container

Container Component for CableFramework

  • Wednesday, June 28, 2017
  • by anonymframework
  • Repository
  • 1 Watchers
  • 0 Stars
  • 58 Installations
  • PHP
  • 8 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 29 Versions
  • 0 % Grown

The README.md

ServiceContainer

CableFramework service container, (*1)

Create new instance

$container = \Cable\Container\Factory::create();

Add a new service


// you can give an anonymous function $container->add('test', function(){ return new Test(); }); // you can give the name of class $container->add('test', Test::class); // you can give the already exists class instance $container->add('test', new Test());

Resolve the service


$test = $container->resolve('test'); // you can give arguments, // they will be used in constructor calling, // of course if you didnt give an instance $test->resolve('test', array('message' => 'hello world'));

Expectations


//you may want to check resolved value is an instance of something // well you can to that like that $resolved= $container->resolve('test'); if(!$resolved instanceof MyTestInterface){ } // the problem that you may want to check multipile interfaces // well, you can do that like that try{ // you can always give an array like, expect('test', [MyInterface::class, MySecondInterface::class]); $container->expect('test', MyTestInterface::class); }catch(ExpectationException $e){ echo "give me something valid"; } // if test doesnot return an instanceof MyTestInterface // container will throw an expectation exception

ServiceProviders


class Provider extends ServiceProvider{ public function register(){} public function boot(){ $this->getContainer()->add('test', Test::class); } } $container = \Cable\Container\Factory::create(); $container->addProvider(Provider::class); // now you can resolve the 'test' service $test = $container->resolve('test');

tag


$container->tag([Deneme::class, Test::class], 'test'); list($deneme, $test) = $container->tagged('test');

Using Annotations

Provider Annotation

You can put a @Provider annotation into class comment doc, (*2)

@Provider will be trigged when you are trying to resolve that class, (*3)


/** * * @Provider("Your\Provide\Class") * // you can give multiple providers like @Provider({"FirstProviderClass", "SecondProviderClass"}) */ class TestClass{ }

Inject Annotation

You can put @Inject Annotation into any method, (*4)

use Cable\Container\Annotations\Inject;

$container->add("my_alias_to_resolve", function(){
      return "hello world";
});


class TestClass{


    /**
     *
     * @Inject({"$test": "my_alias_to_resolve"})
     *
     */
    public function __construct($test){

    }

}

 ```

Same as ;

```php 

$container->when(Test::class)
          ->needs("test")
          ->give(function(){
              return $this->getContainer()->make("my_alias_to_resolve");
          });

The Versions

28/06 2017

dev-master

9999999-dev

Container Component for CableFramework

  Sources   Download

MIT

The Requires

 

The Development Requires

27/06 2017

1.2.8

1.2.8.0

Container Component for CableFramework

  Sources   Download

MIT

The Requires

 

The Development Requires

27/06 2017

1.2.7

1.2.7.0

Container Component for CableFramework

  Sources   Download

MIT

The Requires

 

The Development Requires

18/06 2017

1.2.6

1.2.6.0

Container Component for CableFramework

  Sources   Download

MIT

The Requires

 

The Development Requires

12/06 2017

1.2.4

1.2.4.0

Container Component for CableFramework

  Sources   Download

MIT

The Requires

 

The Development Requires

12/06 2017

1.2.5

1.2.5.0

Container Component for CableFramework

  Sources   Download

MIT

The Requires

 

The Development Requires

10/06 2017

1.2.3

1.2.3.0

Container Component for CableFramework

  Sources   Download

MIT

The Development Requires

09/06 2017

1.2.2

1.2.2.0

Container Component for CableFramework

  Sources   Download

MIT

The Development Requires

08/06 2017

1.2.1

1.2.1.0

Container Component for CableFramework

  Sources   Download

MIT

The Development Requires

05/06 2017

1.2.0

1.2.0.0

Container Component for CableFramework

  Sources   Download

MIT

The Development Requires

05/06 2017

1.1.9

1.1.9.0

Container Component for CableFramework

  Sources   Download

MIT

The Development Requires

04/06 2017

1.1.8

1.1.8.0

Container Component for CableFramework

  Sources   Download

MIT

The Development Requires

04/06 2017

1.1.7

1.1.7.0

Container Component for CableFramework

  Sources   Download

MIT

The Development Requires

03/06 2017

1.1.6

1.1.6.0

Container Component for CableFramework

  Sources   Download

MIT

The Development Requires

03/06 2017

1.1.5

1.1.5.0

Container Component for CableFramework

  Sources   Download

MIT

The Development Requires

01/06 2017

1.1.4

1.1.4.0

Container Component for CableFramework

  Sources   Download

MIT

The Development Requires

01/06 2017

1.1.2

1.1.2.0

Container Component for CableFramework

  Sources   Download

MIT

The Development Requires

01/06 2017

1.1.3

1.1.3.0

Container Component for CableFramework

  Sources   Download

MIT

The Development Requires

01/06 2017

1.1.1

1.1.1.0

Container Component for CableFramework

  Sources   Download

MIT

The Development Requires

31/05 2017

1.0.8

1.0.8.0

Container Component for CableFramework

  Sources   Download

MIT

The Development Requires

31/05 2017

1.1.0

1.1.0.0

Container Component for CableFramework

  Sources   Download

MIT

The Development Requires

31/05 2017

1.0.7

1.0.7.0

Container Component for CableFramework

  Sources   Download

MIT

The Development Requires

30/05 2017

1.0.6

1.0.6.0

Container Component for CableFramework

  Sources   Download

MIT

29/05 2017

1.0.5

1.0.5.0

Container Component for CableFramework

  Sources   Download

MIT

29/05 2017

1.0.4

1.0.4.0

Container Component for CableFramework

  Sources   Download

MIT

29/05 2017

1.0.3

1.0.3.0

Container Component for CableFramework

  Sources   Download

MIT

29/05 2017

1.0.2

1.0.2.0

Container Component for CableFramework

  Sources   Download

MIT

27/05 2017

1.0.1

1.0.1.0

Container Component for CableFramework

  Sources   Download

MIT

27/05 2017

1.0.0

1.0.0.0

Container Component for CableFramework

  Sources   Download

MIT

The Requires

 

by Avatar anonymframework