Skip to content
This repository has been archived by the owner on Jul 8, 2023. It is now read-only.

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Feb 9, 2014
2 parents a854350 + 1a27b58 commit 8d71b1f
Show file tree
Hide file tree
Showing 33 changed files with 1,816 additions and 1,120 deletions.
2 changes: 1 addition & 1 deletion .travis.env
@@ -1 +1 @@
Ob4Tk/LbPO+MA2+t5gzLmh+/9Q7hPOsMdoAkrIrIS9NJuN7j+Njf2rg3yPq9TZjXpbGnQaR0avSaiCfpjkVfWMOYYtyU6Duotgp71lpshQhM3owIifkEfqRhh3mP/sOnTjcW9bpD2A/97u3mK9Gc2nyw1nNIn5egD85VJ10KYis=
pTSn8XE11MNuOBzY6d53r/8q20eT+HAtllIOn4q3Jp9nsxlzTx9ORQvwT8LBiDW8TTY87h+TuwawA9AYA/tA0QWPAkI3lD9HqW5/DS0p1aS9ssRywq5KJXs/N8MaqTUfom+RdPkpCwSvAYxWcjy9CXkp+zYVwPPZpg7x2k1rxuY=
50 changes: 33 additions & 17 deletions .travis.install
@@ -1,26 +1,42 @@
#!/usr/bin/env php
<?php
/**
* This script is executed before composer dependencies are installed,
* and as such must be included in each project as part of the skeleton.
*/
if ($token = getenv('ARCHER_TOKEN')) {
$config = array(
'config' => array(
'github-oauth' => array('github.com' => $token)
)
);

$file = '~/.composer/config.json';
$dir = dirname($file);
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
file_put_contents($file, json_encode($config));
// Update git to the latest version ...
passthru('sudo apt-get update');
passthru('sudo apt-get install git');

// Update composer to the latest version ...
passthru('composer self-update --no-interaction');

// Build a composer config that uses the GitHub OAuth token if it is available ...
$config = array(
'config' => array(
'notify-on-install' => false
)
);

if ($token = getenv('ARCHER_TOKEN')) {
$config['config']['github-oauth'] = array(
'github.com' => $token
);
$composerFlags = '--prefer-dist';
} else {
$composerFlags = '--prefer-source';
}

passthru('composer install --dev --no-progress --no-interaction --ansi ' . $composerFlags);
$file = '~/.composer/config.json';
$dir = dirname($file);
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
file_put_contents($file, json_encode($config));

// Display some information about GitHub rate limiting ...
if ($token) {
passthru('curl -s -i -H "Authorization: token $ARCHER_TOKEN" https://api.github.com | grep "^X-RateLimit"');
}

// Install composer dependencies ...
$exitCode = 0;
passthru('composer install --dev --no-progress --no-interaction --ansi ' . $composerFlags, $exitCode);
exit($exitCode);
27 changes: 8 additions & 19 deletions .travis.yml
@@ -1,29 +1,18 @@
#
# This is the default Travis CI configuration.
#
# It uses a GitHub OAuth token when fetching composer dependencies
# to avoid IP-based API throttling.
#
# It also allows publication of artifacts via an additional build.
#
language: php

php:
- 5.3
- 5.4
- 5.5
php: ["5.3", "5.4", "5.5", "hhvm"]

matrix:
allow_failures:
- php: hhvm

env:
global:
- ARCHER_PUBLISH_VERSION=5.4
- secure: "Ob4Tk/LbPO+MA2+t5gzLmh+/9Q7hPOsMdoAkrIrIS9NJuN7j+Njf2rg3yPq9TZjXpbGnQaR0avSaiCfpjkVfWMOYYtyU6Duotgp71lpshQhM3owIifkEfqRhh3mP/sOnTjcW9bpD2A/97u3mK9Gc2nyw1nNIn5egD85VJ10KYis="
- ARCHER_PUBLISH_VERSION=5.5
- secure: "pTSn8XE11MNuOBzY6d53r/8q20eT+HAtllIOn4q3Jp9nsxlzTx9ORQvwT8LBiDW8TTY87h+TuwawA9AYA/tA0QWPAkI3lD9HqW5/DS0p1aS9ssRywq5KJXs/N8MaqTUfom+RdPkpCwSvAYxWcjy9CXkp+zYVwPPZpg7x2k1rxuY="

install:
- ./.travis.install

script:
- ./vendor/bin/archer travis:build

matrix:
# PHP 5.5 is still in alpha, so ignore build failures.
allow_failures:
- php: 5.5
25 changes: 18 additions & 7 deletions CHANGELOG.md
@@ -1,14 +1,25 @@
# Liberator changelog

### 1.1.1
## 2.0.0 (2014-02-09)

* Added [icecave/archer](https://github.com/IcecaveStudios/archer) integration
* Repository maintenance
- **[BC BREAK]** Some class members that were previously protected are now
private. It is very unlikely that this affects anyone at all, but technically
it's backwards incompatible.
- **[NEW]** Added an interface for identifying liberator proxied values.
- **[NEW]** API documentation
- **[MAINTENANCE]** Repository maintenance

### 1.1.0
## 1.1.1 (2013-03-04)

* Improved API
- **[NEW]** Added [Archer] integration
- **[MAINTENANCE]** Repository maintenance

### 1.0.0
[Archer]: https://github.com/IcecaveStudios/archer

* Initial stable release
## 1.1.0 (2012-08-02)

- **[IMPROVED]** Improved API

## 1.0.0 (2012-08-02)

- **[NEW]** Initial stable release
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,4 +1,4 @@
Copyright © 2013 Erin Millard
Copyright © 2014 Erin Millard

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
70 changes: 39 additions & 31 deletions README.md
Expand Up @@ -2,32 +2,27 @@

*A proxy for circumventing PHP access modifier restrictions.*

[![Build status](https://raw.github.com/eloquent/liberator/gh-pages/artifacts/images/icecave/regular/build-status.png)](http://travis-ci.org/eloquent/liberator)
[![Test coverage](https://raw.github.com/eloquent/liberator/gh-pages/artifacts/images/icecave/regular/coverage.png)](http://eloquent.github.com/liberator/artifacts/tests/coverage)
[![The most recent stable version is 2.0.0][version-image]][Semantic versioning]
[![Current build status image][build-image]][Current build status]
[![Current coverage status image][coverage-image]][Current coverage status]

## Installation
## Installation and documentation

Available as [Composer](http://getcomposer.org/) package
[eloquent/liberator](https://packagist.org/packages/eloquent/liberator).
- Available as [Composer] package [eloquent/liberator].
- [API documentation] available.

## What is Liberator?

Liberator is an object proxy that allows you to access methods and properties
of an object or class that would normally be restricted by PHP. Essentially,
this means you ignore any 'private' or 'protected' keywords.
*Liberator* allows access to **protected** and **private** methods and
properties of objects as if they were marked **public**. It can do so for both
objects and classes (i.e. static methods and properties).

Liberator's primary use is as a testing tool. Unit tests can often be simplified
using a mix of partially mocked objects and Liberator.

Liberator is based upon the [Pops](https://github.com/eloquent/pops) object
proxy system.
*Liberator*'s primary use is as a testing tool, allowing direct access to
methods that would otherwise require complicated test harnesses or mocking to
test.

## Usage

Liberator allows access to **protected** and **private** methods and properties
of objects as if they were marked **public**. It can do so for both objects and
classes (i.e. static methods and properties).

### For objects

Take the following class:
Expand All @@ -37,24 +32,24 @@ class SeriousBusiness
{
private function foo($adjective)
{
return 'foo is '.$adjective;
return 'foo is ' . $adjective;
}

private $bar = 'mind';
}
```

Normally there is no way to call `foo()` or access `$bar` from outside the
`SeriousBusiness` class, but **Liberator** allows this to be achieved:
`SeriousBusiness` class, but *Liberator* allows this to be achieved:

```php
use Eloquent\Liberator\Liberator;

$object = new SeriousBusiness;
$liberator = Liberator::liberate($object);

echo $liberator->foo('not so private...'); // outputs 'foo is not so private...'
echo $liberator->bar.' = blown'; // outputs 'mind = blown'
echo $liberator->foo('not so private...'); // outputs 'foo is not so private...'
echo $liberator->bar . ' = blown'; // outputs 'mind = blown'
```

### For classes
Expand All @@ -66,41 +61,54 @@ class SeriousBusiness
{
static private function baz($adjective)
{
return 'baz is '.$adjective;
return 'baz is ' . $adjective;
}

static private $qux = 'mind';
}
```

To access these, a **class liberator** must be used instead of an
**object liberator**, but they operate in a similar manner:
To access these, a *class liberator* must be used instead of an *object
liberator*, but they operate in a similar manner:

```php
use Eloquent\Liberator\Liberator;

$liberator = Liberator::liberateClass('SeriousBusiness');

echo $liberator->baz('not so private...'); // outputs 'baz is not so private...'
echo $liberator->qux.' = blown'; // outputs 'mind = blown'
echo $liberator->baz('not so private...'); // outputs 'baz is not so private...'
echo $liberator->qux . ' = blown'; // outputs 'mind = blown'
```

Alternatively, Liberator can generate a class that can be used statically:
Alternatively, *Liberator* can generate a class that can be used statically:

```php
use Eloquent\Liberator\Liberator;

$liberatorClass = Liberator::liberateClassStatic('SeriousBusiness');

echo $liberatorClass::baz('not so private...'); // outputs 'baz is not so private...'
echo $liberatorClass::liberator()->qux.' = blown'; // outputs 'mind = blown'
echo $liberatorClass::liberator()->qux . ' = blown'; // outputs 'mind = blown'
```

Unfortunately, there is (currently) no __getStatic() or __setStatic() in PHP,
so accessing static properties in this way is a not as elegant as it could be.

## Applications for Liberator

* Writing [white-box](http://en.wikipedia.org/wiki/White-box_testing) style unit
tests (testing protected/private methods).
* Modifying behaviour of poorly designed third-party libraries.
- Writing [white-box] style unit tests (testing protected/private methods).
- Modifying behavior of poorly designed third-party libraries.

<!-- References -->

[white-box]: http://en.wikipedia.org/wiki/White-box_testing

[API documentation]: http://lqnt.co/liberator/artifacts/documentation/api/
[Composer]: http://getcomposer.org/
[build-image]: http://img.shields.io/travis/eloquent/liberator/develop.svg "Current build status for the develop branch"
[Current build status]: https://travis-ci.org/eloquent/liberator
[coverage-image]: http://img.shields.io/coveralls/eloquent/liberator/develop.svg "Current test coverage for the develop branch"
[Current coverage status]: https://coveralls.io/r/eloquent/liberator
[eloquent/liberator]: https://packagist.org/packages/eloquent/liberator
[Semantic versioning]: http://semver.org/
[version-image]: http://img.shields.io/:semver-2.0.0-brightgreen.svg "This project uses semantic versioning"
12 changes: 6 additions & 6 deletions composer.json
@@ -1,7 +1,7 @@
{
"name": "eloquent/liberator",
"description": "A proxy for circumventing PHP access modifier restrictions.",
"keywords": ["access","modifier","object","proxy","private","protected","reflection"],
"keywords": ["access", "modifier", "object", "proxy", "private", "protected", "reflection"],
"homepage": "https://github.com/eloquent/liberator",
"license": "MIT",
"authors": [
Expand All @@ -12,15 +12,15 @@
}
],
"require": {
"php": ">=5.3.0",
"eloquent/pops": "~3"
"php": ">=5.3",
"eloquent/pops": "~4.1.0"
},
"require-dev": {
"icecave/archer": "~0.2"
"icecave/archer": "~1"
},
"autoload": {
"psr-0": {
"Eloquent\\Liberator": "src"
"psr-4": {
"Eloquent\\Liberator\\": "src"
}
}
}

0 comments on commit 8d71b1f

Please sign in to comment.