PHPackages                             ailixter/gears-watchedcall - 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. ailixter/gears-watchedcall

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

ailixter/gears-watchedcall
==========================

Hooks before/after any method call

0.1.0(6y ago)00MITPHPPHP ^7.1

Since Aug 10Pushed 6y ago1 watchersCompare

[ Source](https://github.com/ailixter/gears-watchedcall)[ Packagist](https://packagist.org/packages/ailixter/gears-watchedcall)[ RSS](/packages/ailixter-gears-watchedcall/feed)WikiDiscussions master Synced today

READMEChangelog (1)Dependencies (1)Versions (3)Used By (0)

gears-watchedcall
=================

[](#gears-watchedcall)

Hooks before/after any method call

Before a call
-------------

[](#before-a-call)

```
    use Ailixter\Gears\CallWatching;
    use const Ailixter\Gears\WatchedCall\BEFORE_CALL;
    use const Ailixter\Gears\WatchedCall\AFTER_CALL;

    class Example
    {
        use CallWatching;
        /**
         * @access public
         * via private modifier
         */
        private function watchedMethod($arg1, $arg2)
        {
            return $arg1 + $arg2;
        }
    }

    $example = new Example;
    $example->attachToWatch(BEFORE_CALL, 'watchedMethod', function (callable $callable, array $args) {
        // $callable is guaranteed to be in form [object, method]
        [$object, $method] = $callable;
        // inspect $args
        // ...
        // do something else
    });
    $result = $example->watchedMethod(2, 3); // 5
```

### Loud Access Check

[](#loud-access-check)

```
    $example->attachToWatch(BEFORE_CALL, 'watchedMethod', function (callable $callable) {
        if (!User::canAccess($callable)) {
            throw new UserAccessException;
        }
    });
    $result = $example->watchedMethod(2, 3); // exception
```

### Quiet Access Check

[](#quiet-access-check)

```
    $example->attachToWatch(BEFORE_CALL, 'watchedMethod', function (callable &$callable) {
        if (!User::canAccess($callable)) {
            // just return something acceptable
            $callable = function () { return null; }
        }
    });
    $result = $example->watchedMethod(2, 3); // null
```

### Fallback For Unknown Methods

[](#fallback-for-unknown-methods)

```
    $example->attachToWatch(BEFORE_CALL, 'unknownMethod', function (callable &$callable) {
        // just return something acceptable
        $callable = function () { return null; }
    });
    $result = $example->unknownMethod(2, 3); // null
```

### Tampering Routine

[](#tampering-routine)

```
    $example->attachToWatch(BEFORE_CALL, 'watchedMethod', function (callable &$callable) {
        $callable = 'min';
    });
    $result = $example->watchedMethod(2, 3); // 2
```

### Tampering Arguments

[](#tampering-arguments)

```
    $example->attachToWatch(BEFORE_CALL, 'watchedMethod', function (callable $callable, array &$args) {
        $args = array_map(function (int $arg) { return $arg * $arg; }, $args);
    });
    $result = $example->watchedMethod(2, 3); // 13
```

### Classic Decoration

[](#classic-decoration)

```
    $done = false;
    $example->attachToWatch(BEFORE_CALL, 'watchedMethod', function (callable &$callable) use (&$done) {
        if ($done) return;
        $done = true;
        $callable = function (...$args) use ($callable) {
            return $callable(...array_map(function (int $arg) { return $arg * $arg; }, $args)) + 1;
        };
    });
    $result = $example->watchedMethod(2, 3); // 14
```

After a call
------------

[](#after-a-call)

### Result Substitution

[](#result-substitution)

```
    $example->attachToWatch(AFTER_CALL, 'watchedMethod', function (callable $callable, array $args, &$result) {
        $result *= 2;
    });
    $result = $example->watchedMethod(2, 3); // 10
```

### Loud Result Check

[](#loud-result-check)

```
    $example->attachToWatch(AFTER_CALL, 'watchedMethod', function (callable $callable, array $args, $result) {
        if (array_sum($args) != $result) {
            throw new CalculationError;
        }
    });
    $result = $example->watchedMethod(2, 3); // 10
```

### Quiet Result Check

[](#quiet-result-check)

```
    $example->attachToWatch(AFTER_CALL, 'watchedMethod', function (callable $callable, array $args, &$result) {
        if (array_sum($args) != $result) {
            $result = null;
        }
    });
    $result = $example->watchedMethod(2, 3); // 10
```

Decoration
----------

[](#decoration)

```
    $example
    ->attachToWatch(BEFORE_CALL, 'watchedMethod', function (callable $callable, array &$args) {
        $args = array_map(function (int $arg) { return $arg * $arg; }, $args);
    })
    ->attachToWatch(AFTER_CALL, 'watchedMethod', function (callable $callable, array $args, &$result) {
        $result += 1
    });
    $result = $example->watchedMethod(2, 3); // 14
```

Watching via Delegation
-----------------------

[](#watching-via-delegation)

```
    class Delegate
    {
        public function watchedMethod($arg1, $arg2)
        {
            return $arg1 + $arg2;
        }
    }

    class Example
    {
        use CallWatching;
        private $delegate;
        public function __construct(Delegate $delegate)
        {
            $this->delegate = $delegate;
        }
        /**
         * note overriding
         */
        protected function getWatchedObject()
        {
            return $this->delegate;
        }
    }
```

###  Health Score

19

—

LowBetter than 10% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity0

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity44

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

Total

2

Last Release

2461d ago

### Community

Maintainers

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

---

Top Contributors

[![ailixter](https://avatars.githubusercontent.com/u/8529462?v=4)](https://github.com/ailixter "ailixter (7 commits)")

---

Tags

access-controlcontractdecoratormanagedpostconditionprecondition

### Embed Badge

![Health badge](/badges/ailixter-gears-watchedcall/health.svg)

```
[![Health](https://phpackages.com/badges/ailixter-gears-watchedcall/health.svg)](https://phpackages.com/packages/ailixter-gears-watchedcall)
```

PHPackages © 2026

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