2017 © Pedro Peláez
 

library property-exposer

Give access to private properties based on phpDoc directives.

image

adagio/property-exposer

Give access to private properties based on phpDoc directives.

  • Wednesday, November 29, 2017
  • by Keven
  • Repository
  • 0 Watchers
  • 1 Stars
  • 304 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 5 Versions
  • 107 % Grown

The README.md

adagio/property-exposer

adagio/property-exposer gives access to private properties based on phpDoc directives., (*1)

The goal is to avoid getters and setters in the class body and keep only meaningful action methods:, (*2)

<?php

// Before

class Foo
{
    private $bar, $baz;

    public function setBar($value)
    {
        $this->bar = $value;
    }

    public function getBar()
    {
        return $this->bar;
    }

    public function getBaz()
    {
        return $this->baz;
    }

    public function doSomething()
    {
        // ...
    }
}

// After

/**
 *
 * @property int $bar Bar
 * @property-read string $baz Baz
 */
class Foo
{
    use PropertyExposerTrait;

    private $bar, $baz;

    public function doSomething()
    {
        // ...
    }
}

Domain methods appears immediatly, easying code understanding and maintenance., (*3)

One consequence is that DTO objects have no more methods, they appears for what their are: values transporters..., (*4)

Installation

The recommended way to install adagio/property-exposer is through Composer:, (*5)

composer require adagio/property-exposer

After installing, you need to require Composer's autoloader., (*6)

Usage

<?php

use Adagio\PropertyExposer\PropertyExposerTrait;

/**
 *
 * @property int $bar Bar
 * @property-read string $baz Baz
 */
final class Foo
{
    use PropertyExposerTrait;

    /**
     *
     * @var int
     */
    private $bar = 7;

    /**
     *
     * @var string
     */
    private $baz = 'test';
}

$foo = new Foo;

echo $foo->bar."\n"; // 7
$foo->bar = 1;
echo $foo->bar."\n"; // 1

echo $foo->baz."\n"; // "test"
$foo->baz = 'test2'; // Exception...
echo $foo->baz."\n";

The Versions

29/11 2017

dev-master

9999999-dev https://github.com/adagiolabs/property-exposer

Give access to private properties based on phpDoc directives.

  Sources   Download

MIT

The Requires

 

by Avatar Keven

getter setter accessor mutator property

29/11 2017

1.2.0

1.2.0.0 https://github.com/adagiolabs/property-exposer

Give access to private properties based on phpDoc directives.

  Sources   Download

MIT

The Requires

 

by Avatar Keven

getter setter accessor mutator property

27/11 2017

1.1.0

1.1.0.0 https://github.com/adagiolabs/property-exposer

Give access to private properties based on phpDoc directives.

  Sources   Download

MIT

The Requires

 

by Avatar Keven

getter setter accessor mutator property

06/01 2017

1.0.1

1.0.1.0 https://github.com/adagiolabs/property-exposer

Give access to private properties based on phpDoc directives.

  Sources   Download

MIT

The Requires

 

by Avatar Keven

getter setter accessor mutator property

06/01 2017

1.0.0

1.0.0.0 https://github.com/adagiolabs/property-exposer

Give access to private properties based on phpDoc directives.

  Sources   Download

MIT

The Requires

 

by Avatar Keven

getter setter accessor mutator property