PHPackages                             dashifen/repository - 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. dashifen/repository

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

dashifen/repository
===================

An object with read-only protected properties from which other objects can be extened.

4.0.2(1y ago)05.4k5WTFPLPHPPHP &gt;=8.2

Since Jul 4Pushed 1y agoCompare

[ Source](https://github.com/dashifen/repository)[ Packagist](https://packagist.org/packages/dashifen/repository)[ RSS](/packages/dashifen-repository/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (2)Dependencies (2)Versions (28)Used By (5)

dashifen/repository
===================

[](#dashifenrepository)

*Repository* (noun): a place, building, or receptacle where things are or may be stored.

This package defines an object, `AbstractRepository`, that provides read-only access to its protected properties using `__get()`. If there are protected properties that need to remain hidden from external scopes, you can specify a list that won't be returned in that way.

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

[](#installation)

`composer install dashifen/repository`

Usage
-----

[](#usage)

There are two ways to go here:

1. Extend the `AbstractRepository` object.
2. Extend the `Repository` object.

If you extend the abstract object, you'll be forced to implement three methods:

1. getHiddenPropertyNames - returns an array of properties that should remain inaccessable via the arrow operator,
2. getCustomPropertyDefaults - sets more complex default values than can be set during property declaration,
3. getRequiredProperties - returns a list of properties that must have values after object instantiation.

The `Repository` object has already implemented these methods; they each return empty arrays.

Construction
------------

[](#construction)

The constructor for a Repository takes an associative array of data such that the indices are the names of properties and the array values will be set as the values for the listed properties. If you write a setter, it'll be called with the values for validation purposes.

The constructor's array argument's indices can either be in the expected camel case for the object's properties or in kabob case as in HTML attributes. Thus, an index of `start-date` would be "linked" to the `startDate` property.

Getters
-------

[](#getters)

Typically, because a Repository exposes protected properties, getting them with the arrow operator is the way to go. But, if you want to transform the internal representation of a property for external scopes, you can define a getter for a property that performs a transformation and returns its results. For example, converting a date from YYYY-MM-DD format into MM/DD/YYYY for display on-screen.

Getters must be in the form of `"get" . ucfirst($propertyName)`. So, the `startDate` property would have a getter of `getStartDate()`. Getters can, themselves, be protected if you want to hide them from external scopes and rely on the `__get()` implementation and the arrow operator for access.

Setters
-------

[](#setters)

Repositories do not implement `__set()`, so you have to write them yourself. By default, the `AbstractRepository` object will use setters within it's `__construct()` method. So, if you extend that object, you must create a setter for each of your properties that are expected to be used by that constructor, *i.e.* those properties referenced by the constructor's array parameter.

Like getters, they must be in the format of `"set" . ucfirst($propertyName)`. Thus, the setter for `startDate` must be `setStartDate()`. If you implement setters, they will be called from the Repository's constructor when it iterates over it's array argument. Because they're called from the constructor, they can be protected or private to create an object with read-only properties after construction.

### Example

[](#example)

```
class Foo extends AbstractRepository {
    protected $bar;
    protected $baz;
    protected $bing;

    protected function getHiddenPropertyNames(): array
    {
        return ["baz"];
    }

    protected function getCustomPropertyDefaults(): array
    {
        return ["bing" => strtotime('Y-m-d h:i:s')];
    }

    protected function getRequiredProperties(): array
    {
        return ["bar"];
    }

    protected function setBar(string $bar): void
    {
        $this->bar = $bar;
    }

    protected function getBar(): string
    {
        return ucfirst($this->bar);
    }
}

$foo = new Foo(["bar" => "apple"]);

echo $foo->bar;         // echos "Apple" because of the getBar() getter
echo $foo->baz;         // throws RepositoryException (baz is hidden)
echo $foo->bing;        // echos current timestamp (based on custom default value)

$oof = new Foo([]);     // throws RepositoryException (bar is required)
```

Array-able
----------

[](#array-able)

There is a `toArray` method for Repositories to extract property names and values for non-hidden properties of the object.

JsonSerializable
----------------

[](#jsonserializable)

Repositories implement the JsonSerializable interface. Therefore, you can encode them and non-hidden protected properties will be included in the JSON string that action produces.

Iterator
--------

[](#iterator)

Repositories implement the Iterator interface. This allows you to use them in a `foreach` loop. Using the Foo object defined in our example above ...

```
$foo = new Foo(['bar' => 'Hello, World!']);

foreach ($foo as $field => $value) {
    echo "$field: $value" . PHP_EOL;
}
```

... would produce ...

```
bar: Hello, World!
bing:

```

... skipping the `baz` property because it's hidden.

dashifen/container
------------------

[](#dashifencontainer)

This object is a new name for the old `dashifen/container` object. To avoid any confusion relating to the shared name with the PSR-11 Container Interface, I've simply changed the name from container to repository. All future work on this object will occur here. If you're still using the old object, I'd recommend switching your code and using this one instead.

###  Health Score

43

—

FairBetter than 91% of packages

Maintenance45

Moderate activity, may be stable

Popularity17

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity82

Battle-tested with a long release history

 Bus Factor1

Top contributor holds 62.1% 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 ~86 days

Recently: every ~275 days

Total

25

Last Release

433d ago

Major Versions

1.3.5 → 2.0.02020-01-23

2.0.4 → 3.0.02020-07-29

3.1.4 → 4.0.02023-09-05

PHP version history (4 changes)1.0.0PHP 7.3.\*

1.3.4PHP &gt;=7.3

3.0.0PHP &gt;=7.4

4.0.0PHP &gt;=8.2

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/8269?v=4)[David Dashifen Kees](/maintainers/dashifen)[@dashifen](https://github.com/dashifen)

---

Top Contributors

[![dashifen](https://avatars.githubusercontent.com/u/8269?v=4)](https://github.com/dashifen "dashifen (18 commits)")[![dashifen-gu](https://avatars.githubusercontent.com/u/50078554?v=4)](https://github.com/dashifen-gu "dashifen-gu (11 commits)")

### Embed Badge

![Health badge](/badges/dashifen-repository/health.svg)

```
[![Health](https://phpackages.com/badges/dashifen-repository/health.svg)](https://phpackages.com/packages/dashifen-repository)
```

###  Alternatives

[yangbx/captcha-lumen

captcha for lumen

123.8k](/packages/yangbx-captcha-lumen)

PHPackages © 2026

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