-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43 from antecedent/redefinition-of-internals
Merge redefinition of internals into master
- Loading branch information
Showing
27 changed files
with
1,122 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,114 +1,136 @@ | ||
<?php | ||
|
||
/** | ||
* @author Ignas Rudaitis <ignas.rudaitis@gmail.com> | ||
* @copyright 2010-2016 Ignas Rudaitis | ||
* @license http://www.opensource.org/licenses/mit-license.html | ||
*/ | ||
namespace Patchwork; | ||
|
||
require_once __DIR__ . '/src/Exceptions.php'; | ||
require_once __DIR__ . '/src/CallRerouting.php'; | ||
require_once __DIR__ . '/src/CodeManipulation.php'; | ||
require_once __DIR__ . '/src/Utils.php'; | ||
require_once __DIR__ . '/src/Stack.php'; | ||
require_once __DIR__ . '/src/Config.php'; | ||
|
||
function redefine($what, callable $asWhat) | ||
{ | ||
return CallRerouting\connect($what, $asWhat); | ||
} | ||
|
||
function relay(array $args = null) | ||
{ | ||
return CallRerouting\relay($args); | ||
} | ||
|
||
function fallBack() | ||
{ | ||
throw new Exceptions\NoResult; | ||
} | ||
|
||
function restore(CallRerouting\Handle $handle) | ||
{ | ||
$handle->expire(); | ||
} | ||
|
||
function restoreAll() | ||
{ | ||
CallRerouting\disconnectAll(); | ||
} | ||
|
||
function silence(CallRerouting\Handle $handle) | ||
{ | ||
$handle->silence(); | ||
} | ||
|
||
function getClass() | ||
{ | ||
return Stack\top('class'); | ||
} | ||
|
||
function getCalledClass() | ||
{ | ||
return Stack\topCalledClass(); | ||
} | ||
|
||
function getFunction() | ||
{ | ||
return Stack\top('function'); | ||
} | ||
|
||
function getMethod() | ||
{ | ||
return getClass() . '::' . getFunction(); | ||
} | ||
|
||
function configure() | ||
{ | ||
Config\locate(); | ||
} | ||
|
||
function hasMissed($callable) | ||
{ | ||
return Utils\callableWasMissed($callable); | ||
} | ||
|
||
Utils\alias('Patchwork', [ | ||
'redefine' => ['replace', 'replaceLater'], | ||
'relay' => 'callOriginal', | ||
'fallBack' => 'pass', | ||
'restore' => 'undo', | ||
'restoreAll' => 'undoAll', | ||
]); | ||
|
||
configure(); | ||
|
||
Utils\markMissedCallables(); | ||
|
||
if (Utils\runningOnHHVM()) { | ||
# no preprocessor needed on HHVM; | ||
# just let Patchwork become a wrapper for fb_intercept() | ||
spl_autoload_register('Patchwork\CallRerouting\deployQueue'); | ||
return; | ||
} | ||
|
||
CodeManipulation\Stream::wrap(); | ||
|
||
CodeManipulation\register([ | ||
CodeManipulation\Actions\CodeManipulation\propagateThroughEval(), | ||
CodeManipulation\Actions\CallRerouting\injectCallInterceptionCode(), | ||
CodeManipulation\Actions\CallRerouting\injectQueueDeploymentCode(), | ||
]); | ||
|
||
CodeManipulation\onImport([ | ||
CodeManipulation\Actions\CallRerouting\markPreprocessedFiles(), | ||
]); | ||
|
||
Utils\clearOpcodeCaches(); | ||
|
||
register_shutdown_function('Patchwork\Utils\clearOpcodeCaches'); | ||
|
||
if (Utils\wasRunAsConsoleApp()) { | ||
require __DIR__ . '/src/Console.php'; | ||
} | ||
<?php | ||
|
||
/** | ||
* @author Ignas Rudaitis <ignas.rudaitis@gmail.com> | ||
* @copyright 2010-2016 Ignas Rudaitis | ||
* @license http://www.opensource.org/licenses/mit-license.html | ||
*/ | ||
namespace Patchwork; | ||
|
||
require_once __DIR__ . '/src/Exceptions.php'; | ||
require_once __DIR__ . '/src/CallRerouting.php'; | ||
require_once __DIR__ . '/src/CodeManipulation.php'; | ||
require_once __DIR__ . '/src/Utils.php'; | ||
require_once __DIR__ . '/src/Stack.php'; | ||
require_once __DIR__ . '/src/Config.php'; | ||
|
||
function redefine($subject, callable $content) | ||
{ | ||
$handle = null; | ||
foreach (array_slice(func_get_args(), 1) as $content) { | ||
$handle = CallRerouting\connect($subject, $content, $handle); | ||
} | ||
$handle->silence(); | ||
return $handle; | ||
} | ||
|
||
function relay(array $args = null) | ||
{ | ||
return CallRerouting\relay($args); | ||
} | ||
|
||
function fallBack() | ||
{ | ||
throw new Exceptions\NoResult; | ||
} | ||
|
||
function restore(CallRerouting\Handle $handle) | ||
{ | ||
$handle->expire(); | ||
} | ||
|
||
function restoreAll() | ||
{ | ||
CallRerouting\disconnectAll(); | ||
} | ||
|
||
function silence(CallRerouting\Handle $handle) | ||
{ | ||
$handle->silence(); | ||
} | ||
|
||
function assertEventuallyDefined(CallRerouting\Handle $handle) | ||
{ | ||
$handle->unsilence(); | ||
} | ||
|
||
function getClass() | ||
{ | ||
return Stack\top('class'); | ||
} | ||
|
||
function getCalledClass() | ||
{ | ||
return Stack\topCalledClass(); | ||
} | ||
|
||
function getFunction() | ||
{ | ||
return Stack\top('function'); | ||
} | ||
|
||
function getMethod() | ||
{ | ||
return getClass() . '::' . getFunction(); | ||
} | ||
|
||
function configure() | ||
{ | ||
Config\locate(); | ||
} | ||
|
||
function hasMissed($callable) | ||
{ | ||
return Utils\callableWasMissed($callable); | ||
} | ||
|
||
function always($value) | ||
{ | ||
return function() use ($value) { | ||
return $value; | ||
}; | ||
} | ||
|
||
Utils\alias('Patchwork', [ | ||
'redefine' => ['replace', 'replaceLater'], | ||
'relay' => 'callOriginal', | ||
'fallBack' => 'pass', | ||
'restore' => 'undo', | ||
'restoreAll' => 'undoAll', | ||
]); | ||
|
||
configure(); | ||
|
||
Utils\markMissedCallables(); | ||
|
||
if (Utils\runningOnHHVM()) { | ||
# no preprocessor needed on HHVM; | ||
# just let Patchwork become a wrapper for fb_intercept() | ||
spl_autoload_register('Patchwork\CallRerouting\deployQueue'); | ||
return; | ||
} | ||
|
||
CodeManipulation\Stream::wrap(); | ||
|
||
CodeManipulation\register([ | ||
CodeManipulation\Actions\CodeManipulation\propagateThroughEval(), | ||
CodeManipulation\Actions\CallRerouting\injectCallInterceptionCode(), | ||
CodeManipulation\Actions\CallRerouting\injectQueueDeploymentCode(), | ||
CodeManipulation\Actions\RedefinitionOfInternals\spliceNamedFunctionCalls(), | ||
CodeManipulation\Actions\RedefinitionOfInternals\spliceDynamicCalls(), | ||
]); | ||
|
||
CodeManipulation\onImport([ | ||
CodeManipulation\Actions\CallRerouting\markPreprocessedFiles(), | ||
]); | ||
|
||
Utils\clearOpcodeCaches(); | ||
|
||
register_shutdown_function('Patchwork\Utils\clearOpcodeCaches'); | ||
|
||
CallRerouting\createStubsForInternals(); | ||
CallRerouting\connectDefaultInternals(); | ||
|
||
if (Utils\wasRunAsConsoleApp()) { | ||
require __DIR__ . '/src/Console.php'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.