2017 © Pedro Peláez
 

library property-access

Trait that automatically calls getters and setters for property access.

image

spekkionu/property-access

Trait that automatically calls getters and setters for property access.

  • Saturday, December 23, 2017
  • by spekkionu
  • Repository
  • 1 Watchers
  • 2 Stars
  • 19 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Property Access Trait

Build Status Code Coverage Scrutinizer Code Quality SensioLabsInsight, (*1)

Trait that automatically calls getters and setters for property access., (*2)

use Spekkionu\PropertyAccess\PropertyAccessTrait;

class ExampleClass
{
    use PropertyAccessTrait;

    private $name;

    private $email;

}

$example = new ExampleClass(); $example->name = 'Bob'; $example->email = 'bob@example.com'; echo $example->name; // Bob $example->fill(array( 'name' => 'Steve', 'email' => 'steve@example.com' )); echo $example->email; // steve@example.com

Getters and Setters will be called

You can even use Value Objects

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('bob@example.com');

The Versions

23/12 2017

dev-master

9999999-dev

Trait that automatically calls getters and setters for property access.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

access getter setter property

02/04 2015

0.4.0

0.4.0.0

Trait that automatically calls getters and setters for property access.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

access getter setter property