PHPackages                             rasuvaeff/yii3-filestorage-attachments - 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. rasuvaeff/yii3-filestorage-attachments

ActiveLibrary

rasuvaeff/yii3-filestorage-attachments
======================================

Tenant-scoped polymorphic file attachments for rasuvaeff/yii3-filestorage

v0.1.0(today)00BSD-3-ClausePHPPHP 8.3 - 8.5CI passing

Since Aug 14Pushed todayCompare

[ Source](https://github.com/rasuvaeff/yii3-filestorage-attachments)[ Packagist](https://packagist.org/packages/rasuvaeff/yii3-filestorage-attachments)[ Docs](https://github.com/rasuvaeff/yii3-filestorage-attachments)[ RSS](/packages/rasuvaeff-yii3-filestorage-attachments/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (19)Versions (2)Used By (0)

Yii3 Filestorage Attachments
============================

[](#yii3-filestorage-attachments)

`rasuvaeff/yii3-filestorage-attachments` provides a small database-backed owner-to-file link service for Yii3 Filestorage. It covers the common polymorphic attachment case without requiring Active Record.

Install
-------

[](#install)

```
composer require rasuvaeff/yii3-filestorage-attachments
```

The package requires `rasuvaeff/yii3-filestorage-db`. Run its file-table migration first, then register this package's migration namespace:

```
MigrationService::class => [
    'setSourceNamespaces()' => [[
        'Rasuvaeff\\Yii3FilestorageDb\\Migration',
        'Rasuvaeff\\Yii3FilestorageAttachments\\Migration',
    ]],
],
```

The config plugin supplies `AttachmentTableName` and `Attachments`. It does not bind `FileScopeProviderInterface`; applications with tenants bind that contract once, and the same provider is used by `yii3-filestorage-db`.

Usage
-----

[](#usage)

```
$attachments->attach(
    file: $file,
    ownerType: 'order',
    ownerId: (string) $orderId,
    role: 'invoice',
);

$invoices = $attachments->forOwner(
    ownerType: 'order',
    ownerId: (string) $orderId,
    role: 'invoice',
);

$attachments->detach(
    file: $file,
    ownerType: 'order',
    ownerId: (string) $orderId,
    role: 'invoice',
);
```

`attach()` is idempotent and returns `false` when the exact link already exists. `forOwner()` returns `list` in insertion order; omit `role` to list every role. `detachOwner()` removes every role and file link for an owner and must be called by the application or an Active Record lifecycle when that owner is deleted.

The table has a real foreign key to `filestorage_file`, so deleting a file row automatically removes its links. There is deliberately no generic foreign key to owner tables.

> **SQLite prerequisite:** SQLite enforces `ON DELETE CASCADE` only when every connection enables `PRAGMA foreign_keys = ON`. The package does not configure connections injected into it — do this in your application's connection setup. MySQL/MariaDB and PostgreSQL enforce the cascade by default.

Table names and scope
---------------------

[](#table-names-and-scope)

Set `rasuvaeff/yii3-filestorage-attachments.attachmentTable` and `tablePrefix`in application params when the defaults conflict. The migration and runtime service resolve the same typed `AttachmentTableName`.

With no scope provider, links use an internal empty scope key. With a bound `FileScopeProviderInterface`, every operation is restricted to its current scope and a file must be visible in that scope before it can be attached.

Verification
------------

[](#verification)

```
make build
make test-integration
make rector
```

The integration suite applies the real `yii3-filestorage-db` and attachments migrations on SQLite and exercises the documented migration path.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance100

Actively maintained with recent releases

Popularity0

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity40

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

0d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b0812d5572a7041dfe36e222d295b2e6dc55833a605350fcde58a51a5965ed30?d=identicon)[rasuvaeff](/maintainers/rasuvaeff)

---

Top Contributors

[![rasuvaeff](https://avatars.githubusercontent.com/u/1352718?v=4)](https://github.com/rasuvaeff "rasuvaeff (3 commits)")

---

Tags

attachmentsfilestorageyii3attachmentsyii3file storagepolymorphic

###  Code Quality

Static AnalysisPsalm, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/rasuvaeff-yii3-filestorage-attachments/health.svg)

```
[![Health](https://phpackages.com/badges/rasuvaeff-yii3-filestorage-attachments/health.svg)](https://phpackages.com/packages/rasuvaeff-yii3-filestorage-attachments)
```

###  Alternatives

[yiisoft/active-record

Active record pattern implementation

120103.6k19](/packages/yiisoft-active-record)

PHPackages © 2026

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