2017 © Pedro Peláez
 

library setter

Set private object attributes directly, without calling setter methods.

image

grottopress/setter

Set private object attributes directly, without calling setter methods.

  • Saturday, March 3, 2018
  • by akadusei
  • Repository
  • 1 Watchers
  • 0 Stars
  • 6 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 10 Versions
  • 0 % Grown

The README.md

Setter

Description

Setter allows you to set private object attributes directly, without calling setter methods., (*1)

For example, instead of calling $myObject->setMyAttr($newValue), you can just do $myObject->myAttr = $newValue. Under the hood, Setter sets your attribute by calling a private setMyAttr() method that you define in your class., (*2)

This way, you get the benefit of syntactic sugar, while maintaining encapsulation., (*3)

Installation

Install via composer:, (*4)

composer require grottopress/setter

Usage

Import trait into your class, and use thus:, (*5)

<?php
declare (strict_types = 1);

namespace Vendor;

use GrottoPress\Setter\SetterTrait;

class MyClass {
    /**
     * Import trait
     */
    use SetterTrait;

    private $changeMe;
    private $leaveMeAlone;

    /**
     * Define your private setter method
     * Method name should be of the format "set{$attrName}"
     */
    private function setChangeMe($newValue)
    {
        $this->changeMe = $newValue;
    }

    // ...
}

// Instantiate
$object = new Vendor\MyClass();

// Try to set attributes
$object->changeMe = 'New Me!'; // => Works!
$object->leaveMeAlone = 'xyz'; // => Error: 'setLeaveMeAlone()' not defined

Development

Run tests with composer run test., (*6)

Contributing

  1. Fork it
  2. Switch to the master branch: git checkout master
  3. Create your feature branch: git checkout -b my-new-feature
  4. Make your changes, updating changelog and documentation as appropriate.
  5. Commit your changes: git commit
  6. Push to the branch: git push origin my-new-feature
  7. Submit a new Pull Request against the GrottoPress:master branch.

The Versions

03/03 2018

dev-master

9999999-dev

Set private object attributes directly, without calling setter methods.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

setter 00p

03/03 2018

dev-dev

dev-dev

Set private object attributes directly, without calling setter methods.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

setter 00p

03/03 2018

0.4.2

0.4.2.0

Set private object attributes directly, without calling setter methods.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

setter 00p

01/03 2018

0.4.1

0.4.1.0

Set private object attributes directly, without calling setter methods.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

setter 00p

28/02 2018

0.4.0

0.4.0.0

Set private object attributes directly, without calling setter methods.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

setter 00p

25/11 2017

0.3.1

0.3.1.0

Set private object attributes directly, without calling setter methods.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

setter 00p

09/11 2017

0.3.0

0.3.0.0

Set private object attributes directly, without calling setter methods.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

setter 00p

11/08 2017

0.2.0

0.2.0.0

A simple library to set/update object attributes

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

setter oop

08/08 2017

0.1.1

0.1.1.0

A simple library to set/update object attributes

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

setter oop

06/08 2017

0.1.0

0.1.0.0

A simple library to set/update object attributes

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires