Skip to content

Commit e9fbc7e

Browse files
committed
Methods documentation.
1 parent 196d85b commit e9fbc7e

20 files changed

Lines changed: 1019 additions & 152 deletions

AGENTS.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Project Guide — ebics-client-php
2+
3+
## Overview
4+
5+
PHP library to communicate with banks through the **EBICS** protocol (Electronic Banking Internet Communication Standard).
6+
Supports EBICS versions 2.4, 2.5, 3.0 and signature/encryption variants E002, X002, A005, A006.
7+
8+
## Technology Stack
9+
10+
| Item | Version |
11+
|------|---------|
12+
| **PHP** | 8.5+ (`^8.5`) |
13+
| **PHPUnit** | ~10.5 |
14+
| **PHPStan** | ~2.1 |
15+
| **PHPCS** | ~3.13 (PSR-12) |
16+
| **Composer** | latest |
17+
18+
### Required PHP Extensions
19+
20+
`bcmath`, `curl`, `dom`, `json`, `openssl`, `zip`, `zlib`, `libxml`
21+
22+
## Docker Environment
23+
24+
The project uses Docker for a consistent development environment.
25+
26+
```
27+
docker/
28+
├── docker-compose.yml
29+
└── php-cli/
30+
├── Dockerfile (php:8.5.4-cli + xdebug + extensions)
31+
└── php.ini
32+
```
33+
34+
### Docker Compose
35+
36+
| Target | Image | Container Name |
37+
|--------|-------|----------------|
38+
| `php-cli-ebics-client-php` | `php-cli-ebics-client-php:8.5.4-cli` | `php-cli-ebics-client-php` |
39+
40+
Network mode: **host** (for easy access to local services).
41+
Xdebug is pre-installed and enabled (port 9003).
42+
43+
### Makefile Targets
44+
45+
| Command | Alias | Description |
46+
|---------|-------|-------------|
47+
| `make docker-up` | `u`, `start` | Start Docker containers |
48+
| `make docker-down` | `d`, `stop` | Stop Docker containers |
49+
| `make docker-build` | `build` | Rebuild Docker images |
50+
| `make docker-install` | `install` | Run `composer install` in container |
51+
| `make docker-php` | `php` | Open a bash shell in the PHP container |
52+
| `make check` || Run PHPCBF, PHPCS, PHPStan, PHPUnit |
53+
| `make credentials-pack` || Zip test credentials |
54+
| `make credentials-unpack` || Unzip test credentials |
55+
56+
### Composer Scripts (run inside Docker)
57+
58+
| Command | Description |
59+
|---------|-------------|
60+
| `composer code-test` | Run PHPUnit tests |
61+
| `composer code-style` | Run PHPCS |
62+
| `composer code-analyse` | Run PHPStan |
63+
64+
## Directory Structure
65+
66+
```
67+
├── src/ # PSR-4: EbicsApi\Ebics\
68+
│ ├── Contracts/ # Interfaces
69+
│ ├── Exceptions/ # Custom exception classes
70+
│ ├── Factories/ # Factory classes (Crypt, Signature, etc.)
71+
│ ├── Models/ # Data models (Key, KeyPair, Keyring, Buffer, etc.)
72+
│ ├── Services/ # Business logic services
73+
│ └── EbicsClient.php # Main client entry point
74+
├── tests/ # PSR-4: EbicsApi\Ebics\Tests\
75+
│ ├── _data/ # Test data & keyring files
76+
│ ├── _fixtures/ # Test fixtures (XML files, keys)
77+
│ ├── _workspace/ # Generated test artifacts
78+
│ └── AbstractEbicsTestCase.php # Base test class with helpers
79+
├── doc/schema/ # EBICS XSD schemas
80+
└── docker/ # Docker configuration
81+
```
82+
83+
## Coding Standards
84+
85+
- **PSR-12** coding style (enforced by PHPCS).
86+
- **PHPStan** level enforced via `phpstan.neon`.
87+
- Source code lives in `src/`; tests live in `tests/`.
88+
- PHPCS targets `src/` only (tests excluded in `phpcs.xml`).
89+
- Tests may use snake_case method names where needed (PHPCS exclusion).
90+
91+
## Running Commands
92+
93+
All commands execute **inside Docker**:
94+
95+
```bash
96+
# Start environment
97+
make docker-up
98+
99+
# Run full quality check
100+
make check
101+
102+
# Or individually:
103+
docker compose -p ebics-client-php exec php-cli-ebics-client-php ./vendor/bin/phpunit
104+
docker compose -p ebics-client-php exec php-cli-ebics-client-php ./vendor/bin/phpcs
105+
docker compose -p ebics-client-php exec php-cli-ebics-client-php ./vendor/bin/phpstan
106+
107+
# Open shell
108+
make docker-php
109+
```
110+
111+
## Testing Conventions
112+
113+
- Base class: `AbstractEbicsTestCase` (provides client setup, keyring, credentials).
114+
- Test groups (PHPUnit `@group`): e.g. `@group crypt-services`.
115+
- Credentials stored in `tests/_data/credentials/credentials_<id>.json`.
116+
- Keyrings stored in `tests/_data/workspace/keyring_<id>.json`.
117+
- Fixtures (static XML/JSON) in `tests/_fixtures/`.
118+
119+
### Client Setup Helpers
120+
121+
```php
122+
// In any test extending AbstractEbicsTestCase:
123+
$client = $this->setupClientV24($credentialsId); // EBICS 2.4
124+
$client = $this->setupClientV25($credentialsId); // EBICS 2.5
125+
$client = $this->setupClientV30($credentialsId); // EBICS 3.0
126+
```
127+
128+
### Fake / Debug HTTP Clients
129+
130+
Pass `$fake = true` or `$debug = true` to `setupClient*()` to use `FakerHttpClient` (returns fixture data) or `DebuggerHttpClient` (logs requests).
131+
132+
## Key Concepts
133+
134+
| Concept | Description |
135+
|---------|-------------|
136+
| **Keyring** | Holds user & bank signatures (A = authentication, X = signing, E = encryption), passwords, and optional X.509 certificates. |
137+
| **Signature A** | Authentication signature (versions A005 / A006). |
138+
| **Signature X** | Transaction signing (version X002). |
139+
| **Signature E** | Encryption (version E002). |
140+
| **CryptService** | All crypto ops: hashing, AES-128-CBC encrypt/decrypt, RSA sign/encrypt, key generation, nonces, order IDs. |
141+
| **KeyPair** | Public key + private key + password bundle. |
142+
143+
## Notable Implementation Details
144+
145+
- Classes marked `@internal` may change without notice.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## 3.1
22

