Skip to content

Commit

Permalink
Merge pull request #45 from johnzuk/feature/architecture-upgrade
Browse files Browse the repository at this point in the history
Feature/architecture upgrade
  • Loading branch information
Janusz Żukowicz authored May 10, 2018
2 parents 0ae557e + 5f7464a commit 4a36d1f
Show file tree
Hide file tree
Showing 70 changed files with 2,983 additions and 840 deletions.
1 change: 1 addition & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@ return PhpCsFixer\Config::create()
'phpdoc_no_package' => false,
'phpdoc_order' => true,
'phpdoc_align' => true,
'ordered_imports' => true,
])
->setFinder($finder);
5 changes: 5 additions & 0 deletions .styleci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
preset: recommended

disabled:
- align_double_arrow
- no_multiline_whitespace_before_semicolons
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@ install:

script:
- composer validate --strict
- vendor/bin/phpstan analyze -c phpstan.neon -l max src
- vendor/bin/phpcs src
- vendor/bin/phpunit
- vendor/bin/phpunit --coverage-clover=coverage.xml

after_success:
- bash <(curl -s https://codecov.io/bash)
64 changes: 34 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,64 +4,68 @@ PHP GUS API library
[![Build Status](https://travis-ci.org/johnzuk/GusApi.svg?branch=master)](https://travis-ci.org/johnzuk/GusApi)
[![Packagist](https://img.shields.io/packagist/v/gusapi/gusapi.svg)](https://packagist.org/packages/gusapi/gusapi)
[![Packagist](https://img.shields.io/packagist/dt/gusapi/gusapi.svg)](https://packagist.org/packages/gusapi/gusapi)
[![StyleCI](https://styleci.io/repos/30836493/shield?branch=master)](https://styleci.io/repos/30836493)

PHP GUS API is an object-oriented library to get information from [REGON site](https://wyszukiwarkaregon.stat.gov.pl/wsBIR/UslugaBIRzewnPubl.svc) based on **official** REGON SOAP API.
Official GUS docs [here](http://bip.stat.gov.pl/dzialalnosc-statystyki-publicznej/rejestr-regon/interfejsyapi/jak-skorzystac-informacja-dla-podmiotow-komercyjnych/).

Installation
======================
This library uses [Composer](https://packagist.org/packages/gusapi/gusapi), just type in:
```composer require gusapi/gusapi```
```bash
composer require gusapi/gusapi
```

Supported Versions
==================
|Version|PHP version |Support | Doc |
|-------|------------|----------------------------------|------|
|4.x | >= 7.1 | Support ends on December 1, 2019 | [Doc](https://github.com/johnzuk/GusApi/blob/master/README.md)|
|3.3.x | >= 5.6 | Support ends on December 1, 2018 | [Doc](https://github.com/johnzuk/GusApi/blob/3.3/README.md) |
|3.2.x | >= 5.4 | Support ended on April 1, 2018 | [Doc](https://github.com/johnzuk/GusApi/blob/3.2/README.md) |

If you use PHP <= 7.0 see documentation for 3.3.x version [HERE](https://github.com/johnzuk/GusApi/blob/3.3/README.md)
-------------------

Upgrade from 3.x to 4.x
=========================
For more information see [UPGRADE.md](UPGRADE.md).


Example
Example for 4.x
======================
See file [examples/getFromNip.php](examples/getFromNip.php).
See file [examples/readmeExample.php](examples/readmeExample.php).

```php
require_once '../vendor/autoload.php';

use GusApi\GusApi;
use GusApi\RegonConstantsInterface;
use GusApi\Exception\InvalidUserKeyException;
use GusApi\GusApi;
use GusApi\ReportTypes;
use GusApi\ReportTypeMapper;

$gus = new GusApi(
'abcde12345abcde12345', // your user key / twój klucz użytkownika
new \GusApi\Adapter\Soap\SoapAdapter(
RegonConstantsInterface::BASE_WSDL_URL,
RegonConstantsInterface::BASE_WSDL_ADDRESS // production server / serwer produkcyjny
//for test server use RegonConstantsInterface::BASE_WSDL_ADDRESS_TEST
//w przypadku serwera testowego użyj: RegonConstantsInterface::BASE_WSDL_ADDRESS_TEST
)
);

$mapper = new ReportTypeMapper();
$gus = new GusApi('your api key here');
//for development server use:
//$gus = new GusApi('abcde12345abcde12345', 'dev');

try {
$nipToCheck = 'xxxxxxxxxx'; //change to valid nip value
$sessionId = $gus->login();

$gusReports = $gus->getByNip($sessionId, $nipToCheck);

foreach ($gusReports as $gusReport) {
$reportType = $mapper->getReportType($gusReport);
$gus->login();

var_dump($gus->getFullReport(
$sessionId,
$gusReport,
$reportType
));
$gusReports = $gus->getByNip($nipToCheck);

foreach ($gusReports as $gusReport) {
//you can change report type to other one
$reportType = ReportTypes::REPORT_PUBLIC_LAW;
echo $gusReport->getName();
$fullReport = $gus->getFullReport($gusReport, $reportType);
var_dump($fullReport);
}

} catch (InvalidUserKeyException $e) {
echo 'Bad user key';
} catch (\GusApi\Exception\NotFoundException $e) {
echo 'No data found <br>';
echo 'For more information read server message below: <br>';
echo $gus->getResultSearchMessage($sessionId);
echo $gus->getResultSearchMessage();
}

```
Expand Down
50 changes: 50 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# UPGRADE FROM 3.x to 4.0

Installation
------------
Before upgrading this package make sure you are using [PHP 7.1](http://php.net/migration71) or newer as it is required to run version 4.0 of this library.

To upgrade, simply run:
```bash
composer require gusapi/gusapi ^4.0
```

Creating the client
-------------------
Before:
```php
$gus = new GusApi(
'abcde12345abcde12345',
new \GusApi\Adapter\Soap\SoapAdapter(
RegonConstantsInterface::BASE_WSDL_URL,
RegonConstantsInterface::BASE_WSDL_ADDRESS
)
);
```

After:
```php
$gus = new GusApi(
'abcde12345abcde12345',
'prod' // or 'dev'
);
```

Calling API methods
-------------------
The GusApi class now handles the session so you don't need to pass SID to every method.

Before:
```php
$sessionId = $gus->login(); // returns SID on success
$gusReports = $gus->getByNip($sessionId, '7740001454');
```

After:
```php
$loggedIn = $gus->login(); // returns true on success
$gusReports = $gus->getByNip('7740001454');

// You can still fetch SID by calling:
$sessionId = $gus->getSessionId();
```
90 changes: 0 additions & 90 deletions examples/getFromNip.php

This file was deleted.

32 changes: 32 additions & 0 deletions examples/readmeExample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

require_once '../vendor/autoload.php';

use GusApi\Exception\InvalidUserKeyException;
use GusApi\GusApi;
use GusApi\ReportTypes;

$gus = new GusApi('your api key here');
//for development server use:
//$gus = new GusApi('abcde12345abcde12345', 'dev');

try {
$nipToCheck = 'xxxxxxxxxx'; //change to valid nip value
$gus->login();

$gusReports = $gus->getByNip($nipToCheck);

foreach ($gusReports as $gusReport) {
//you can change report type to other one
$reportType = ReportTypes::REPORT_PUBLIC_LAW;
echo $gusReport->getName();
$fullReport = $gus->getFullReport($gusReport, $reportType);
var_dump($fullReport);
}
} catch (InvalidUserKeyException $e) {
echo 'Bad user key';
} catch (\GusApi\Exception\NotFoundException $e) {
echo 'No data found <br>';
echo 'For more information read server message below: <br>';
echo $gus->getResultSearchMessage();
}
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
ignoreErrors:
- '#stream_context_set_option invoked with 2 parameters, 4#'
- '#GusApi\\Client\\SoapClient does not have a constructor#'
66 changes: 0 additions & 66 deletions src/GusApi/Adapter/AdapterInterface.php

This file was deleted.

7 changes: 0 additions & 7 deletions src/GusApi/Adapter/Soap/Exception/NoDataException.php

This file was deleted.

Loading

0 comments on commit 4a36d1f

Please sign in to comment.