PHPackages                             joaomfrebelo/saft-pt\_4\_php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. joaomfrebelo/saft-pt\_4\_php

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

joaomfrebelo/saft-pt\_4\_php
============================

PHP core lib to work with SAF-T (PT). A library/framework to generate, parse, import and validate programmatically or cli the Portuguese Tax Audit file SAF-T (PT)

2.1.2(3y ago)202138MITPHPPHP 8.0.\* || 8.1.\* || 8.2.\*CI passing

Since Mar 22Pushed 2w ago2 watchersCompare

[ Source](https://github.com/joaomfrebelo/Saft-PT_4_PHP)[ Packagist](https://packagist.org/packages/joaomfrebelo/saft-pt_4_php)[ Docs](https://github.com/joaomfrebelo/saft-pt_4_php)[ RSS](/packages/joaomfrebelo-saft-pt-4-php/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (11)Versions (15)Used By (0)

Rebelo SAFT-PT
==============

[](#rebelo-saft-pt)

---

Rebelo SAFT-PT is a PHP library/framework to lead with the Portuguese tax audit file. The community edition lets to generate, parse, import and validate programmatically or CLI the Portuguese Tax Audit file SAFT-PT. This library also create the digital signature that is impose by law to all invoice, transport documents and working documents issued im Portugal. The enterprise edition also submit the SAFT-PT file to the Portuguese Tax Authority e-fatura web site.

### Install

[](#install)

```
composer require joaomfrebelo/saft-pt_4_php
```

#### Examples

[](#examples)

[https://github.com/joaomfrebelo/Saft-PT\_4\_PHP/tree/master/examples](https://github.com/joaomfrebelo/Saft-PT_4_PHP/tree/master/examples)

#### Legal documentation, portuguse tax law

[](#legal-documentation-portuguse-tax-law)

[https://github.com/joaomfrebelo/Saft-PT\_4\_PHP/tree/master/legal\_documentation](https://github.com/joaomfrebelo/Saft-PT_4_PHP/tree/master/legal_documentation)

Parse and validate a SAFT-PT file:

```
$auditFile = \Rebelo\SaftPt\AuditFile\AuditFile::loadFile("/path/to/file");
$auditFile->validate();
if ($auditFile->getErrorRegistor()->hasErrors()) {
    // Do stuff
} else {
    // read and integrate data to you database ERP
}
```

Create the signature hash

```
$sign = new Rebelo\SaftPt\Sign\Sign();
$sign->setPrivateKey($privatekey);
$hash = $sign->createSignature($docDate, $systemEntryDate, $doc, $grossTotal, $lastHash);
```

Validate the hash signature

```
$sign = new Rebelo\SaftPt\Sign\Sign();
$sign->setPublicKey($publicKey);
$isValid = $sign->verifySignature($hash, $docDate, $systemEntryDate, $doc, $grossTotal, $lastHash);
```

Create a SAFT-PT file

```
$audit = new AuditFile();
$header = $audit->getHeader();
$header->setCompanyID($companyID);
$header->setTaxRegistrationNumber($taxRegistrationNumber);
$header->setTaxAccountingBasis(Rebelo\SaftPt\AuditFile\TaxAccountingBasis::FACTURACAO());
$header->setCompanyName($companyName);
$header->setBusinessName($businessName);
(...)
// Expoert to file
$audit->toFile("/path/to/file");
```

CLI file validation

```
./vendor/bin/saft4php validate -g=en -p=/path/to/Public_Key.txt" -- /path/saft.xml
```

```
./vendor/bin/saft4php validate /path/saft.xml
```

To more options like delta, help

```
./vendor/bin/saft4php validate --help
```

#### [![](img/help.png)](img/help.png)

[](#)

#### Using as stand alone SAFT-PT validator

[](#using-as-stand-alone-saft-pt-validator)

First clone or download the project

```
git clone https://github.com/joaomfrebelo/Saft-PT_4_PHP.git
```

In the project root (php &gt;= 7.4 installed)

```
php saft4php validate /path/saft.xml
```

#### [![](img/validation.png)](img/validation.png)

[](#-1)

#### Some type of validations

[](#some-type-of-validations)

- XML scheme
- Document values
- Total values
- Documents number sequence
- Signature
- Address where are mandatory
- Dates
- And other stuff

#### API documentation

[](#api-documentation)

[https://joaomfrebelo.github.io/Saft-PT\_4\_PHP/](https://joaomfrebelo.github.io/Saft-PT_4_PHP/)

### Professional support:

[](#professional-support)

FeaturesCEEEGenerate SAFTyesyesParse SAFTyesyesCreate hash signatureyesyesValidate file programmaticallyyesyesValidate file CLIyesyesValidate hash signatureyesyesSubmit file to e-faturanoyesCreate XML file in memoryyesyesCreate XML file with StreamWriter to save memorynoyesIntegration with DataSourcenoyesEasy to integrate with Unit testyesyesIntegration with other languages (With midleware)yes### License

[](#license)

MIT License

###  Health Score

48

—

FairBetter than 93% of packages

Maintenance63

Regular maintenance activity

Popularity24

Limited adoption so far

Community13

Small or concentrated contributor base

Maturity77

Established project with proven stability

 Bus Factor1

Top contributor holds 93.3% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~175 days

Recently: every ~329 days

Total

14

Last Release

16d ago

Major Versions

1.0.2 → 2.0.02021-02-07

1.0.3 → 2.0.12022-01-03

2.1.2 → 3.0.0-RC12026-06-15

PHP version history (5 changes)1.0.0-ALPHAPHP ^7.4

1.0.0PHP ^7.4 || ^8.0

2.0.0PHP ^8.0

2.1.1PHP 8.0.\* || 8.1.\* || 8.2.\*

3.0.0-RC1PHP 8.3.\*

### Community

Maintainers

![](https://www.gravatar.com/avatar/909b2a0bdc281c7125fc264a04f0da1538f16cbad859501919565f8e21dde18d?d=identicon)[joaomfrebelo](/maintainers/joaomfrebelo)

---

Top Contributors

[![joaomfrebelo](https://avatars.githubusercontent.com/u/2965955?v=4)](https://github.com/joaomfrebelo "joaomfrebelo (42 commits)")[![pchouse](https://avatars.githubusercontent.com/u/47385696?v=4)](https://github.com/pchouse "pchouse (3 commits)")

---

Tags

ate faturaSAFT-PTAutoridade tributariaPortuguese Tax AuthorityPortuguese tax file audit

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Code StylePHP\_CodeSniffer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/joaomfrebelo-saft-pt-4-php/health.svg)

```
[![Health](https://phpackages.com/badges/joaomfrebelo-saft-pt-4-php/health.svg)](https://phpackages.com/packages/joaomfrebelo-saft-pt-4-php)
```

###  Alternatives

[matomo/matomo

Matomo is the leading Free/Libre open analytics platform

21.7k38.9k](/packages/matomo-matomo)[laravel/framework

The Laravel Framework.

34.8k543.8M20.1k](/packages/laravel-framework)[illuminate/console

The Illuminate Console package.

13046.0M6.5k](/packages/illuminate-console)[shopware/core

Shopware platform is the core for all Shopware ecommerce products.

585.6M574](/packages/shopware-core)[open-dxp/opendxp

Content &amp; Product Management Framework (CMS/PIM)

9421.6k61](/packages/open-dxp-opendxp)[dagger/dagger

Dagger PHP SDK

261.1k](/packages/dagger-dagger)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