3+
* Documentation detailization.
34
* Safety improvements.
45

56
## 3.0

phpunit.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
bootstrap="tests/bootstrap.php"
55
colors="true"
66
beStrictAboutOutputDuringTests="true"
7-
cacheResult="false">
7+
cacheResult="false"
8+
failOnDeprecation="true">
89
<source>
910
<include>
1011
<directory>src</directory>

src/Contracts/SignatureInterface.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,54 @@
55
use EbicsApi\Ebics\Models\Crypt\Key;
66

77
/**
8-
* EBICS SignatureInterface representation.
8+
* EBICS Signature interface.
9+
*
10+
* Represents a cryptographic signature used in EBICS protocol communication.
11+
* Each signature type serves a specific role:
12+
*
13+
* - **Type A** (Authentication): Authenticates the user to the bank.
14+
* Versions: `A005` (RSA-PKCS#1 v1.5), `A006` (RSA-PSS).
15+
* - **Type X** (Signing): Signs transaction data. Version: `X002`.
16+
* - **Type E** (Encryption): Encrypts data transfer. Version: `E002`.
917
*
1018
* @license http://www.opensource.org/licenses/mit-license.html MIT License
1119
* @author Andrew Svirin
1220
*/
1321
interface SignatureInterface
1422
{
23+
/**
24+
* Authentication signature version 5 (RSA-PKCS#1 v1.5 with SHA-256).
25+
*/
1526
const A_VERSION5 = 'A005';
27+
28+
/**
29+
* Authentication signature version 6 (RSA-PSS with SHA-256).
30+
*/
1631
const A_VERSION6 = 'A006';
1732

33+
/**
34+
* Encryption signature version 2.
35+
*/
1836
const E_VERSION2 = 'E002';
37+
38+
/**
39+
* Transaction signing signature version 2.
40+
*/
1941
const X_VERSION2 = 'X002';
2042

43+
/**
44+
* Authentication signature type identifier.
45+
*/
2146
const TYPE_A = 'A';
47+
48+
/**
49+
* Transaction signing signature type identifier.
50+
*/
2251
const TYPE_X = 'X';
52+
53+
/**
54+
* Encryption signature type identifier.
55+
*/
2356
const TYPE_E = 'E';
2457

2558
/**

src/Factories/Crypt/AESFactory.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
use EbicsApi\Ebics\Models\Crypt\AES;
77

88
/**
9-
* Class AESFactory represents producers for the @see AES.
9+
* AES factory for creating AES cryptographic instances.
10+
*
11+
* Produces `AESInterface` instances used for symmetric encryption/decryption
12+
* (typically AES-128-CBC) in EBICS data transfer pipelines.
1013
*
1114
* @license http://www.opensource.org/licenses/mit-license.html MIT License
1215
* @author Andrew Svirin

src/Factories/Crypt/RSAFactory.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
use EbicsApi\Ebics\Models\Crypt\RSA;
99

1010
/**
11-
* Class RSAFactory represents producers for the @see RSA.
11+
* RSA factory for creating RSA cryptographic instances.
12+
*
13+
* Produces `RSAInterface` instances configured as private or public keys.
14+
* Decouples the concrete RSA implementation from business logic, allowing
15+
* different underlying libraries to be swapped via the class map.
1216
*
1317
* @license http://www.opensource.org/licenses/mit-license.html MIT License
1418
* @author Andrew Svirin
@@ -32,7 +36,9 @@ public function __construct(?array $classMap = null)
3236
}
3337

3438
/**
35-
* @param int $type
39+
* Create an RSA instance by key type identifier.
40+
*
41+
* @param int $type Key type constant (e.g. RSA::PRIVATE_FORMAT_PKCS1).
3642
* @return RSAInterface
3743
*/
3844
public function create(int $type): RSAInterface

src/Models/Buffer.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
use RuntimeException;
77

88
/**
9-
* Buffer class.
9+
* Buffer wraps a file stream for chunked read/write operations.
10+
*
11+
* This model provides a stream-based buffer abstraction used throughout
12+
* encryption/decryption pipelines. It supports opening files, reading/writing
13+
* data in chunks, seeking, and applying stream filters. The buffer tracks
14+
* remaining length and automatically closes the stream on destruction.
1015
*
1116
* @license http://www.opensource.org/licenses/mit-license.html MIT License
1217
* @author Andrew Svirin

src/Models/Crypt/ASN1.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,7 @@ public function asn1map($decoded, $mapping, $special = [])
665665
continue;
666666
}
667667
$maymatch = true;
668+
$candidate = null;
668669
if ($child['type'] != self::TYPE_CHOICE) {
669670
$childClass = self::CLASS_UNIVERSAL;
670671
$constant = null;

src/Models/Crypt/Key.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
namespace EbicsApi\Ebics\Models\Crypt;
44

55
/**
6-
* Key.
6+
* Cryptographic key wrapper.
7+
*
8+
* Holds raw key material (PEM string or binary) and its type identifier
9+
* (e.g. `RSA::PRIVATE_FORMAT_PKCS1`, `RSA::PUBLIC_FORMAT_PKCS1`).
710
*
811
* @license http://www.opensource.org/licenses/mit-license.html MIT License
912
* @author Andrew Svirin

src/Models/Crypt/KeyPair.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
namespace EbicsApi\Ebics\Models\Crypt;
44

55
/**
6-
* Key pair.
6+
* RSA key pair bundle.
7+
*
8+
* Holds a public key, a private key, and the password used to encrypt
9+
* the private key. Used for key generation, storage, and password rotation.
710
*
811
* @license http://www.opensource.org/licenses/mit-license.html MIT License
912
* @author Andrew Svirin

0 commit comments

Comments
 (0)