mgdigital / deconstructor
This package is abandoned and no longer maintained.
No replacement package was suggested.
There is no license information available for the latest version (v0.1.4) of this package.
v0.1.4
2016-06-02 13:41 UTC
Requires
- php: >=7.0
Requires (Dev)
None
Suggests
None
Provides
None
Conflicts
None
Replaces
None
This package is not auto-updated.
Last update: 2018-02-16 12:34:27 UTC
README
What?
Classes can have constructors, so why not deconstructors?
Why?
Allows an object to describe how it was instantiated, allowing identical copies to be created from its constructor arguments.
How?
<?php
class ValueObject implements MGDigital\Deconstructor\DeconstructorInterface
{
private $property;
public function __construct($property)
{
$this->property = $property;
}
public function deconstruct(): array
{
return [$this->property];
}
public function getProperty()
{
return $this->property;
}
}
$instance = new ValueObject('value');
$deconstruction = MGDigital\Deconstructor\Deconstruction::deconstruct($instance);
$copy = $deconstruction->construct();
echo $copy->getProperty(); // value