1. Go to this page and download the library: Download spekkionu/property-access library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
spekkionu / property-access example snippets
use Spekkionu\PropertyAccess\PropertyAccessTrait;
class ExampleClass
{
use PropertyAccessTrait;
private $name;
private $email;
}
use Spekkionu\PropertyAccess\PropertyAccessTrait;
class ExampleClass
{
use PropertyAccessTrait;
private $name;
private $email;
public function setEmail(EmailAddress $email){
$this->email = $email;
}
}
// Value Object
class EmailAddress
{
private $email;
public function __construct($email)
{
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new InvalidArgumentException('Not a valid email address.');
}
$this->email = $email;
}
public function getValue()
{
return $this->email;
}
public function __toString()
{
return $this->getValue();
}
}
// Usage
$example = new ExampleClass();
$example->email = new EmailAddress('[email protected]');
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.