Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ipTraceable ipValue is required
  • Loading branch information
mabar authored and f3l1x committed Dec 3, 2019
1 parent bc5a6d8 commit edefd1f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
11 changes: 11 additions & 0 deletions .docs/README.md
Expand Up @@ -8,6 +8,7 @@ Doctrine ([Atlantic18/DoctrineExtensions](https://github.com/Atlantic18/Doctrine
- [Configuration](#configuration)
- [Loggable, Translatable, Treeable](#loggable-translatable-treeable)
- [Translatable](#translatable)
- [IpTraceable](#iptraceable)

## Setup

Expand Down Expand Up @@ -85,3 +86,13 @@ nettrine.extensions.atlantic18:
persistDefaultTranslation: off
skipOnLoad: off
```

### [IpTraceable](https://github.com/Atlantic18/DoctrineExtensions/blob/v2.4.x/doc/ip_traceable.md)

IpTraceable requires client IP address:

```
nettrine.extensions.atlantic18:
ipTraceable:
ipValue: @Nette\Http\IRequest::getRemoteAddress()
```
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -20,7 +20,8 @@ Doctrine ([Atlantic18/DoctrineExtensions](https://github.com/Atlantic18/Doctrine
- [Configuration](.docs/README.md#configuration)
- [Loggable, Translatable, Treeable](.docs/README.md#loggable-translatable-treeable)
- [Translatable](.docs/README.md#translatable)

- [IpTraceable](.docs/README.md##iptraceable)

## Versions

| State | Version | Branch | Nette | PHP |
Expand Down
9 changes: 6 additions & 3 deletions src/DI/Atlantic18BehaviorExtension.php
Expand Up @@ -13,6 +13,7 @@
use Gedmo\Translatable\TranslatableListener;
use Gedmo\Tree\TreeListener;
use Nette\DI\CompilerExtension;
use Nette\DI\Definitions\Statement;
use Nette\Schema\Expect;
use Nette\Schema\Schema;
use stdClass;
Expand Down Expand Up @@ -43,7 +44,9 @@ public function getConfigSchema(): Schema
]))->default(false),
'uploadable' => Expect::bool(false),
'sortable' => Expect::bool(false),
'ipTraceable' => Expect::bool(false),
'ipTraceable' => Expect::anyOf(false, Expect::structure([
'ipValue' => Expect::anyOf(Expect::string(), Expect::array(), Expect::type(Statement::class))->required(),
]))->default(false),
]);
}

Expand Down Expand Up @@ -132,11 +135,11 @@ public function loadConfiguration(): void

// IpTraceable ===============================================

if ($config->ipTraceable) {
if ($config->ipTraceable !== false) {
$builder->addDefinition($this->prefix('ipTraceable'))
->setFactory(IpTraceableListener::class)
->addSetup('setAnnotationReader', ['@' . Reader::class])
->addSetup('setIpValue', !empty($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : null)
->addSetup('setIpValue', $config->ipTraceable->ipValue)
->addTag(self::TAG_NETTRINE_SUBSCRIBER);
}
}
Expand Down

0 comments on commit edefd1f

Please sign in to comment.