Skip to content

Commit

Permalink
Docs improvements (#5)
Browse files Browse the repository at this point in the history
* unify syntax in readmes
- use 4 spaces in CSS, in JS, in HTML and in Latte
- use tab in NEON and in PHP
- neon highlighting syntax
- normalized filename of Readmes
- typos
  • Loading branch information
petrparolek authored Mar 11, 2021
1 parent afbd884 commit 300a443
Showing 1 changed file with 41 additions and 41 deletions.
82 changes: 41 additions & 41 deletions .docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Contents

- [Setup](#setup)
- [Configuration](#configuration)
- [Configuration](#configuration)
- [Usage](#usage)

## Setup
Expand All @@ -16,9 +16,9 @@ composer require contributte/validator

Register extension:

```yaml
```neon
extensions:
validator: Contributte\Validator\DI\ValidatorExtension
validator: Contributte\Validator\DI\ValidatorExtension
```

### Configuration
Expand All @@ -31,25 +31,25 @@ The extension tries to provide sane defaults so that in most common cases, it wo

If you're not satisfied with these defaults, you can add or override some of the options:

```yaml
```neon
validator:
# configure various mapping loaders
mapping:
xml: [/path/to/mapping.xml, /path/to/another/mapping.xml]
yaml: [/path/to/mapping.yml, /path/to/another/mapping.yml]
methods: [loadValidatorMetadataMethodName]
# use a different mapping cache implementation
cache: Symfony\Component\Cache\Adapter\RedisAdapter(@redis.client)
# configure translator and/or translation domain...
translation:
translator: My\Translator
domain: validator
# ...or disable translation entirely
translation:
translator: false
# configure various mapping loaders
mapping:
xml: [/path/to/mapping.xml, /path/to/another/mapping.xml]
yaml: [/path/to/mapping.yml, /path/to/another/mapping.yml]
methods: [loadValidatorMetadataMethodName]
# use a different mapping cache implementation
cache: Symfony\Component\Cache\Adapter\RedisAdapter(@redis.client)
# configure translator and/or translation domain...
translation:
translator: My\Translator
domain: validator
# ...or disable translation entirely
translation:
translator: false
```

## Usage
Expand All @@ -61,12 +61,12 @@ use Symfony\Component\Validator\Validator\ValidatorInterface;

final class MyServiceThatNeedsToValidateStuff
{
private ValidatorInterface $validator;
private ValidatorInterface $validator;

public function __construct(ValidatorInterface $validator)
{
$this->validator = $validator;
}
public function __construct(ValidatorInterface $validator)
{
$this->validator = $validator;
}
}
```

Expand All @@ -79,20 +79,20 @@ class VatNumber extends \Symfony\Component\Validator\Constraint {}

class VatNumberValidator extends \Symfony\Component\Validator\ConstraintValidator
{
private ViesService $vies;
public function __construct(ViesService $vies) // <-- this dependency is automatically autowired
{
$this->vies = $vies;
}
public function validate($value,\Symfony\Component\Validator\Constraint $constraint)
{
if (!$this->vies->validate($value)) {
$this->context->buildViolation('Value "{{ value }}" is not a valid EU VAT number.')
->setParameter('{{ value }}', $value)
->addViolation();
}
}
private ViesService $vies;

public function __construct(ViesService $vies) // <-- this dependency is automatically autowired
{
$this->vies = $vies;
}

public function validate($value,\Symfony\Component\Validator\Constraint $constraint)
{
if (!$this->vies->validate($value)) {
$this->context->buildViolation('Value "{{ value }}" is not a valid EU VAT number.')
->setParameter('{{ value }}', $value)
->addViolation();
}
}
}
```

0 comments on commit 300a443

Please sign in to comment.