<commit_before><?php

/**
 * AspectPHP_Transformation_Template_JoinPointHandler
 *
 * @category PHP
 * @package AspectPHP_Transformation
 * @author <NAME> <<EMAIL>>
 * @copyright 2012 <NAME>
 * @license http://www.opensource.org/licenses/BSD-3-Clause BSD License
 * @link https://github.com/Matthimatiker/AspectPHP
 * @since 04.04.2012
 */

/**
 * Contains code templates that will be weaved into classes.
 *
 * The templates are responsible for handling the JoinPoints
 * logic and act as a proxy for calls to the original methods.
 *
 * @category PHP
 * @package AspectPHP_Transformation
 * @author <NAME> <<EMAIL>>
 * @copyright 2012 <NAME>
 * @license http://www.opensource.org/licenses/BSD-3-Clause BSD License
 * @link https://github.com/Matthimatiker/AspectPHP
 * @since 04.04.2012
 */
class AspectPHP_Transformation_Template_JoinPointHandler
{
    
    /**
     * Handles method calls.
     *
     * Contains logic regarding the aspect and join point handling.
     *
     * This method is injected into all compiled classes. Otherwise it
     * would not be possible to forward to its private methods.
     *
     * @param string $method The name of the called method.
     * @param string $compiledMethod The name of the method that will be called internally.
     * @param object|string $context The context of the method call.
     * @param array(mixed) $args The method arguments.
     * @return mixed
     * @throws Exception If the original method or a join point throws an exception.
     */
    private static function _aspectPHPInternalHandleCall($method, $compiledMethod, $context, $args)
    {
        if (AspectPHP_Container::hasManager()) {
            $aspects = AspectPHP_Container::getManager()->getAspectsFor(__CLASS__ . '::' . $method);
        } else {
            $aspects = array();
        }
        if (count($aspects) === 0) {
            return call_user_func_array(array($context, $compiledMethod), $args);
        }
        $joinPoint = new AspectPHP_JoinPoint($method, $context);
        $joinPoint->setArguments($args);
        foreach ($aspects as $aspect) {
            /* @var $aspect AspectPHP_Aspect */
            $aspect->before($joinPoint);
        }
        try {
            $returnValue = call_user_func_array(array($context, $compiledMethod), $args);
            $joinPoint->setReturnValue($returnValue);
            foreach ($aspects as $aspect) {
                /* @var $aspect AspectPHP_Aspect */
                $aspect->afterReturning($joinPoint);
            }
            return $joinPoint->getReturnValue();
        } catch(Exception $e) {
            $joinPoint->setException($e);
            foreach ($aspects as $aspect) {
                /* @var $aspect AspectPHP_Aspect */
                $aspect->afterThrowing($joinPoint);
            }
            throw $e;
        }
    }
    
}<commit_msg>added method that forwards calls to the handler<commit_after><?php

/**
 * AspectPHP_Transformation_Template_JoinPointHandler
 *
 * @category PHP
 * @package AspectPHP_Transformation
 * @author <NAME> <<EMAIL>>
 * @copyright 2012 <NAME>
 * @license http://www.opensource.org/licenses/BSD-3-Clause BSD License
 * @link https://github.com/Matthimatiker/AspectPHP
 * @since 04.04.2012
 */

/**
 * Contains code templates that will be weaved into classes.
 *
 * The templates are responsible for handling the JoinPoints
 * logic and act as a proxy for calls to the original methods.
 *
 * @category PHP
 * @package AspectPHP_Transformation
 * @author <NAME> <<EMAIL>>
 * @copyright 2012 <NAME>
 * @license http://www.opensource.org/licenses/BSD-3-Clause BSD License
 * @link https://github.com/Matthimatiker/AspectPHP
 * @since 04.04.2012
 */
class AspectPHP_Transformation_Template_JoinPointHandler
{
    
    /**
     * Handles method calls.
     *
     * Contains logic regarding the aspect and join point handling.
     *
     * This method is injected into all compiled classes. Otherwise it
     * would not be possible to forward to its private methods.
     *
     * @param string $method The name of the called method.
     * @param string $compiledMethod The name of the method that will be called internally.
     * @param object|string $context The context of the method call.
     * @param array(mixed) $args The method arguments.
     * @return mixed
     * @throws Exception If the original method or a join point throws an exception.
     */
    private static function _aspectPHPInternalHandleCall($method, $compiledMethod, $context, $args)
    {
        if (AspectPHP_Container::hasManager()) {
            $aspects = AspectPHP_Container::getManager()->getAspectsFor(__CLASS__ . '::' . $method);
        } else {
            $aspects = array();
        }
        if (count($aspects) === 0) {
            return call_user_func_array(array($context, $compiledMethod), $args);
        }
        $joinPoint = new AspectPHP_JoinPoint($method, $context);
        $joinPoint->setArguments($args);
        foreach ($aspects as $aspect) {
            /* @var $aspect AspectPHP_Aspect */
            $aspect->before($joinPoint);
        }
        try {
            $returnValue = call_user_func_array(array($context, $compiledMethod), $args);
            $joinPoint->setReturnValue($returnValue);
            foreach ($aspects as $aspect) {
                /* @var $aspect AspectPHP_Aspect */
                $aspect->afterReturning($joinPoint);
            }
            return $joinPoint->getReturnValue();
        } catch(Exception $e) {
            $joinPoint->setException($e);
            foreach ($aspects as $aspect) {
                /* @var $aspect AspectPHP_Aspect */
                $aspect->afterThrowing($joinPoint);
            }
            throw $e;
        }
    }
    
    /**
     * Forwards method calls to the private method _aspectPHPInternalHandleCall().
     *
     * This method exists for testing purposes only.
     * See {@link _aspectPHPInternalHandleCall()} for details about the parameters.
     *
     * @param string $method
     * @param string $compiledMethod
     * @param object|string $context
     * @param array(mixed) $args
     * @return mixed
     */
    public static function forwardToHandleCall($method, $compiledMethod, $context, $args)
    {
        return self::_aspectPHPInternalHandleCall($method, $compiledMethod, $context, $args);
    }
    
}
{'fraction_non_alphanumeric': 0.11037735849056604, 'fraction_numerical': 0.008490566037735849, 'mean_word_length': 2.6060090702947845, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 35, 'https://': 4, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '531126', 'n_tokens_mistral': 1839, 'n_tokens_neox': 1776, 'n_words': 490}