PHPackages                             mpyw/sharable-value-objects - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. mpyw/sharable-value-objects

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mpyw/sharable-value-objects
===========================

Share value objects that contain the same primitive value as a singleton.

v1.1.0(1y ago)784.6k1MITPHPPHP &gt;=8.2 &lt;8.3.2 || &gt;=8.3.3CI passing

Since Nov 11Pushed 5mo ago1 watchersCompare

[ Source](https://github.com/mpyw/sharable-value-objects)[ Packagist](https://packagist.org/packages/mpyw/sharable-value-objects)[ RSS](/packages/mpyw-sharable-value-objects/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (8)Used By (0)

sharable-value-objects
======================

[](#sharable-value-objects)

[![Build Status](https://github.com/mpyw/sharable-value-objects/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/mpyw/sharable-value-objects/actions) [![Coverage Status](https://camo.githubusercontent.com/4432a6e5345e0ff096ce156ddbd1b838ae29274955dd0e8fc58fafb0e01476d8/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6769746875622f6d7079772f7368617261626c652d76616c75652d6f626a656374732f62616467652e7376673f6272616e63683d6d6173746572)](https://coveralls.io/github/mpyw/sharable-value-objects?branch=master)

Share value objects that contain the same primitive value as a singleton.

Important

**Singleton objects are kept under [`WeakReference`](https://www.php.net/manual/class.weakreference.php).**

Tip

You can compare objects like primitives through `===` operator!

```
Value::create('one') === Value::create('one')  // This should be true
Value::create('one') === Value::create('two')  // This should be false
```

Requirements
------------

[](#requirements)

- PHP: `^8.2`

Note

Older versions have outdated dependency requirements. If you cannot prepare the latest environment, please refer to past releases.

Installing
----------

[](#installing)

```
composer require mpyw/sharable-value-objects
```

Caution

**PHP 8.3.2** is incompatible due to the bug in the PHP core.

- [PHP 8.3.2: final private constructor not allowed when used in trait · Issue #13177 · php/php-src](https://github.com/php/php-src/issues/13177)

Usage
-----

[](#usage)

```
class ScreenName
{
    // 1. Mixin Sharable trait family
    use SharableString;

    // 2. Write your instantiation logic here
    public static function create(string $value): static
    {
        // Validation/Assertion
        if (!preg_match('/\A@\w{4,15}\z/', $value)) {
            throw new \InvalidArgumentException("invalid screen_name: $value");
        }

        // ** Call static::acquire() to get instance **
        return static::acquire($value);
    }

    // 3. Write your raw presentation logic here
    public function value(): string
    {
        // ** Call $this->getOriginalValue() to retrieve original value **
        return $this->getOriginalValue();
    }
}
```

```
class ScreenNameTest extends TestCase
{
    public function testSame(): void
    {
        // Same parameters yield the same instance
        $this->assertSame(
            ScreenName::create('@mpyw'),
            ScreenName::create('@mpyw'),
        );
    }

    public function testDifferent(): void
    {
        // Different parameters yield different instances
        $this->assertNotSame(
            ScreenName::create('@mpyw'),
            ScreenName::create('@X'),
        );
    }
}
```

###  Health Score

47

—

FairBetter than 94% of packages

Maintenance60

Regular maintenance activity

Popularity33

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity70

Established project with proven stability

 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 ~302 days

Total

5

Last Release

438d ago

PHP version history (3 changes)v1.0.0PHP &gt;=8.0

v1.0.3PHP &gt;=8.0 &lt;8.3.2 || &gt;=8.3.3

v1.1.0PHP &gt;=8.2 &lt;8.3.2 || &gt;=8.3.3

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1351893?v=4)[mpyw](/maintainers/mpyw)[@mpyw](https://github.com/mpyw)

---

Top Contributors

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

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mpyw-sharable-value-objects/health.svg)

```
[![Health](https://phpackages.com/badges/mpyw-sharable-value-objects/health.svg)](https://phpackages.com/packages/mpyw-sharable-value-objects)
```

###  Alternatives

[getsolaris/laravel-make-service

A MVCS pattern create a service command for Laravel 5+

81161.3k](/packages/getsolaris-laravel-make-service)[ikkez/f3-flash

Add simple Flash Messages and Flash Keys to PHP Fat-Free Framework

1926.0k5](/packages/ikkez-f3-flash)[mfd/ai-filemetadata

Automatically generates FAL metadata for files by means of public LLMs

1142.1k](/packages/mfd-ai-filemetadata)[latfur/laravel-event-crud

Laravel Event CRUD With Full Calendar

125.6k](/packages/latfur-laravel-event-crud)

PHPackages © 2026

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