Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 46 lines (39 sloc) 1.657 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
<?php

/**
* @author Ignas Rudaitis <ignas.rudaitis@gmail.com>
* @copyright 2010-2013 Ignas Rudaitis
* @license http://www.opensource.org/licenses/mit-license.html
* @link http://antecedent.github.com/patchwork
*/
namespace Patchwork\Preprocessor\Callbacks\Interceptor;

use Patchwork\Preprocessor\Callbacks\Generic;
use Patchwork\Interceptor;
use Patchwork\Utils;

const CALL_INTERCEPTION_CODE = '
$pwClosureName = __NAMESPACE__ ? __NAMESPACE__ . "\\{closure}" : "{closure}";
$pwClass = (__CLASS__ && __FUNCTION__ !== $pwClosureName) ? __CLASS__ : null;
$pwCalledClass = $pwClass ? \get_called_class() : null;
if (!empty(\Patchwork\Interceptor\State::$patches[$pwClass][__FUNCTION__])) {
$pwFrame = \count(\debug_backtrace(false));
if (\Patchwork\Interceptor\intercept($pwClass, $pwCalledClass, __FUNCTION__, $pwFrame, $pwResult)) {
return $pwResult;
}
}
unset($pwClass, $pwCalledClass, $pwResult, $pwClosureName, $pwFrame);
';

const SCHEDULED_PATCH_APPLICATION_CODE = '\Patchwork\Interceptor\applyScheduledPatches()';

function markPreprocessedFiles()
{
    return Generic\markPreprocessedFiles(Interceptor\State::$preprocessedFiles);
}

function injectCallInterceptionCode()
{
    return Generic\prependCodeToFunctions(Utils\condense(CALL_INTERCEPTION_CODE));
}

function injectScheduledPatchApplicationCode()
{
    return Generic\chain(array(
        Generic\injectFalseExpressionAtBeginnings(SCHEDULED_PATCH_APPLICATION_CODE),
        Generic\injectCodeAfterClassDefinitions(SCHEDULED_PATCH_APPLICATION_CODE . ';'),
    ));
}
Something went wrong with that request. Please try again.