Download the PHP package brain/amygdala without Composer

On this page you can find all versions of the php package brain/amygdala. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package 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 to be embedded in larger projects.

It is part of the Brain Project 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, but more to Laravel 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, 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

Installation

You need Composer to install the package. It is hosted on Packagist, 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 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 module, and an http request is what makes WordPress (most web applications indeed) makes decision on what to do.

Developers & Contributors

Package is open to contributors and pull requests. It comes with a set of unit tests written for PHPUnit 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, a powerful mocking test utility.

License

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


All versions of amygdala with dependencies

PHP Build Version
Package Version
Requires php Version >=5.4
brain/brain Version ~0.1.0
brain/support Version ~0.1.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package brain/amygdala contains the following files

Loading the files please wait ...