thruster / data-modifier
Thruster DataModifier Component
1.0.0
2015-12-05 14:46 UTC
Requires
- php: >=7.0
Requires (Dev)
- phpunit/phpunit: ~5.0
This package is auto-updated.
Last update: 2024-11-14 03:31:57 UTC
README
[] (https://github.com/ThrusterIO/data-modifier/releases) [] (LICENSE) [] (https://travis-ci.org/ThrusterIO/data-modifier) [] (https://scrutinizer-ci.com/g/ThrusterIO/data-modifier) [] (https://scrutinizer-ci.com/g/ThrusterIO/data-modifier) [] (https://packagist.org/packages/thruster/data-modifier)
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.