Skip to content

Commit

Permalink
Fix description in README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
devanych committed Oct 1, 2020
1 parent e684367 commit 93312a9
Showing 1 changed file with 1 addition and 28 deletions.
29 changes: 1 addition & 28 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -205,15 +205,10 @@ $container->set(UserProfile::class, function (\Psr\Container\ContainerInterface
return new UserProfile($container->get('user_name'), $container->get('user_age'));
});

$container->set(User::class, function (\Psr\Container\ContainerInterface $container): User {
return new User($container->get(UserProfile::class));
});

$container->get(User::class);

// Or with default values (`John` and `25`)

$container->set(User::class, User::class);
$container->get(User::class);
```

Expand All @@ -228,34 +223,12 @@ final class UserProfileFactory implements \Devanych\Di\FactoryInterface
return new UserProfile($container->get('user_name'), $container->get('user_age'));
}
}

final class UserFactory implements \Devanych\Di\FactoryInterface
{
public ?string $name;
public ?int $age;

public function __construct(string $name = null, int $age = null)
{
$this->name = $name;
$this->age = $age;
}

public function create(\Psr\Container\ContainerInterface $container): User
{
if ($this->name === null || $this->age === null) {
return new User($container->get(UserProfile::class));
}

return new User(new UserProfile($this->name, $this->age));
}
}
*/

$container->setMultiple([
UserProfile::class => UserProfileFactory::class,
'user_name' => 'Alexander',
'user_age' => 40,
User::class => UserFactory::class,
UserProfile::class => UserProfileFactory::class,
]);

$container->get(User::class); // User instance
Expand Down

0 comments on commit 93312a9

Please sign in to comment.