Skip to content

Commit

Permalink
updated documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
bidi47 committed Apr 8, 2024
1 parent 325fe1f commit a33f329
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 7 deletions.
37 changes: 35 additions & 2 deletions docs/book/v5/usage/factory.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ class ExampleFactory
}
```

Register the factory in any mode you register factories on your project.

## Step 2: Access through your Service

```php
Expand All @@ -34,3 +32,38 @@ class ExampleService
//your methods
}
```

## Step 3: Register the factory

Open the ConfigProvider of the module where your repository resides.

Add a new entry under `factories`, where the key is your service's FQCN and the value is your factory's FQCN.

See below example for a better understanding of the file structure.

```php
<?php

declare(strict_types=1);

namespace YourApp;

class ConfigProvider
{
public function __invoke(): array
{
return [
'dependencies' => $this->getDependencies(),
];
}

public function getDependencies(): array
{
return [
'factories' => [
ExampleService::class => ExampleFactory::class,
],
];
}
}
```
47 changes: 42 additions & 5 deletions docs/book/v5/usage/injection.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# Method #2 - Injection

If you use annotated injection you can inject the Session Manager in your services.
If you are using [dot-annotated-services](https://github.com/dotkernel/dot-annotated-services/) in your project, you don't need to create a separate factory, just follow the below steps.

## Step 1: Access through your Service

```php
use Dot\AnnotatedServices\Annotation\Inject;
use Laminas\Session\SessionManager;

class ExampleService
{
private SessionManager $session;

/**
* @Inject({SessionManager::class})
/**
* @Dot\AnnotatedServices\Annotation\Inject({
* SessionManager::class,
* })
*/
public function __construct(SessionManager $session)
{
Expand All @@ -21,3 +23,38 @@ class ExampleService
//your methods
}
```

## Step 2: Register your service

Open the ConfigProvider of the module where your repository resides.

Add a new entry under `factories`, where the key is your service's FQCN and the value is `Dot\AnnotatedServices\Factory\AbstractAnnotatedFactory`.

See below example for a better understanding of the file structure.

```php
<?php

declare(strict_types=1);

namespace YourApp;

class ConfigProvider
{
public function __invoke(): array
{
return [
'dependencies' => $this->getDependencies(),
];
}

public function getDependencies(): array
{
return [
'factories' => [
ExampleService::class => AbstractAnnotatedFactory::class,
],
];
}
}
```

0 comments on commit a33f329

Please sign in to comment.