Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
samdark committed Aug 28, 2024
1 parent 295b5a3 commit 0cc415a
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 32 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ and configure classes resolving dependencies.
## Features

- [PSR-11](https://www.php-fig.org/psr/psr-11/) compatible.
- Supports property injection, constructor injection and method injection.
- Supports property injection, constructor injection, and method injection.
- Detects circular references.
- Accepts array definitions. You can use it with mergeable configs.
- Provides optional autoload fallback for classes without explicit definition.
Expand Down Expand Up @@ -53,7 +53,7 @@ array of *definitions*. The array keys are usually interface names. It will
then use these definitions to create an object whenever the application requests that type.
This happens, for example, when fetching a type directly from the container
somewhere in the application. But objects are also created implicitly if a
definition has a dependency to another definition.
definition has a dependency on another definition.

Usually one uses a single container for the whole application. It's often
configured either in the entry script such as `index.php` or a configuration
Expand Down Expand Up @@ -93,9 +93,9 @@ You can define an object in several ways:
- A full definition describes how to instantiate a class in more detail:
- `class` has the name of the class to instantiate.
- `__construct()` holds an array of constructor arguments.
- The rest of the config are property values (prefixed with `$`) and method calls, postfixed with `()`. They're
- The rest of the config is property values (prefixed with `$`) and method calls, postfixed with `()`. They're
set/called in the order they appear in the array.
- Closures are useful if instantiation is tricky and can better done in code. When using these, arguments are
- Closures are useful if instantiation is tricky and can be better done in code. When using these, arguments are
auto-wired by type. `ContainerInterface` could be used to get current container instance.
- If it's even more complicated, it's a good idea to move such a code into a
factory and reference it as a static call.
Expand Down Expand Up @@ -169,7 +169,7 @@ $car = $composite->get(CarInterface::class);
$bike = $composite->get(BikeInterface::class);
```

Note, that containers attached earlier override dependencies of containers attached later.
Note that containers attached earlier override dependencies of containers attached later.

```php
use Yiisoft\Di\CompositeContainer;
Expand Down Expand Up @@ -216,7 +216,7 @@ services or groups of dependencies for the container and extensions of existing

A provider should extend from `Yiisoft\Di\ServiceProviderInterface` and must
contain a `getDefinitions()` and `getExtensions()` methods. It should only provide services for the container
and therefore should only contain code that's related to this task. It should *never*
and therefore should only contain code related to this task. It should *never*
implement any business logic or other functionality such as environment bootstrap or applying changes to a database.

A typical service provider could look like:
Expand Down Expand Up @@ -354,8 +354,8 @@ $resetter->setResetters([
]);
```

The callback has access to the private and protected properties of the service instance, so you can set initial state
of the service efficiently without creating a new instance.
The callback has access to the private and protected properties of the service instance,
so you can set the initial state of the service efficiently without creating a new instance.

You should trigger the reset itself after each request-response cycle. For RoadRunner, it would look like the following:

Expand Down
6 changes: 3 additions & 3 deletions src/BuildingException.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
use Throwable;

/**
* It wraps all exceptions which do not implement ContainerExceptionInterface while building process.
* It wraps all exceptions that don't implement `ContainerExceptionInterface` during the build process.
* Also adds building context for more understanding.
*/
final class BuildingException extends Exception implements ContainerExceptionInterface
{
/**
* @param string $id ID of the definition or name of the class that was not found.
* @param string[] $buildStack Stack of IDs of services requested definition or class that was not found.
* @param string $id ID of the definition or name of the class that wasn't found.
* @param string[] $buildStack Stack of IDs of services requested definition or class that wasn't found.
*/
public function __construct(
string $id,
Expand Down
8 changes: 4 additions & 4 deletions src/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public function has(string $id): bool
/**
* Returns an instance by either interface name or alias.
*
* Same instance of the class will be returned each time this method is called.
* The Same instance of the class will be returned each time this method is called.
*
* @param string $id The interface or an alias name that was previously registered.
*
Expand Down Expand Up @@ -256,8 +256,8 @@ private function addDefinitions(array $config): void
/**
* Set container delegates.
*
* Each delegate must is a callable in format "function (ContainerInterface $container): ContainerInterface".
* The container instance returned is used in case a service can not be found in primary container.
* Each delegate must be a callable in format `function (ContainerInterface $container): ContainerInterface`.
* The container instance returned is used in case a service can't be found in primary container.
*
* @throws InvalidConfigException
*/
Expand Down Expand Up @@ -474,7 +474,7 @@ private function addDefinitionToStorage(string $id, $definition): void
* @throws NotFoundExceptionInterface
* @throws CircularReferenceException
*
* @return mixed|object New built instance of the specified class.
* @return mixed|object New-built instance of the specified class.
*
* @internal
*/
Expand Down
2 changes: 1 addition & 1 deletion src/ContainerConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public function shouldValidate(): bool
/**
* @param array $delegates Container delegates. Each delegate is a callable in format
* `function (ContainerInterface $container): ContainerInterface`. The container instance returned is used
* in case a service can not be found in primary container.
* in case a service can't be found in primary container.
*/
public function withDelegates(array $delegates): self
{
Expand Down
2 changes: 1 addition & 1 deletion src/ContainerConfigInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function shouldValidate(): bool;
/**
* @return array Container delegates. Each delegate is a callable in format
* `function (ContainerInterface $container): ContainerInterface`. The container instance returned is used
* in case a service can not be found in primary container.
* in case a service can't be found in primary container.
*/
public function getDelegates(): array;

Expand Down
4 changes: 2 additions & 2 deletions src/ExtensibleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

/**
* @internal A wrapper for a service definition that allows registering extensions.
* An extension is a callable that returns a modified service object:
* An extension is callable that returns a modified service object:
*
* ```php
* static function (ContainerInterface $container, $service) {
Expand All @@ -37,7 +37,7 @@ public function __construct(
/**
* Add an extension.
*
* An extension is a callable that returns a modified service object:
* An extension is callable that returns a modified service object:
*
* ```php
* static function (ContainerInterface $container, $service) {
Expand Down
2 changes: 1 addition & 1 deletion src/Helpers/DefinitionParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ final class DefinitionParser
/**
* @param mixed $definition Definition to parse.
*
* @return array Definition parsed into array of a special structure.
* @return array Definition parsed into an array of a special structure.
* @psalm-return array{mixed,array}
*/
public static function parse(mixed $definition): array
Expand Down
2 changes: 1 addition & 1 deletion src/Reference/TagReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Yiisoft\Definitions\Reference;

/**
* TagReference is a helper class that is used to specify a reference to a tag.
* TagReference is a helper class used to specify a reference to a tag.
* For example, `TagReference::to('my-tag')` specifies a reference to all services that are tagged with `tag@my-tag`.
*/
final class TagReference
Expand Down
8 changes: 4 additions & 4 deletions src/ServiceProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* The goal of service providers is to centralize and organize in one place
* registration of classes bound by any logic or classes with complex dependencies.
*
* You can simply organize registration of a service and its dependencies in a single
* provider class except of creating bootstrap file or configuration array for the Container.
* You can organize registration of a service and its dependencies in a single
* provider class except for creating a bootstrap file or configuration array for the Container.
*
* Example:
*
Expand All @@ -21,7 +21,7 @@
* public function getDefinitions(): array
* {
* return [
* 'car' => ['class' => Car::class],
* 'car' => ['class' => Car::class],
* 'car-factory' => CarFactory::class,
* EngineInterface::class => EngineMarkOne::class,
* ];
Expand All @@ -47,7 +47,7 @@ public function getDefinitions(): array;
/**
* Returns an array of service extensions.
*
* An extension is a callable that returns a modified service object:
* An extension is callable that returns a modified service object:
*
* ```php
* static function (ContainerInterface $container, $service) {
Expand Down
2 changes: 1 addition & 1 deletion src/StateResetter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function reset(): void

/**
* @param Closure[]|self[] $resetters Array of reset callbacks. Each callback has access to the private and
* protected properties of the service instance, so you can set initial state of the service efficiently
* protected properties of the service instance, so you can set the initial state of the service efficiently
* without creating a new instance.
*/
public function setResetters(array $resetters): void
Expand Down
4 changes: 2 additions & 2 deletions tests/Benchmark/ContainerBench.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function provideDefinitions(): array

/**
* Load the bulk of the definitions.
* These all refer to a service that is not yet defined but must be defined in the bench.
* These all refer to a service that is not yet defined but must be defined in the benchmark.
*/
public function before(): void
{
Expand All @@ -76,7 +76,7 @@ public function before(): void
shuffle($this->randomIndexes);

$this->composite = new CompositeContainer();
// We attach the dummy containers multiple times, to see what would happen if we have lots of them.
// Attach the dummy containers multiple times, to see what would happen if there are lots of them.
$this->composite->attach(
new Container(
ContainerConfig::create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Psr\Container\ContainerInterface;

class InvokeableCarFactory
class InvokableCarFactory
{
public function __invoke(ContainerInterface $container): Car
{
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
use Yiisoft\Di\Tests\Support\EngineMarkTwo;
use Yiisoft\Di\Tests\Support\EngineStorage;
use Yiisoft\Di\Tests\Support\Garage;
use Yiisoft\Di\Tests\Support\InvokeableCarFactory;
use Yiisoft\Di\Tests\Support\InvokableCarFactory;
use Yiisoft\Di\Tests\Support\MethodTestClass;
use Yiisoft\Di\Tests\Support\NullableConcreteDependency;
use Yiisoft\Di\Tests\Support\OptionalConcreteDependency;
Expand Down Expand Up @@ -802,7 +802,7 @@ public function testInvokeable(): void
$config = ContainerConfig::create()
->withDefinitions([
'engine' => EngineMarkOne::class,
'invokeable' => new InvokeableCarFactory(),
'invokeable' => new InvokableCarFactory(),
]);
$container = new Container($config);

Expand Down Expand Up @@ -1603,7 +1603,7 @@ public function testCircularReferenceExceptionWhileResolvingProviders(): void
public function getDefinitions(): array
{
return [
// E.g. wrapping container with proxy class
// wrapping container with proxy class
ContainerInterface::class => static fn (ContainerInterface $container) => $container,
];
}
Expand Down

0 comments on commit 0cc415a

Please sign in to comment.