2017 © Pedro Peláez
 

library getter

Get private object attributes directly, without calling getter methods.

image

grottopress/getter

Get private object attributes directly, without calling getter methods.

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

The README.md

Getter

Description

Getter allows you to get private object attributes directly, without calling getter methods., (*1)

For example, instead of calling $myObject->getMyAttr(), you can just do $myObject->myAttr. Under the hood, Getter gets your attribute by calling a private getMyAttr() 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: composer require grottopress/getter, (*4)

Usage

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

<?php
declare (strict_types = 1);

namespace Vendor;

use GrottoPress\Getter\GetterTrait;

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

    private $haveMe;
    private $leaveMeAlone;

    public function __construct()
    {
        $this->haveMe = 'Hello :-)';
        $this->leaveMeAlone = 'Go away!';
    }

    /**
     * Define your private getter method
     * Method name should be of the format "get{$attrName}"
     */
    private function getHaveMe(): string
    {
        return $this->haveMe;
    }

    // ...
}

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

// Try to get attributes
echo $object->haveMe; // => Hello :-)
echo $object->leaveMeAlone; // => Error: 'getLeaveMeAlone()' not defined
echo $object->nonExistent; // => Exception: 'nonExistent' does not exist

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

Get private object attributes directly, without calling getter methods.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

getter oop

03/03 2018

dev-dev

dev-dev

Get private object attributes directly, without calling getter methods.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

getter oop

03/03 2018

0.3.3

0.3.3.0

Get private object attributes directly, without calling getter methods.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

getter oop

01/03 2018

0.3.2

0.3.2.0

Get private object attributes directly, without calling getter methods.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

getter oop

28/02 2018

0.3.1

0.3.1.0

Get private object attributes directly, without calling getter methods.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

getter oop

28/02 2018

0.3.0

0.3.0.0

Get private object attributes directly, without calling getter methods.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

getter oop

25/11 2017

0.2.1

0.2.1.0

Get private object attributes directly, without calling getter methods.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

getter oop

09/11 2017

0.2.0

0.2.0.0

Get private object attributes directly, without calling getter methods.

  Sources   Download

MIT

The Requires

  • php >=7.0

 

The Development Requires

getter oop

08/08 2017

0.1.3

0.1.3.0

A simple library to get object attributes

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

getter oop

06/08 2017

0.1.2

0.1.2.0

A simple library to get object attributes

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

05/08 2017

0.1.1

0.1.1.0

A simple library to get object attributes

  Sources   Download

MIT

The Requires

  • php >=5.4

 

The Development Requires

05/08 2017

0.1.0

0.1.0.0

A simple library to get object attributes

  Sources   Download

MIT

The Requires

  • php >=5.4