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

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

brain/brain
===========

A Pimple wrapper for WordPress

0.1.1(10y ago)182.6k7GPL-2.0+PHPPHP &gt;=5.4

Since Feb 23Pushed 10y ago2 watchersCompare

[ Source](https://github.com/gmazzap/Brain)[ Packagist](https://packagist.org/packages/brain/brain)[ RSS](/packages/brain-brain/feed)WikiDiscussions master Synced 1w ago

READMEChangelog (1)Dependencies (2)Versions (2)Used By (7)

Brain
=====

[](#brain)

Brain is a simple [Pimple](http://pimple.sensiolabs.org/) wrapper for WordPress.

It's the base package of the [Brain Project](http://giuseppe-mazzapica.github.io/Brain).

To register params and services in the container you should create a **module**, that is a class implementing `Brain\Module` inteface.

This interface is made by 3 methods:

1. `getBindings` that take the current container as argument, it is used to register services and params
2. `boot` to boot the module, i.e. to run something that should be done once. Method takes as argument the current container, so it can be used to do something on boot.
3. `getPath` that should return the absolute path of module folder

To register the module, should be used the `addModule` method of container, but **only using `'brain_init'` hook**.

The `'brain_loaded'` hook is fired when all modules has been loaded.

\##Usage Example##

\###First define a service###

```
class FooService {

  function foo( $foo = '' ) {
    echo 'Foo is ' . $foo . '';
  }

}

```

\###Then define a Brain module###

```
class FooModule implements Brain\Module {

  function getBindings( Brain\Container $brain ) {
    $brain['foo'] = 'bar';
    $brain['foo_service'] = function() { return new FooService; };
  }

  function boot( Brain\Container $brain ) {
    add_action( 'loop_start', function() use( $brain ) {
      $brain['foo_service']->foo( $brain['foo'] );
    });
  }

  function getPath() {
    return dirname( __FILE__ );
  }
}

```

\###Finally add the module to Brain###

```
add_action( 'brain_init', function( $brain ) {
  $brain->addModule( new FooModule );
});

```

See [Pimple docs](http://pimple.sensiolabs.org/) for more info.

\###Get data from Brain###

To get services registered is possible to use the `Brain::instance()` static method and use the array access method of Pimple, something like:

```
$brain = Brain::instance();
$foo_service = $brain['foo_service'];

```

or is possible to use the Brain `get` method, in chaining it with the `instance` method, just like:

```
$foo_service = Brain::instance()->get('foo_service');

```

\##Installation##

The package should be installed via [Composer](https://getcomposer.org/). Brain is available through [packagist](https://packagist.org/), so you only need to add in your `composer.json` the require settings. Something like so:

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

```

There is no need to explicitly require Pimple, because Brain will require it for you. after that just

```
$ composer install

```

and you are done. See [composer docs](https://getcomposer.org/doc/) for further details.

\###Note on PHP version###

Pimple supports PHP 5.3+, however I don't want to support anymore that version, so even if (probably) the current version on Brain works with PHP 5.3, is possible that a nearly future release will not, I'll never test it.

\##Related WordPress hooks##

Brain init itself and its modules on `'after_setup_theme'` with priority 0, a reasonably early hook that can be used in plugin and themes. The Brain-related hooks are:

- `'brain_init'` to register modules (see above)
- `'brain_loaded'` is fired when all modules are loaded
- `'after_setup_theme'` with priority &gt;= 1 (or any later hook) to get data from the container

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community15

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

3737d 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 (37 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[ckfinder/ckfinder-laravel-package

CKFinder 3 package for Laravel

159497.2k48](/packages/ckfinder-ckfinder-laravel-package)[jaxon-php/jaxon-core

Jaxon is an open source PHP library for easily creating Ajax web applications

73142.3k25](/packages/jaxon-php-jaxon-core)[ckfinder/ckfinder-symfony-bundle

CKFinder bundle for Symfony

42435.7k](/packages/ckfinder-ckfinder-symfony-bundle)[inpsyde/wp-app-container

DI Container and related tools to be used at website level.

41253.5k](/packages/inpsyde-wp-app-container)[rockettheme/toolbox

RocketTheme Toolbox Library

22526.9k3](/packages/rockettheme-toolbox)[rochamarcelo/cake-pimple-di

A cakephp plugin for dependency injection based on Pimple library

12176.8k](/packages/rochamarcelo-cake-pimple-di)

PHPackages © 2026

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