Skip to content

Commit 18c9cb3

Browse files
committed
fix Laravel Service Provider, rename InvalidDatabaseException, update example
1 parent c4074d8 commit 18c9cb3

File tree

5 files changed

+20
-14
lines changed

5 files changed

+20
-14
lines changed

examples/example.php

+9-3
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@
44

55
use ZerosDev\NikReader\Reader;
66

7-
$nik = '3502200101200001';
7+
$nik = '3502200101040001';
88

99
$reader = new Reader();
1010

11-
$result = $reader->read($nik)->toArray();
11+
$result = $reader->read($nik);
12+
$province = $result->getProvince();
13+
$city = $result->getCity();
14+
$subdistrict = $result->getSubdistrict();
15+
// ..........
1216

13-
print_r($result);
17+
$json = $reader->toJSON();
18+
19+
print_r($json);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?php
2+
3+
namespace ZerosDev\NikReader\Exceptions;
4+
5+
class InvalidDatabaseException extends NikReaderException
6+
{
7+
// ..
8+
}

src/Exceptions/InvalidDatabaseWilayahException.php

-8
This file was deleted.

src/Laravel/ServiceProvider.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class ServiceProvider extends LaravelServiceProvider implements DeferrableProvid
1616
public function register()
1717
{
1818
$this->app->singleton(Reader::class, function ($app) {
19-
return (new Reader(config('nik_reader')));
19+
return new Reader();
2020
});
2121
}
2222

src/Reader.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function read(string $nik = null)
101101
public function setDatabase(string $file)
102102
{
103103
if (! is_file($file) || ! is_readable($file)) {
104-
throw new Exceptions\InvalidDatabaseWilayahException(sprintf(
104+
throw new Exceptions\InvalidDatabaseException(sprintf(
105105
'The database file cannot be found or not readable: %s',
106106
$file
107107
));
@@ -112,7 +112,7 @@ public function setDatabase(string $file)
112112
$database = json_decode($database);
113113

114114
if (json_last_error() !== JSON_ERROR_NONE) {
115-
throw new Exceptions\InvalidDatabaseWilayahException(sprintf(
115+
throw new Exceptions\InvalidDatabaseException(sprintf(
116116
'Unable to decode database contents: %s',
117117
$file
118118
));

0 commit comments

Comments
 (0)