Skip to content

No build #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 13 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ PHPBench Service Container
[![Build Status](https://travis-ci.org/phpbench/container.svg?branch=master)](https://travis-ci.org/phpbench/container)
[![StyleCI](https://styleci.io/repos/55606670/shield)](https://styleci.io/repos/55606670)

This is a simple but powerful (of course its powerful) dependency injection container:
This is a simple but powerful dependency injection container:

- Extendable (a.k.a service providers);
- Configurable;
- Taggable services;
- Extensions provide default configuration;
- Service tagging;

This container was developed incidentally for PHPBench, and is not a very
polished library, but I like it.
Expand All @@ -18,7 +18,7 @@ Simple usage
------------

```php
$container = new Container();
$container = Container::create();
$container->register('foobar', function (Container $container) {
return new \stdClass();
});
Expand All @@ -39,7 +39,6 @@ $container = new Container(
'foo.bar' => 'my_new_value',
]
);
$container->init(); // will trigger loading of the extensions.
```

```php
Expand All @@ -48,18 +47,25 @@ class MyExtension implements ExtensionInterface
public function load(Container $container)
{
$container->register('my_service', function (Container $container) {
return new MyService(
$service = new MyService(
$container->getParameter('foo_bar'),
$container->get('some_other_service')
);

// get all tagged services and add them to the instantiated object
foreach ($container->getServiceIdsForTag('my_tag') as $serviceId) {
$service->add($container->get($serviceId));
}
});

$container->register('tagged_service', function (Container $container) {
return new MyService(
$service = new MyService(
$container->getParameter('foo_bar'),
$container->get('some_other_service')
);
}, [ 'tag' => []);

return $service;
}, [ 'my_tag' => [ 'attribute_1' => 'foo' ]); // optional tag attributes
}

/**
Expand All @@ -73,16 +79,6 @@ class MyExtension implements ExtensionInterface
'foo_bar' => 'this is foo'
];
}

/**
* Build the container.
*/
public function build(Container $container)
{
foreach ($container->getServiceIdsForTag() as $serviceId) {
$container->get('my_service')->add($container->get($serviceId));
}
}
}
```

Expand Down
4 changes: 0 additions & 4 deletions lib/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,6 @@ public function init()
foreach ($extensions as $extension) {
$extension->load($this);
}

foreach ($extensions as $extension) {
$extension->build($this);
}
}

/**
Expand Down
7 changes: 0 additions & 7 deletions lib/ExtensionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,4 @@ public function load(Container $container);
* @return array
*/
public function getDefaultConfig();

/**
* Called after all services in all extensions have been registered.
*
* @param Container $container
*/
public function build(Container $container);
}
6 changes: 0 additions & 6 deletions tests/Unit/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ public function testRegisterExtension()
$object = $container->get('foobar');
$this->assertInstanceOf('stdClass', $object);
$this->assertEquals('bar', $object->foobar);
$this->assertEquals('barfoo', $object->setOnBuild);
}

/**
Expand Down Expand Up @@ -226,9 +225,4 @@ public function load(Container $container)
return $stdClass;
});
}

public function build(Container $container)
{
$container->get('foobar')->setOnBuild = 'barfoo';
}
}