PHPackages                             mindgruve/gordo-proxy - 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. [Database &amp; ORM](/categories/database)
4. /
5. mindgruve/gordo-proxy

ActiveLibrary[Database &amp; ORM](/categories/database)

mindgruve/gordo-proxy
=====================

Extend your doctrine proxies with Gordo-Proxy

0.5.15(9y ago)0136MITPHP

Since Apr 26Pushed 9y ago4 watchersCompare

[ Source](https://github.com/mindgruve/gordo-proxy)[ Packagist](https://packagist.org/packages/mindgruve/gordo-proxy)[ RSS](/packages/mindgruve-gordo-proxy/feed)WikiDiscussions master Synced 3w ago

READMEChangelog (10)Dependencies (5)Versions (16)Used By (0)

Gordo-Proxy
===========

[](#gordo-proxy)

```
    No more anemic data models  :)
    Gordo is a small library designed to help you build deliciously rich domains.

```

Architecture
------------

[](#architecture)

Gordo splits the responsibilities of business logic from your database mapping:

- First a doctrine data object. (Entity if using ORM, Document if using ODM).
- A second object which holds most of your business logic which acts as a proxy to your doctrine data object.
- A factory class for dependency injection.
- When you have object associations (one-to-one, many-to-one) these will also be lazy-loaded and into proxy objects.
- You can configure your Proxy object to sync data back to your doctrine data object.

To Summarize:

```
    With Gordo you can create a Proxy object and interact with it as if it were the original data object.

```

Quick Start - Creating a proxy
------------------------------

[](#quick-start---creating-a-proxy)

Say we have a User data object, and we want to inject a dependency (like an encryption service).

1. Your doctrine entity is updated by adding an annotation @Proxy, where the target is the fully qualified name of your Proxy object.

    ```
     namespace Gordo\Example;

     /**
     * @Entity
     * @Proxy(target="Gordo\Example\UserProxy")
     */
     class User
     {
         /**
          * @Id @Column(type="integer")
          * @GeneratedValue
          */
         private $id;

         /** @Column(length=140) */
         protected $username;

          /** @Column(length=140) */
         protected $passwordHash;
     }

    ```
2. Here is the service you want to inject. In real life, this might be much more complicated :)

    ```
     Namespace Gordo\Example;

     class passwordChecker
     {
         public function isValid($password, $hash){
             return md5($password) == $hash;
         }

         public function hash($password){
             return md5($password);
         }
     }

    ```
3. Since we can't inject dependencies into our Doctrine entity class, we create a proxy class . There are two requirements: (1) Be sure to extend your entity and (2) use the ProxyTrait. In this example, our UserProxy also encapsulates our encryption business logic.

    ```
     namespace Gordo\Example;
     use Mindgruve\Gordo\Traits\ProxyTrait;;

     class UserProxy extends User
     {
          use ProxyTrait;

         protected $passwordChecker;

         public function __construct($passwordChecker){
             $this->passwordChecker = $passwordChecker;
         }

         public function updatePassword($password){
             $this->passwordHash = $this->passwordChecker->hash($password);
         }

         public function isValidPassword($password){
             return $this->passwordHash->isValid($password);
         }
     }

    ```
4. Gordo-Proxy allows you to register a factory to create your Proxy objects. Be sure to implement **Mindgruve\\Gordo\\Proxy\\FactoryInterface**. The factory interface has to methods - supports() which should return true if your Factory supports a given class, and build() which should return a new instance of your Proxy class. (For example, If this factory were used in Symfony it would be a service, and the encryption service would be injected.)

    ```
     namespace Gordo\Example;

     use Mindgruve\Gordo\Proxy\FactoryInterface;

     class UserProxyFactory implements FactoryInterface{
         protected $passwordChecker;
         public function __construct($passwordChecker){
             $this->passwordChecker = $passwordChecker;
         }

         public function supports($proxyClass){
             if ($proxyClass == 'Gordo\Example\UserProxy') {
                 return true;
             }

             return false;
         }
     }

     /**
      * @param $proxyClass
      * @return object
      */
     public function build($proxyClass)
     {
         return new UserProxy($this->passwordChecker);
     }

    ```
5. Now you are ready to register your factory with the ProxyManager and build your first proxy...

    ```
     use Mindgruve\Gordo\Proxy\ProxyManager;
     use Gordo\Example\UserProxyFactory;

     // Register the factory
     $proxyManager = new ProxyManager($entityManager);
     $userManager->registerFactory(new UserProxyFactory());

     // Get a doctrine entity
     $userRepository = $entityManager->getRepository('Mindgruve\Example\User');
     $users = $userRepository->load($id);

     // Transform doctrine entity into proxy
     $userProxy = $proxyManager->transform($user);

    ```

Automatic Data Syncing between Proxy --&gt; Data Object
-------------------------------------------------------

[](#automatic-data-syncing-between-proxy----data-object)

When you create a Proxy, Gordo-Proxy copies over the data from the Doctrine object into the Proxy when created. From this point on, the doctrine object and the proxy generated by Gordo-Proxy are separate.

However, sometimes, it is useful to establish data binding from the proxy back to the original doctrine entity or document.

There are a couple of annotations that you can put on your entity to configure this data syncing.

PropertyDescriptionDefaultsyncPropertiesArray of properties to syncAll properties are syncedsyncMethodsMethods that initiate a sync to entityBy default, methods sync dataIf you want to sync all properties use syncProperties={"*"}
Likewise If you want to sync all the methods use syncMethods={"*"}.
If syncMethods is null or empty array, then data syncing is disabled.

**Example:** Sync all properties, but only when username is updated

```
/**
 * @Entity
 * @Proxy(target="Gordo\Example\UserProxy",syncMethods={"setUsername"})
 */

```

**Example:** Sync only the password

```
/**
 * @Entity
 * @Proxy(target="Gordo\Example\UserProxy",syncProperties={"passwordHash"},syncMethods={"setPassword"})
 */

```

**Example:** Turning on automatic syncing for all properties

```
/**
 * @Entity
 * @Proxy(target="Gordo\Example\UserProxy",syncMethods={"*"})
 */

```

Manually Syncing Data
---------------------

[](#manually-syncing-data)

Part of the ProxyTrait is a public function syncData($syncDirection, $properties).

The first parameter **$syncDirection** is either:
**ProxyConstants::UPDATE\_DATA\_OBJECT** - which will transfer the changes from the proxy object --&gt; doctrine data object
**ProxyConstants::UPDATE\_PROXY** - which will transfer changes the other way and pull up changes from the doctrine data object --&gt; proxy

The second parameter is either an array of properties to sync or one of 3 constants:
**ProxyConstants::SYNC\_PROPERTIES\_NONE** - which is a noop
**ProxyConstants::SYNC\_PROPERTIES\_DEFAULT** - which will sync properties defined in the objects @Proxy meta data for syncProperties
**ProxyConstants::SYNC\_PROPERTIES\_ALL** - which will sync all the properties (regardless of what is in the @Proxy meta data)

**Note** There is also a protected method getDataObject() as part of the ProxyTrait which will return the original data object used to create the proxy.

Todo
----

[](#todo)

- Build command to build production ready proxies.

###  Health Score

28

—

LowBetter than 52% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity61

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

Recently: every ~17 days

Total

15

Last Release

3643d ago

### Community

Maintainers

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

---

Top Contributors

[![swimson](https://avatars.githubusercontent.com/u/4927059?v=4)](https://github.com/swimson "swimson (107 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/mindgruve-gordo-proxy/health.svg)

```
[![Health](https://phpackages.com/badges/mindgruve-gordo-proxy/health.svg)](https://phpackages.com/packages/mindgruve-gordo-proxy)
```

###  Alternatives

[propel/propel1

Propel is an open-source Object-Relational Mapping (ORM) for PHP5.

8351.6M87](/packages/propel-propel1)[analogue/orm

An intuitive Data Mapper ORM for PHP and Laravel

63447.3k3](/packages/analogue-orm)[bravo3/orm

NoSQL ORM for databases such as Redis

619.0k2](/packages/bravo3-orm)[concrete5/core

Concrete – an open source content management system.

20163.8k49](/packages/concrete5-core)[hiqdev/yii2-data-mapper

Data Mapper for Yii2

1316.9k1](/packages/hiqdev-yii2-data-mapper)

PHPackages © 2026

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