Skip to content

Commit

Permalink
add support for dot notation
Browse files Browse the repository at this point in the history
  • Loading branch information
michele-widesrl committed Dec 7, 2022
1 parent d64fa0f commit 7865b05
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

All notable changes to `laravel-codice-fiscale` will be documented in this file

## 1.0.0 - 201X-XX-XX
## 0.1.0 - 2020-07-06

- initial release

## 0.1.7 - 2022-10-06

- Update LaravelCodiceFiscale.php

## 0.1.9 - 2022-10-13

- fix publish tags
- configurable impossible-to-match

## 0.1.10 - 2022-12-07

- add support for dot notation
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ publish lang
php artisan vendor:publish --provider "IvanoMatteo\LaravelCodiceFiscale\LaravelCodiceFiscaleServiceProvider" --tag lang

php artisan vendor:publish --provider "IvanoMatteo\LaravelCodiceFiscale\LaravelCodiceFiscaleServiceProvider" --tag config

```

``` php
Expand Down Expand Up @@ -96,4 +95,4 @@ The MIT License (MIT). Please see [License File](LICENSE.md) for more informatio

## Laravel Package Boilerplate

This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).
This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"scripts": {
"test": "vendor/bin/phpunit",
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"

},
"config": {
"sort-packages": true
Expand Down
5 changes: 0 additions & 5 deletions resources/lang/en/codfisc.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
<?php





return [

'field-do-not-match' => 'do not match with fiscal code',
'do-not-match' => 'do not match',
'name' => 'Name',
Expand Down
13 changes: 4 additions & 9 deletions src/LaravelCodiceFiscale.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,12 @@

namespace IvanoMatteo\LaravelCodiceFiscale;

use DateTime;
use Illuminate\Support\Arr;
use IvanoMatteo\CodiceFiscale\CodiceFiscale;
use IvanoMatteo\CodiceFiscale\CodicefiscaleException;


class LaravelCodiceFiscale
{

private $cache = [];

private $filedNames = [
Expand Down Expand Up @@ -45,11 +43,8 @@ private function parse($cf_str)
return $this->cache[$cf_str];
}



public function registerValidator()
{

\Validator::extend('codfisc', function ($attribute, $value, $parameters, $validator) {

//dd($attribute);
Expand All @@ -61,7 +56,6 @@ public function registerValidator()
$msg = null;

$map = []; // create parameters map

foreach ($parameters as $i => $p) {
if ($i === 0 && strpos($p, '=') === false) {
$codfisc = $p;
Expand All @@ -87,8 +81,9 @@ public function registerValidator()

// get request data
$reqData = $validator->getData();
$reqData = Arr::dot($reqData);

$cf = $this->parse($codfisc ? $reqData[$codfisc] : $value);
$cf = $this->parse($codfisc ? Arr::get($reqData, $codfisc) : $value);

if (!isset($cf['err'])) {
$cf = $cf['cf'];
Expand Down Expand Up @@ -143,8 +138,8 @@ function ($message, $attribute, $rule, $parameters) use ($msg) {
);
return false;
}

return true;

}, ':attribute :cf_error');
}
}

0 comments on commit 7865b05

Please sign in to comment.