PHPackages                             sota2501/cakephp-ownership - 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. [Framework](/categories/framework)
4. /
5. sota2501/cakephp-ownership

ActiveCakephp-plugin[Framework](/categories/framework)

sota2501/cakephp-ownership
==========================

Ownership plugin for CakePHP

2.0.1(2y ago)0620MITPHPPHP &gt;=8.1

Since Dec 15Pushed 2y ago1 watchersCompare

[ Source](https://github.com/Sota2501/cakephp-ownership)[ Packagist](https://packagist.org/packages/sota2501/cakephp-ownership)[ RSS](/packages/sota2501-cakephp-ownership/feed)WikiDiscussions 2.x Synced 3w ago

READMEChangelog (7)Dependencies (4)Versions (9)Used By (0)

Ownership plugin for CakePHP
============================

[](#ownership-plugin-for-cakephp)

The Ownership Plugin is a plugin designed to introduce ownership functionality (distinct from user functionality). The key distinction lies in ensuring that the owner of an entity matches the owner of the associated entity. It is important to note, however, that guaranteeing this ownership match may result in an increased number of SELECT executions.

Installation
------------

[](#installation)

You can install this plugin into your CakePHP application using [composer](https://getcomposer.org).

The recommended way to install composer packages is:

```
composer require sota2501/cakephp-ownership

```

Load the plugin by adding the following statement in your project's `src/Application.php`:

```
public function bootstrap(): void
{
    parent::bootstrap();

    $this->addPlugin('Ownership');
}
```

Ownership Setup
---------------

[](#ownership-setup)

You must implement the OwnersTableInterface in the OwnersTable (ex: UsersTable). The following is an example, but it is acceptable to implement it as is.

```
use Ownership\Model\Table\OwnersTableInterface;

class UsersTable extends Table implements OwnersTableInterface
{
    protected $currentEntity = null;

    public function getCurrentEntity(): ?EntityInterface
    {
        return $this->currentEntity;
    }

    public function setCurrentEntity(?EntityInterface $entity): void
    {
        $this->currentEntity = $entity;
    }
}
```

At least, you must add the OwnershipBehavior to the table that introduces ownership (it is not necessary to add it to either the owner model or the model that does not introduce ownership). For options, specify the owner model name in 'owner' and the association key name to the owner model in 'parent'.

```
// ex) ArticleItemsTable => Articles => ( ... => ) Users
class ArticleItemsTable extends Table
{
    public function initialize(array $config): void
    {
        // ...
        $this->addBehavior('Ownership.Ownership', ['owner' => 'Users', 'parent' => 'Articles']);

        $this->belongsTo('Articles', [
            'foreignKey' => 'article_id',
        ]);
        // ...
    }
}
```

You can add OwnershipBehavior without specifying any options when not introducing ownership.

Usage
-----

[](#usage)

The consistency guarantee provided by this plugin is automatically performed in beforeSave event and does not provide a way to avoid this behavior.

This plugin provides a finder to get entities owned by a specific user. Additionally, it also offers a finder for entities that are not owned, even if ownership has been introduced.

```
$article = $articles->find('owned', ['owner_id' => 1])->first();
$article = $articles->find('nonOwned')->first();
```

By utilizing methods implemented in the owner model, especially by setting the logged-in user, you can get entities owned only by the currently logged-in user without specifying the owner\_id. Note that at least one of them must be specified, but if both are specified, the owner\_id takes precedence.

In addition to the above functionality, the OwnershipBehavior provides two functions:

```
$id = $articles->getOwnerId($article);
$isConsistent = $articles->isOwnerConsistent($article);
```

The first function gets the owner's ID in the form of an array `[field_name => ID]`. It returns null if the entity is not owned and false if ownership has not been introduced.

The second function is used to check the consistency of the owner.

License
-------

[](#license)

The Ownership Plugin is licensed under the MIT License.

###  Health Score

27

—

LowBetter than 47% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Every ~14 days

Recently: every ~1 days

Total

9

Last Release

810d ago

Major Versions

1.0.3 → 2.0.02024-04-01

1.x-dev → 2.0.12024-04-04

PHP version history (3 changes)1.0.0PHP &gt;=7.2

1.0.3PHP &gt;=7.4

2.0.0PHP &gt;=8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/10e6cffa56688d1a23f64af95b3537ec0ba7315f8d5080f29b59b26995e256d3?d=identicon)[Sota2501](/maintainers/Sota2501)

---

Top Contributors

[![sota2501](https://avatars.githubusercontent.com/u/86478666?v=4)](https://github.com/sota2501 "sota2501 (17 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan

Type Coverage Yes

### Embed Badge

![Health badge](/badges/sota2501-cakephp-ownership/health.svg)

```
[![Health](https://phpackages.com/badges/sota2501-cakephp-ownership/health.svg)](https://phpackages.com/packages/sota2501-cakephp-ownership)
```

###  Alternatives

[cakephp/debug_kit

CakePHP Debug Kit

84114.4M160](/packages/cakephp-debug-kit)[cakephp/bake

Bake plugin for CakePHP

11211.7M190](/packages/cakephp-bake)[friendsofcake/bootstrap-ui

Bootstrap front-end framework support for CakePHP

3502.1M38](/packages/friendsofcake-bootstrap-ui)[dereuromark/cakephp-ide-helper

CakePHP IdeHelper Plugin to improve auto-completion

1882.3M40](/packages/dereuromark-cakephp-ide-helper)[cakephp/twig-view

Twig powered View for CakePHP

155.5M17](/packages/cakephp-twig-view)[cakephp/elastic-search

An Elastic Search datasource and data mapper for CakePHP

85825.9k10](/packages/cakephp-elastic-search)

PHPackages © 2026

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