PHPackages                             brain/amygdala - 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. brain/amygdala

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

brain/amygdala
==============

Simplify request sniffing and getting in WordPress.

0.1.0(10y ago)61.9k3GPL-2.0+PHPPHP &gt;=5.4

Since Feb 23Pushed 10y ago2 watchersCompare

[ Source](https://github.com/gmazzap/Amygdala)[ Packagist](https://packagist.org/packages/brain/amygdala)[ RSS](/packages/brain-amygdala/feed)WikiDiscussions master Synced 5d ago

READMEChangelog (1)Dependencies (4)Versions (2)Used By (3)

Amygdala
========

[](#amygdala)

Amygdala is a package (not full plugin) that wraps request informations and ease the getting of data without having to deal with superglobals.

It makes use of [composer](https://getcomposer.org/) to be embedded in larger projects.

It is part of the [Brain Project](http://giuseppe-mazzapica.github.io/Brain) module.

\###API###

Amygdala package comes with an API that ease its usage, without having to get, instantiate or digging into package objects. API is defined in a class, stored in the Brain (Pimple) container with the id: `"amygdala"`. So is possible to get it using Brain instance, something like: `$api = Brain\Container::instance()->get("amygdala")`, and then call all API function on the instance got in that way. However that's not very easy to use, especially for people used to just use a plain function to add and trigger hooks. This is the reason why package also comes with a **facade class**. The term is not referred to [façade pattern](http://en.wikipedia.org/wiki/Facade_pattern), but more to [Laravel facades](http://laravel.com/docs/facades), whence the approach (not actual code) comes from: no *real* static method is present in the class, but a single `__callstatic` method that *proxy* API methods to proper instantiated objects.

The facade class is named `Request` inside Brain namespace. A simple example to get a variable from `$_GET` sanitized as url using `'example.com'` as default:

```
Brain\Request::query( 'adomain', 'example.com', FILTER_SANITIZE_URL );

```

\###Embed in OOP projects###

The static facade class is easy to use, however using in that way inside other classes, create there hardcoded dependency to Amygdala. In addition, unit testing other classes in isolation becomes pratically impossible. To solve these problems, the easiest way is to use composition via dependency injection. In facts, the `Brain\Request` facade class can be used in dynamic way, like so:

```
$request = new Brain\Request;
$request->query( 'adomain', 'example.com', FILTER_SANITIZE_URL );

```

There is absolutely no difference in the two methods, but using the latter is possible to inject an instance of the class inside other classes. See the following example:

```
class A_Plugin_Class {

  function __construct( \Brain\Request $request ) {
    $this->request = $request;
  }

  function get_a_POST_value( $a_key, $default = '', $filter = FILTER_UNSAFE_RAW ) {
    return $this->request->post( $a_key, $default, $filter );
  }

}

```

The method `get_a_POST_value` makes use of `$this->request` property to call the Amygdala API method. Testing the method in isolation is very simple too, an example using PHPUnit and Mockery:

```
class A_Plugin_Class_Test () {

  function test_get_a_POST_value() {
    $request = \Mockery::mock('\Brain\Request');
    $request->shouldReceive( 'post' )->once()->with( 'foo', 'bar' )->andReturn( 'A value!' );
    $class = new A_Plugin_Class( $request );
    $this->assertEquals( 'A value!', $class->get_a_POST_value( 'foo', 'bar' ) );
  }

}

```

So the method is tested in isolation, mocking a $\_POST request: easy and straightforward.

\###Gotchas!###

Amygdala is a Brain module. As you can read in [Brain readme](https://github.com/Giuseppe-Mazzapica/Brain/blob/master/README.md), it bootstrap itself and its modules on `after_setup_theme` with priority 0, this mean that you **can't use Amygdala before `after_setup_theme` is fired**.

\###Requirements###

- PHP 5.4+
- Composer (to install)
- WordPress 3.9 (it *maybe* works with earlier versions, but it's not tested and versions &lt; 3.9 will never supported).

\###Installation###

You need [Composer](https://getcomposer.org/) to install the package. It is hosted on [Packagist](https://packagist.org/), so the only thing needed is insert `"brain/amygdala": "dev-master"` in your `composer.json` `require` object

```
{
    "require": {
        "php": ">=5.4",
        "brain/amygdala": "dev-master"
    }
}

```

See [Composer documentation](https://getcomposer.org/doc/) on how to install Composer itself, and packages.

\###Codename: Amygdala###

The *Amygdala*, is a part of the brain that shown in research to perform a primary role in the processing of decision-making.

Amygdala package is so called because is a [Brain](https://github.com/Giuseppe-Mazzapica/Brain) module, and an http request is what makes WordPress (most web applications indeed) makes decision on what to do.

\###Developers &amp; Contributors###

Package is open to contributors and pull requests. It comes with a set of unit tests written for [PHPUnit](http://phpunit.de/) suite. Please be sure all tests pass before submit a PR. To run tests, please install package in stand-alone mode (i.e 'vendor' folder is inside package folder). When installed in *dev* mode Striatum also install [Mockery](https://github.com/padraic/mockery), a powerful mocking test utility.

\###License###

Amygdala own code is licensed under GPLv2+. Through Composer, it install code from:

- [Composer](https://getcomposer.org/) (MIT)
- [Brain](https://github.com/Giuseppe-Mazzapica/Brain) (GPLv2+)
- [Pimple](http://pimple.sensiolabs.org/) (MIT) - required by Brain -
- [PHPUnit](http://phpunit.de/) (BSD-3-Clause) - only dev install -
- [Mockery](https://github.com/padraic/mockery) (BSD-3-Clause) - only dev install -

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity48

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

Unknown

Total

1

Last Release

3736d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/2208282?v=4)[Giuseppe Mazzapica](/maintainers/gmazzap)[@gmazzap](https://github.com/gmazzap)

---

Top Contributors

[![gmazzap](https://avatars.githubusercontent.com/u/2208282?v=4)](https://github.com/gmazzap "gmazzap (40 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/brain-amygdala/health.svg)

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

PHPackages © 2026

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