thruster/data-modifier

Thruster DataModifier Component

1.0.0 2015-12-05 14:46 UTC

This package is auto-updated.

Last update: 2024-11-14 03:31:57 UTC


README

[Latest Version] (https://github.com/ThrusterIO/data-modifier/releases) [Software License] (LICENSE) [Build Status] (https://travis-ci.org/ThrusterIO/data-modifier) [Code Coverage] (https://scrutinizer-ci.com/g/ThrusterIO/data-modifier) [Quality Score] (https://scrutinizer-ci.com/g/ThrusterIO/data-modifier) [Total Downloads] (https://packagist.org/packages/thruster/data-modifier)

[Email] (mailto:team@thruster.io)

The Thruster DataModifier Component.

Install

Via Composer

$ composer require thruster/data-modifier

Usage

The sample code to understand working principle:

<?PHP

use Thruster\Component\DataModifier\DataModifierInterface;
use Thruster\Component\DataModifier\DataModifierGroup;

$user = new class {
    protected $username = 'foo_bar';
    protected $password = 'youwillnotguessit';
    protected $activationCode;

    public function getPassword()
    {
        return $this->password;
    }

    public function setPassword($password)
    {
        $this->password = $password;
    }

    public function setActivationCode($activationCode)
    {
        $this->activationCode = $activationCode;
    }
};

$passwordHasher = new class implements DataModifierInterface {
    public function modify($input)
    {
        $input->setPassword(password_hash($input->getPassword(), PASSWORD_BCRYPT));

        return $input;
    }
};

$activationCodegenerator = new class implements DataModifierInterface {
    public function modify($input)
    {
        $input->setActivationCode(substr(md5(strrev(microtime(true))), 0, 12));

        return $input;
    }
};

$modifierGroup = new DataModifierGroup();
$modifierGroup->addModifier($passwordHasher, 1);
$modifierGroup->addModifier($activationCodegenerator);

var_dump($modifierGroup->modify($user));
class class@anonymous#2 (3) {
  protected $username =>
  string(7) "foo_bar"
  protected $password =>
  string(60) "$2y$10$B1F39njifACQcr68osihIeMM0Ps/yAlOrGiEdb.KGgVqBWMARiDqm"
  protected $activationCode =>
  string(12) "25018c42dd5d"
}

Testing

$ composer test

Contributing

Please see CONTRIBUTING and CONDUCT for details.

License

Please see License File for more information.