PHPackages                             hazbo/moodswing - 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. hazbo/moodswing

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

hazbo/moodswing
===============

Turns moods into colours

216PHP

Since Jun 25Pushed 13y ago2 watchersCompare

[ Source](https://github.com/hazbo/moodswing2)[ Packagist](https://packagist.org/packages/hazbo/moodswing)[ RSS](/packages/hazbo-moodswing/feed)WikiDiscussions master Synced 4w ago

READMEChangelogDependenciesVersions (1)Used By (0)

Moodswing 2
===========

[](#moodswing-2)

[![Build Status](https://camo.githubusercontent.com/78efdeefcf1b5abb8f1196e15efc9c0e5071e8b9f1ce3a8ac5234b4d736a4d7e/68747470733a2f2f7472617669732d63692e6f72672f68617a626f2f6d6f6f647377696e67322e706e67)](https://travis-ci.org/hazbo/moodswing2)[![Total Downloads](https://camo.githubusercontent.com/aef4a5545a7832716f94d41d77c66103663dac748a152b57df7e3879fcddcac9/68747470733a2f2f706f7365722e707567782e6f72672f68617a626f2f6d6f6f647377696e672f646f776e6c6f6164732e706e67)](https://packagist.org/packages/hazbo/moodswing)

The general idea behind moodswing is to simply allow the developer to 'pass' through a mood as a string i.e. `happy` and for it to return either the name of a colour, as a string, or the hex for that colour, that psychologically best represents that mood. Pretty straight forward.

- PSR-0
- PSR-1
- PSR-2
- PSR-3

Installation
------------

[](#installation)

Add `hazbo/moodswing` to your composer.json file

```
{
    "require" : {
        "hazbo/moodswing" : "dev-master"
    }
}

```

Then run: `php composer.phar install`or `update`

Usage
-----

[](#usage)

```
use Hazbo\Moodswing;

$moodswing = new Moodswing\Processor();
$moodswing->getColourFor('happy');

```

Given that the colour data has been added to the JSON file, the example above will return something like:

```
array(2) {
  ["colour"]=>
  string(4) "COLOUR"
  ["hex"]=>
  string(7) "HEX"
}

```

If we just need the hex, or the colour, we could do something like this:

```
$moodswing->getColourFor('happy', Moodswing::COLOUR);

```

Or:

```
$moodswing->getColourFor('happy', Moodswing::HEX);

```

And it will return a string for us. If you'd like to only use a few select moods for all functionality, you can use the register.

```
$moodswing->register(array(
    'happy', 'sad', 'chipper'
));

```

Doing this will only allow you to use those three moods for whatever it is you want to do. Want to get all moods?

```
$moodswing->getAllMoods();

```

### Logging

[](#logging)

Moodswing implements the PSR-3 `LoggerInterface`. If you'd like to enable logging, you can do so like this:

```
$moodswing->setLogger($logger);

```

A full worknig example, using Monolog, could look like this:

```
