PHPackages                             holgerk/jiggle - 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. holgerk/jiggle

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

holgerk/jiggle
==============

v1.0.5(12y ago)0146MITPHPPHP &gt;=5.3.0

Since Oct 20Pushed 11y ago1 watchersCompare

[ Source](https://github.com/holgerk/php-jiggle)[ Packagist](https://packagist.org/packages/holgerk/jiggle)[ RSS](/packages/holgerk-jiggle/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (7)Used By (0)

php-jiggle [![Latest Stable Version](https://camo.githubusercontent.com/6b157c6e2dc2ebfa8f78006a114241755bd36ac32c7f5f72004d37e63f8495c0/68747470733a2f2f706f7365722e707567782e6f72672f686f6c6765726b2f6a6967676c652f762f737461626c652e706e67)](https://packagist.org/packages/holgerk/jiggle) [![Build Status](https://camo.githubusercontent.com/704d72a80fbe08701d523415855851f107475015452961d86f751f024113ceef/68747470733a2f2f7472617669732d63692e6f72672f686f6c6765726b2f7068702d6a6967676c652e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/holgerk/php-jiggle)
====================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#php-jiggle--)

Jiggle is a depency injection container for php 5.3+

By default every dependency is a singleton. If you assign an function to to the container it is considered as an singleton factory. So the function is only called once when the dependency is required the first time.

Methods
-------

[](#methods)

### singleton($class)

[](#singletonclass)

Create a singleton factory for the given class

- **param** string $class the class which should be instantiated
- **return** callable

### create($class)

[](#createclass)

Create an object of the given class

If the class constructor has arguments they are injected from the current jiggle instance.

- **param** string $class the class to instantiate
- **return** object the newly created instance

### inject($callable, $overloadedDeps = array())

[](#injectcallable-overloadeddeps--array)

Executes the given callable

If the callable has arguments they are injected from the current jiggle instance.

- **param** callable $callable the callable to invoke
- **param** array $overloadedDeps optional additional or overloaded dependencies
- **return** mixed return value of the invoked callable

### replace($name, $value)

[](#replacename-value)

Replace an existing dependency

Usefull if one would like to mock some part of a bigger system or for clients to replace an unwanted implementation.

- **param** string $name of the dependency to replace
- **param** mixed $value replacement implementation

### resolver($callable)

[](#resolvercallable)

Let one provide a callable which is called if a dependency is not resolvable

If the provided resolver can resolve the dependency it should simply return it. If the dependency could not resolved the resolver needs to throw an exception, otherwise the dependency would be resolved to null.

- **param** callable $callable the resolver callabe

Examples
--------

[](#examples)

### Set and get dependencies

[](#set-and-get-dependencies)

```
$jiggle = new Jiggle;
$jiggle->d1 = 42;
echo $jiggle->d1; // => 42
```

### Lazy loading with factory functions

[](#lazy-loading-with-factory-functions)

```
$jiggle = new Jiggle;
$jiggle->d1 = function() {
    return 42;
};
echo $jiggle->d1; // => 42
```

### Basic wiring of dependencies

[](#basic-wiring-of-dependencies)

```
$jiggle = new Jiggle;
$jiggle->d1 = 42;
$jiggle->d2 = function() use($jiggle) {
    return $jiggle->d1;
};
echo $jiggle->d2; // => 42
```

### Implicit injection of depencies into singleton factory functions

[](#implicit-injection-of-depencies-into-singleton-factory-functions)

```
$jiggle = new Jiggle;
$jiggle->d1 = 42;
$jiggle->d2 = function($d1) {
    return $d1;
};
echo $jiggle->d2; // => 42
```

### Explicit injection of depencies into any function

[](#explicit-injection-of-depencies-into-any-function)

```
$jiggle = new Jiggle;
$jiggle->d1 = 40;
$jiggle->d2 = 2;
$result = $jiggle->inject(function($d1, $d2) {
    return $d1 + $d2;
});
echo $result; // => 42
```

### Explicit injection with dependency overloading

[](#explicit-injection-with-dependency-overloading)

```
$jiggle = new Jiggle;
$jiggle->d1 = 20;
$jiggle->d2 = 1000;
$result = $jiggle->inject(function($d1, $d2, $d3) {
    return $d1 + $d2 + $d3;
}, array('d2' => 20, 'd3' => 2));
echo $result; // => 42
```

### Basic instantiation

[](#basic-instantiation)

```
$jiggle = new Jiggle;
$jiggle->d1 = 40;
$jiggle->d2 = 2;
$jiggle->d3 = function() use($jiggle) {
    return new D3($jiggle->d1, $jiggle->d2);
};
echo $jiggle->d3->sum(); // => 42
```

### Instantiation with implicit constructor injection

[](#instantiation-with-implicit-constructor-injection)

```
$jiggle = new Jiggle;
$jiggle->d1 = 40;
$jiggle->d2 = 2;
$jiggle->d3 = function() use($jiggle) {
    return $jiggle->create('D3');
};
echo $jiggle->d3->sum(); // => 42
```

### Short form of implicit constructor injection

[](#short-form-of-implicit-constructor-injection)

```
$jiggle = new Jiggle;
$jiggle->d1 = 40;
$jiggle->d2 = 2;
$jiggle->d3 = $jiggle->singleton('D3');
echo $jiggle->d3->sum(); // => 42
```

### Basic function dependency

[](#basic-function-dependency)

```
$jiggle = new Jiggle;
$jiggle->d1 = function() {
    return function() {
        return 42;
    };
};
echo $jiggle->d1(); // => 42
```

### Existing deps could not replaced by accident

[](#existing-deps-could-not-replaced-by-accident)

```
$jiggle = new Jiggle;
$jiggle->a = true;
$jiggle->a = false; // d1 = 21;
$jiggle->replace('d1', 42);
echo $jiggle->d1; // => 42
```

### Isset support

[](#isset-support)

```
$jiggle = new Jiggle;
$jiggle->d1 = 42;
$this->assertTrue(isset($jiggle->d1));
$this->assertFalse(isset($jiggle->d2));
```

### Resolver is called for unresolvable deps

[](#resolver-is-called-for-unresolvable-deps)

```
$jiggle = new Jiggle;
$jiggle->resolver(function($dependencyName) {
    if ($dependencyName == 'd2') {
        return 42;
    }
    throw new Exception("Could not resolve dependency: $dependencyName!");
});
$jiggle->d1 = function($d2) { return $d2; };
echo $jiggle->d1; // => 42
```

Composer
--------

[](#composer)

```
{
    "require": {
        "holgerk/jiggle": "*"
    }
}
```

License
-------

[](#license)

The MIT License (MIT)

Copyright (c) 2013 Holger Kohnen

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity62

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

Total

6

Last Release

4562d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/8e55c03dc164181c5860898403302c95e31822e3610dc02027b1adc89269180d?d=identicon)[holgerk](/maintainers/holgerk)

---

Top Contributors

[![holgerk](https://avatars.githubusercontent.com/u/1426236?v=4)](https://github.com/holgerk "holgerk (24 commits)")

### Embed Badge

![Health badge](/badges/holgerk-jiggle/health.svg)

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

###  Alternatives

[dotswan/filament-map-picker

Easily pick and retrieve geo-coordinates using a map-based interface in your Filament applications.

124139.3k2](/packages/dotswan-filament-map-picker)[ender/laravel-ueditor

A laravel package of ueditor,which is baidu's open source WYSIWYG editor

393.4k](/packages/ender-laravel-ueditor)

PHPackages © 2026

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