PHPackages                             ascetik/callapsule - 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. ascetik/callapsule

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

ascetik/callapsule
==================

A way to encapsulate callables

v0.4.0(2y ago)01043MITPHP

Since Nov 10Pushed 2y ago1 watchersCompare

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

READMEChangelogDependencies (1)Versions (7)Used By (3)

collabubble
===========

[](#collabubble)

A way to encapsulate a callable

Purpose
-------

[](#purpose)

This package is made to encapsulate a *callable* of any type, providing the ability to handle them the same way. I needed this kind of package for routing or a service manager, any task to defer, to encapsulate callables correctly...

Release notes
-------------

[](#release-notes)

> v0.4.0

- **CallableType** abstract *getReflection()* method.

Usage
-----

[](#usage)

Use the **CallWrapper** factory static methods to build a CallableType :

```
class Foo
{
    public function bar(){}
    public function __invoke(){}
    public static function biz(){}
}

// To wrap a Closure
$closureWrapper = CallWrapper::wrap(fn(string $name) => 'hello ' . $name);
// or
$closureWrapper = CallWrapper::wrapClosure(fn(string $name) => 'hello ' . $name);

// to wrap an instance and a method to call
$methodWrapper = CallWrapper::wrap([new Foo(), 'bar']);
// or
$methodWrapper = CallWrapper::wrapMethod(new Foo(), 'bar');

// to wrap a static method
$staticWrapper = CallWrapper::wrap([Foo::class, 'biz']);
// or
$staticWrapper = CallWrapper::wrapStatic(Foo::class, 'biz');

// To wrap an invokable class
$invokable = CallWrapper::wrap(new Foo());
// or
$invokable = CallWrapper::wrapInvokable(new Foo());
```

The use of this factory is the best choice to build and use a **CallableType**. Some checks make direct instanciation unavailable due to private constructors.

A **CallableType** is able to run the callable it holds. For external needs, it is able to give its callable back as is :

```
$callable = $closureWrapper->callable();
echo call_user_func($callable,' John'); // prints "hello John"

// or use it directly
echo $closureWrapper->apply(['name' => 'John']); // same result
```

CallableType methods
--------------------

[](#callabletype-methods)

- **CallableType**::apply(*?iterable*): *mixed* : execute callable and return the result
- **CallableType**::action(): *callable* : return wrapped callable type-hinted as *callable*
- **CallableType**::getCallable(): *object* : return wrapped callable fully type-hinted

Implementations
---------------

[](#implementations)

I could enumerate 4 use cases for a callable wrap :

- a Closure
- a class method, with an instance and the method to run
- a static class method, with a class-string instead of an instance
- an instance with \_\_invoke magic method

If you can find more, feel free to use **CallableType** abstraction.

### ClosureCall

[](#closurecall)

Holds a Closure. Direct instanciation (public constructor)

No Errors/Exceptions thrown

### InvokableCall

[](#invokablecall)

Holds an *invokable* instance. Static factory method for checks.

Throws an **UninvokableClassException** if the given instance does not implement *\_\_invoke()* method.

### MethodCall

[](#methodcall)

Holds an instance and a method. Static factory method for checks.

Throws a **MethodNotImplementedException** if given method is not implemented.

> *getCallable* method returns a **ClassMethod** instance with a *get()* method returning the callable array.

### StaticCall

[](#staticcall)

Holds a class name and a method name. Static factory for checks.

Throws a **ClassNotFoundException** if given class does not exist. Throws a **MethodNotImplementedException** if given method is not implemented.

> *getCallable* method returns a **ClassMethod** instance with a *get()* method returning the callable array.

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity13

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

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

Total

6

Last Release

911d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/4a4d8042606038f6fe934a289278b31406405b77801d3e77142b29341a2614d6?d=identicon)[ascetik](/maintainers/ascetik)

---

Top Contributors

[![ascetik](https://avatars.githubusercontent.com/u/92370226?v=4)](https://github.com/ascetik "ascetik (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/ascetik-callapsule/health.svg)

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

###  Alternatives

[vlucas/phpdotenv

Loads environment variables from `.env` to `getenv()`, `$\_ENV` and `$\_SERVER` automagically.

13.5k602.4M5.4k](/packages/vlucas-phpdotenv)[doctrine/collections

PHP Doctrine Collections library that adds additional functionality on top of PHP arrays.

6.0k411.1M1.2k](/packages/doctrine-collections)[nette/utils

🛠 Nette Utils: lightweight utilities for string &amp; array manipulation, image handling, safe JSON encoding/decoding, validation, slug or strong password generating etc.

2.1k394.3M1.5k](/packages/nette-utils)[orchestra/sidekick

Packages Toolkit Utilities and Helpers for Laravel

1214.3M14](/packages/orchestra-sidekick)

PHPackages © 2026

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