2017 © Pedro Peláez
 

library patchwork

Method redefinition (monkey-patching) functionality for PHP.

image

antecedent/patchwork

Method redefinition (monkey-patching) functionality for PHP.

  • Monday, March 5, 2018
  • by antecedent
  • Repository
  • 15 Watchers
  • 349 Stars
  • 399,082 Installations
  • PHP
  • 25 Dependents
  • 0 Suggesters
  • 36 Forks
  • 15 Open issues
  • 40 Versions
  • 20 % Grown

The README.md

Patchwork

Patchwork implements the redefinition (monkey-patching) of functions and methods in PHP. This includes both user-defined and internal callables, which can be functions, class methods, or instance methods. In addition, many function-like constructs, such as exit or include, are supported in an analogous way., (*1)

Internally, Patchwork uses a stream wrapper on file://. In the case of user-defined functions and methods, it is used to inject a simple interceptor snippet to the beginning of every such callable. For the remaining types of callables, various other strategies are applied., (*2)

Example: a DIY profiler

use function Patchwork\{redefine, relay, getMethod};

$profiling = fopen('profiling.csv', 'w');

redefine('App\*', function(...$args) use ($profiling) {
    $begin = microtime(true);
    relay(); # calls the original definition
    $end = microtime(true);
    fputcsv($profiling, [getMethod(), $end - $begin]);
});

Notes

  • Method redefinition is the internally preferred metaphor for Patchwork's behavior.
  • restoreAll() and restore($handle) end the lifetime of, respectively, all redefinitions, or only one of them, where $handle = redefine(...).
  • Closure $this is automatically re-bound to the enclosing class of the method being redefined.
  • The behavior of __CLASS__, static::class etc. inside redefinitions disregards the metaphor. getClass(), getCalledClass(), getMethod() and getFunction() from the Patchwork namespace should be used instead.

Testing-related uses

Patchwork can be used to stub static methods, which, however, is a controversial practice., (*3)

It should be applied prudently, that is, only after making oneself familiar with its pitfalls and temptations in other programming languages. For instance, in Javascript, Ruby, Python and some others, the native support for monkey-patching has made its testing-related uses more commonplace than in PHP., (*4)

Tests that use monkey-patching are often no longer unit tests, because they become sensitive to details of implementation, not only those of interface: for example, such a test might no longer pass after switching from time() to DateTime., (*5)

That being said, they still have their place where the only economically viable alternative is having no tests at all., (*6)

Other use cases

Patchwork is not suggested for AOP and other kinds of production usage. Its impact on the application's performance is highly likely to be prohibitively large. Additionally, while no particular Patchwork-related security risks are either known or anticipated, please keep in mind that Patchwork was never developed with production environments in mind., (*7)

The Versions

05/03 2018

dev-readme

dev-readme http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

19/02 2018

dev-master

9999999-dev http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

19/02 2018

2.1.8

2.1.8.0 http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

21/12 2017

2.1.7

2.1.7.0 http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

05/11 2017

2.1.6

2.1.6.0 http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

11/09 2017

2.1.5

2.1.5.0 http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

02/09 2017

2.1.4

2.1.4.0 http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

30/08 2017

2.1.3

2.1.3.0 http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

29/08 2017

2.1.2

2.1.2.0 http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

29/08 2017

2.1.1

2.1.1.0 http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

27/08 2017

2.1.0

2.1.0.0 http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

27/08 2017

dev-redefinition-of-new

dev-redefinition-of-new http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

01/08 2017

2.0.9

2.0.9.0 http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

27/07 2017

2.0.8

2.0.8.0 http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

11/07 2017

2.0.7

2.0.7.0 http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

23/05 2017

2.0.6

2.0.6.0 http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

23/05 2017

dev-interception-of-language-constructs

dev-interception-of-language-constructs http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

22/05 2017

2.0.5

2.0.5.0 http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

03/05 2017

dev-interception-of-new

dev-interception-of-new http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

03/05 2017

2.0.4

2.0.4.0 http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

31/03 2017

dev-gh-pages-for-v2

dev-gh-pages-for-v2

  Sources   Download

23/03 2017

2.0.3

2.0.3.0 http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

22/03 2017

2.0.2

2.0.2.0 http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

09/03 2017

2.0.1

2.0.1.0 http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

12/08 2016

2.0.0

2.0.0.0 http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

12/08 2016

dev-redefinition-of-internals

dev-redefinition-of-internals http://patchwork2.org/

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

30/07 2016

dev-stream-filters

dev-stream-filters

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

02/07 2016

1.4.3

1.4.3.0

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

22/02 2016

1.4.2

1.4.2.0

Method redefinition (monkey-patching) functionality for PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

12/02 2016

1.4.1

1.4.1.0

Monkey-patching for PHP, in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

15/01 2016

1.4.0

1.4.0.0

Monkey-patching for PHP, in PHP.

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

09/10 2015

1.3.5

1.3.5.0 http://antecedent.github.io/patchwork/

A pure PHP library that lets you redefine user-defined functions at runtime.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

19/03 2015

1.3.4

1.3.4.0 http://antecedent.github.io/patchwork/

A pure PHP library that lets you redefine user-defined functions at runtime.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

07/08 2014

1.3.2

1.3.2.0 http://antecedent.github.io/patchwork/

A pure PHP library that lets you redefine user-defined functions at runtime.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

07/08 2014

1.3.1

1.3.1.0 http://antecedent.github.io/patchwork/

A pure PHP library that lets you redefine user-defined functions at runtime.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

07/08 2014

1.3.0

1.3.0.0 http://antecedent.github.io/patchwork/

A pure PHP library that lets you redefine user-defined functions at runtime.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Ignas Rudaitis

testing aop aspect runkit redefinition monkeypatching interception

04/08 2014

1.2.9

1.2.9.0 http://antecedent.github.io/patchwork/

A pure PHP library that lets you redefine user-defined functions at runtime.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Ignas Rudaitis

testing runkit redefinition monkeypatching

07/06 2014

1.2.8

1.2.8.0 http://antecedent.github.io/patchwork/

A pure PHP library that lets you redefine user-defined functions at runtime.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Ignas Rudaitis

testing runkit redefinition monkeypatching

21/09 2013

1.2.7

1.2.7.0 http://antecedent.github.io/patchwork/

A pure PHP library that lets you redefine user-defined functions at runtime.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Ignas Rudaitis

testing runkit redefinition monkeypatching

03/08 2013

1.2.6

1.2.6.0 http://antecedent.github.io/patchwork/

A pure PHP library that lets you redefine user-defined functions at runtime.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Ignas Rudaitis

testing runkit redefinition monkeypatching