PHPackages                             dandjo/object-adapter - 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. dandjo/object-adapter

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

dandjo/object-adapter
=====================

Provides adapters for target objects with easy property access via magic getter and setter.

7.0.1(3y ago)0599MITPHPPHP &gt;=8.0

Since Mar 31Pushed 3y ago1 watchersCompare

[ Source](https://github.com/dandjo/object-adapter)[ Packagist](https://packagist.org/packages/dandjo/object-adapter)[ RSS](/packages/dandjo-object-adapter/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (10)DependenciesVersions (28)Used By (0)

Object Adapter
==============

[](#object-adapter)

Provides some base classes for adapting target objects with annotated property access.

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

[](#installation)

```
composer require dandjo/object-adapter

```

Purpose
-------

[](#purpose)

Its purpose is to make life easier when working with complex objects behind template engines like Twig. It offers some syntax sugar like writing methods with annotations and accessing the return value via the annotated property name on the adapter. The same applies to setters. It also offers a generic get method for nested data structures using a dotted notation. For this to work, each link in the chain must be an instance of ObjectAdapter or an accessible property.

Usage
-----

[](#usage)

To provide a property for your adapter, you have to annotate an appropriate method with either `@property\getter property_name` or `@property\setter property_name`. A setter method must take a parameter with the value the property should be set to. The name of the method can be chosen arbitrarily. However, the annotation is important. If there is no getter or setter, the adapter acts transparently on its target object.

Examples
--------

[](#examples)

Imagine you have an object with some properties, our target object. When using the ObjectAdapter base class directly, all properties are transparent by default.

```
$targetObject = new \stdClass();
$targetObject->foo = 'bar';

$myAdapter = new \Dandjo\ObjectAdapter\ObjectAdapter($targetObject);
echo $myAdapter->foo;  // 'bar'
```

We inherit from the ObjectAdapter and create a getter for the `foo` property on our target object. With the annotation, the adapter offers a property called `myFoo`.

```
class MyAdapter extends \Dandjo\ObjectAdapter\ObjectAdapter {

    /**
     * @property\getter myFoo
     */
    public function getMyFoo(): string
    {
        return $this->targetObject->foo;
    }

}

$targetObject = new \stdClass();
$targetObject->foo = 'bar';

$myAdapter = new MyAdapter($targetObject);
echo $myAdapter->myFoo;  // 'bar'
echo $targetObject->foo;  // 'bar'
```

Here's an example with a setter.

```
class MyAdapter extends \Dandjo\ObjectAdapter\ObjectAdapter {

    /**
     * @property\setter myFoo
     */
    public function setMyFoo($value): \Dandjo\ObjectAdapter\ObjectAdapter
    {
        $this->targetObject->foo = $value;
    }

}

$targetObject = new \stdClass();
$targetObject->foo = 'bar';

$myAdapter = new MyAdapter($targetObject);
echo $myAdapter->myFoo;  // 'bar'
$myAdapter->myFoo = 'baz';
echo $myAdapter->myFoo;  // 'baz'
echo $targetObject->foo;  // 'baz'
```

If you want to use deep object hierarchies, have a look at the following example. Chained calls are safe since every non-existent property will return a `NullAdapter`.

```
class MyChildAdapter extends \Dandjo\ObjectAdapter\ObjectAdapter {

    /**
     * @property\getter myFoo
     */
    public function getMyFoo(): string
    {
        return $this->targetObject->foo;
    }

}

class MyAdapter extends \Dandjo\ObjectAdapter\ObjectAdapter {

    /**
     * @property\getter myChild
     */
    public function getMyChild(): string
    {
        return new MyChildAdapter($this->targetObject->child);
    }

}

$targetObject = new \stdClass();
$targetObject->child = new \stdClass();
$targetObject->child->foo = 'bar';

$myAdapter = new MyAdapter($targetObject);
echo $myAdapter->myChild->myFoo;  // 'bar'
```

Each adapter implements the `ArrayAccess` and `Interator` Interface, so you can also access or loop annotated properties like follows.

```
class MyAdapter extends \Dandjo\ObjectAdapter\ObjectAdapter {

    /**
     * @property\getter myFoo
     */
    public function getMyFoo(): string
    {
        return $this->targetObject->foo;
    }

}

$targetObject = new \stdClass();
$targetObject->foo = 'bar';

$myAdapter = new MyAdapter($targetObject);
echo $myAdapter['foo'];  // 'bar'
echo $myAdapter['myFoo'];  // 'bar'

foreach ($myAdapter as $propertyName => $propertyValue) {
    echo "$propertyName: $propertyValue";  // myFoo: bar
}
```

###  Health Score

30

—

LowBetter than 64% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity67

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

Recently: every ~143 days

Total

27

Last Release

1215d ago

Major Versions

2.0.2 → 3.0.02021-04-13

3.2.0 → 4.0.02021-04-15

4.0.0 → 5.0.02021-04-17

5.2.0 → 6.0.02021-04-22

6.5.0 → 7.0.02022-07-22

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

7.0.0PHP &gt;=8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/9775283af17974a5fff5640197e99cfdbd3be38dd0ff39ba65c21354ed371c09?d=identicon)[dandjo](/maintainers/dandjo)

---

Top Contributors

[![dandjo](https://avatars.githubusercontent.com/u/34278179?v=4)](https://github.com/dandjo "dandjo (2 commits)")

---

Tags

objectadaptergettersetter

### Embed Badge

![Health badge](/badges/dandjo-object-adapter/health.svg)

```
[![Health](https://phpackages.com/badges/dandjo-object-adapter/health.svg)](https://phpackages.com/packages/dandjo-object-adapter)
```

###  Alternatives

[usmanhalalit/get-set-go

Dynamic Setter-Getter for PHP 5.4+

1813.4k1](/packages/usmanhalalit-get-set-go)[antares/accessible

PHP library that allows you to define your class' getters, setters and constructor with docblock annotations.

123.9k1](/packages/antares-accessible)

PHPackages © 2026

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