2017 © Pedro Peláez
 

library access

Access - Tool for access to private and protected members of object. It's handy for unit tests.

image

petrp/access

Access - Tool for access to private and protected members of object. It's handy for unit tests.

  • Friday, October 11, 2013
  • by PetrP
  • Repository
  • 1 Watchers
  • 5 Stars
  • 2,919 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 5 % Grown

The README.md

Access

Tool for access to private and protected members of object. It's handy for unit tests., (*1)

Property

class Foo
{
    private $foo;
}

$a = Access(new Foo, '$foo');

$a->set(3);
assert($a->get() === 3);

Method

class Foo
{
    private function bar()
    {
        return 4;
    }
}

$a = Access(new Foo, 'bar');

assert($a->call() === 4);

Whole class

class Foo
{
    private $foo;

    private function bar($plus)
    {
        return $this->foo + $plus;
    }
}

$a = Access(new Foo);

$a->foo = 10;
assert($a->foo === 10);
assert($a->bar(1) === 11);

Chaining objects and arrays

class Foo
{
    private $foo;

    public function __construct()
    {
        $this->foo = ['arrayKey' => new Bar];
    }
}
class Bar
{
    private $bar;
}

$a = AccessProxy(new Foo);

$a->foo['arrayKey']->bar = 100;
assert($a->foo['arrayKey']->bar === 100);

assert($a->foo instanceof AccessProxy);
assert(is_array($a->foo->getInstance()));
assert($a->foo['arrayKey'] instanceof AccessProxy);
assert($a->foo['arrayKey']->getInstance() instanceof Bar);

Requirements

Library has no external dependencies., (*2)

Up to PHP <= 8.2 tested. Fully works with PHP >= 5.3.2. PHP >= 5.2.0 is supported partially (see below)., (*3)

AccessMethod require PHP 5.3.2 or later. AccessProperty require PHP 5.3.0 or later., (*4)

PHP >= 5.2.0 AND < 5.3.2 not supported: * Final classes. * Private methods. * Read private static property. * Write private property. * No limitation when extension runkit or classkit is provided., (*5)

Instalations

GitHub

Each version is tagged and available on download page., (*6)

require_once __DIR__ . '/.../Access/src/Init.php';

Composer & Packagist

Access is available on Packagist, where you can get it via Composer., (*7)

composer require petrp/access
require_once __DIR__ . '/vendor/autoload.php';

The Versions

11/10 2013

dev-master

9999999-dev https://github.com/PetrP/Access

Access - Tool for access to private and protected members of object. It's handy for unit tests.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.2.0

 

11/10 2013

v0.2.2

0.2.2.0 https://github.com/PetrP/Access

Access - Tool for access to private and protected members of object. It's handy for unit tests.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.2.0

 

23/04 2013

v0.2.1

0.2.1.0 https://github.com/PetrP/Access

Access - Tool for access to private and protected members of object. It's handy for unit tests.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.2.0

 

19/08 2012

v0.2.0

0.2.0.0 https://github.com/PetrP/Access

Access - Tool for access to private and protected members of object. It's handy for unit tests.

  Sources   Download

BSD-3-Clause

The Requires

  • php >=5.2.0