Skip to content

Commit

Permalink
FIX: Why it's rename to Aware
Browse files Browse the repository at this point in the history
  • Loading branch information
gravataLonga committed May 13, 2020
1 parent ba09dbb commit e5f068d
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 79 deletions.
40 changes: 20 additions & 20 deletions README.md
Expand Up @@ -25,9 +25,9 @@ composer require gravatalonga/container
### Basic Usage

```php
use Gravatalonga\Container\Aware;
use Gravatalonga\Container\Container;

$container = new Aware();
$container = new Container();
$container->set('random', function() {
return rand(0, 1000);
});
Expand All @@ -46,9 +46,9 @@ if ($container->has('random1')) {
When creating a new instance of Container, you can pass on first argument configurations or entries to be already binded into container.

```php
use Gravatalonga\Container\Aware;
use Gravatalonga\Container\Container;

new Aware([
new Container([
'settings' => ['my-settings'],
FooBar::class => function (\Psr\Container\ContainerInterface $c) {
return new FooBar();
Expand All @@ -59,10 +59,10 @@ new Aware([
### Using Service Provider

```php
use Gravatalonga\Container\Aware;
use Gravatalonga\Container\Container;


$container = new Aware();
$container = new Container();
$container->set(RedisClass::class, function () {
return new RedisClass();
});
Expand All @@ -74,10 +74,10 @@ $cache = $container->get('Cache');
When using `set`, `factory` or `share` with Closure and if you want to get `Container` it's self, you can pass type hint of `ContainerInterface` as argument.

```php
use Gravatalonga\Container\Aware;
use Gravatalonga\Container\Container;
use Psr\Container\ContainerInterface;

$container = new Aware([
$container = new Container([
'server' => 'localhost',
'username' => 'root'
]);
Expand All @@ -102,9 +102,9 @@ $cache = $container->get('Cache');
### Using Array like access

```php
use Gravatalonga\Container\Aware;
use Gravatalonga\Container\Container;

$container = new Aware();
$container = new Container();
$container[FooBar::class] = function(ContainerInterface $container) {
return new FooBar($container->get('settings'));
};
Expand All @@ -119,9 +119,9 @@ if (isset($container[FooBar::class])) {
Alias like the name indicate, it to make a possibility to make an alias from one entry to another. It will throw an exception.

```php
use Gravatalonga\Container\Aware;
use Gravatalonga\Container\Container;

$container = new Aware();
$container = new Container();
$container->set(FooBar::class, function(ContainerInterface $container) {
return new FooBar($container->get('settings'));
});
Expand Down Expand Up @@ -158,7 +158,7 @@ You can resolve class which not set into container. Our container it will attemp
### Using Type Hint Class

```php
use Gravatalonga\Container\Aware;
use Gravatalonga\Container\Container;

class FooBar {}

Expand All @@ -170,7 +170,7 @@ class Test
}
}

$container = new Aware();
$container = new Container();
$container->set(FooBar::class, function () {
return new FooBar();
});
Expand All @@ -183,7 +183,7 @@ $container->get(Test::class); // FooBar it will inject into Test class.
### Using Built in type

```php
use Gravatalonga\Container\Aware;
use Gravatalonga\Container\Container;
class Test
{
public function __construct(string $name)
Expand All @@ -192,7 +192,7 @@ class Test
}
}

$container = new Aware();
$container = new Container();
$container->set('name', 'my-var');

$container->get(Test::class); // my-var it will inject into Test class.
Expand All @@ -201,7 +201,7 @@ $container->get(Test::class); // my-var it will inject into Test class.
If argument accept nullable it will attempt resolve; otherwise it will inject null as argument.

```php
use Gravatalonga\Container\Aware;
use Gravatalonga\Container\Container;

class Test
{
Expand All @@ -216,7 +216,7 @@ class Test
}
}

$container = new Aware();
$container = new Container();

$container->get(Test::class); // null it will inject into Test class.
```
Expand All @@ -225,7 +225,7 @@ In also attempt to resolve auto wiring of construction by it's default value, it

First case, if value is a simple built in type value.
```php
use Gravatalonga\Container\Aware;
use Gravatalonga\Container\Container;

class Test
{
Expand All @@ -240,7 +240,7 @@ class Test
}
}

$container = new Aware();
$container = new Container();

$container->get(Test::class); // 'Jonathan Fontes' it will pass into container...
```
Expand Down
6 changes: 3 additions & 3 deletions benchmarks/ContainerBench.php
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use Gravatalonga\Container\Aware;
use Gravatalonga\Container\Container;

/**
* @Revs({1, 8, 64, 4096})
Expand All @@ -11,7 +11,7 @@
class ContainerBench
{
/**
* @var Aware
* @var Container
*/
private $container;

Expand All @@ -25,7 +25,7 @@ public function benchFactory()

public function init()
{
$this->container = new Aware();
$this->container = new Container();
$this->container->set('my-logger', static function () {
return mt_rand(0, 1000);
});
Expand Down
4 changes: 2 additions & 2 deletions src/Aware.php → src/Container.php
Expand Up @@ -19,7 +19,7 @@
/**
* Class Container.
*/
class Aware extends AutoWiringAware implements ArrayAccess, ContainerInterface
class Container extends AutoWiringAware implements ArrayAccess, ContainerInterface
{
/**
* @var ContainerInterface
Expand Down Expand Up @@ -62,7 +62,7 @@ public function __construct(array $config = [])
$this->share(ContainerInterface::class, static function () use ($self) {
return $self;
});
$this->alias(ContainerInterface::class, Aware::class);
$this->alias(ContainerInterface::class, Container::class);
}

/**
Expand Down
20 changes: 10 additions & 10 deletions tests/AliasMethodTest.php
Expand Up @@ -4,7 +4,7 @@

namespace Tests;

use Gravatalonga\Container\Aware;
use Gravatalonga\Container\Container;
use Gravatalonga\Container\NotFoundContainerException;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;
Expand All @@ -19,7 +19,7 @@ final class AliasMethodTest extends TestCase
{
public function testAliasOneVarToAnotherClass()
{
$container = new Aware();
$container = new Container();
$container->set(Bar::class, static function () {
return new Bar();
});
Expand All @@ -35,7 +35,7 @@ public function testAliasOneVarToAnotherClass()

public function testAliasOneVarToAnotherShareEntry()
{
$container = new Aware();
$container = new Container();
$container->share(Bar::class, static function () {
return new Bar();
});
Expand All @@ -51,7 +51,7 @@ public function testAliasOneVarToAnotherShareEntry()

public function testAliasOneVarToAnotherVar()
{
$container = new Aware();
$container = new Container();
$container->set('foobar', 'Hello World');

$container->alias('foobar', 'hello');
Expand All @@ -63,7 +63,7 @@ public function testAliasOneVarToAnotherVar()

public function testCanUseMakeOverAlias()
{
$container = new Aware();
$container = new Container();
$container->factory(FooBarWithNullClass::class, static function (ContainerInterface $container, $name = null) {
return new FooBarWithNullClass($name);
});
Expand All @@ -79,20 +79,20 @@ public function testCanUseMakeOverAlias()

public function testContainerInterfaceIsAliasOfItSelf()
{
$container = new Aware();
$container = new Container();

self::assertTrue($container->has(ContainerInterface::class));
self::assertTrue($container->has(Aware::class));
self::assertTrue($container->has(Container::class));
self::assertSame($container->get(ContainerInterface::class), $container->get(ContainerInterface::class));
self::assertSame($container->get(Aware::class), $container->get(Aware::class));
self::assertSame($container->get(ContainerInterface::class), $container->get(Aware::class));
self::assertSame($container->get(Container::class), $container->get(Container::class));
self::assertSame($container->get(ContainerInterface::class), $container->get(Container::class));
}

public function testGotExceptionIfAliasReferedToNonEntry()
{
$this->expectException(NotFoundContainerException::class);
$this->expectExceptionMessage('Entry bar not found');
$container = new Aware();
$container = new Container();

$container->alias('bar', 'foo');

Expand Down
12 changes: 6 additions & 6 deletions tests/ContainerArrayAccessTest.php
Expand Up @@ -4,7 +4,7 @@

namespace Tests;

use Gravatalonga\Container\Aware;
use Gravatalonga\Container\Container;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerInterface;

Expand All @@ -16,7 +16,7 @@ final class ContainerArrayAccessTest extends TestCase
{
public function testCanUseOffsetExists()
{
$container = new Aware();
$container = new Container();
$container['fact'] = static function (ContainerInterface $container) {
return mt_rand(1, 100);
};
Expand All @@ -27,7 +27,7 @@ public function testCanUseOffsetExists()

public function testCanUseOffsetGet()
{
$container = new Aware();
$container = new Container();
$container['fact'] = static function (ContainerInterface $container) {
return mt_rand(1, 100);
};
Expand All @@ -37,7 +37,7 @@ public function testCanUseOffsetGet()

public function testCanUseOffsetSet()
{
$container = new Aware();
$container = new Container();
$container['fact'] = static function (ContainerInterface $container) {
return mt_rand(0, 500000);
};
Expand All @@ -50,7 +50,7 @@ public function testCanUseOffsetSet()

public function testCanUseOffsetUnset()
{
$container = new Aware();
$container = new Container();
$container->share('hello', static function () {
return 'world';
});
Expand All @@ -71,7 +71,7 @@ public function testCanUseOffsetUnset()

public function testCanUserAliasFromArraySet()
{
$container = new Aware();
$container = new Container();
$container->share('hello', static function () {
return 'world';
});
Expand Down

0 comments on commit e5f068d

Please sign in to comment.