Location: PHPKode > scripts > Super Proxy > super-proxy/SuperProxy.php
<?php
/**
 * This Software is open source and is published under GPL3
 *
 * @author Mathias Krieck hide@address.com
 */

/**
 * Proxy class for accessing private and protected members and functions
 */
class SuperProxy
{
    /**
     * Returns a Proxy class of $sSuperClassName that allows access to protected and private functions and members
     *
     * @param string $sSuperClassName class name
     * @param array  $aParams         constructor params
     *
     * @return object
     */
    public static function getInstance( $sSuperClassName, array $aParams = array() )
    {
        $sClass          = null;
        $sProxyClassName = "{$sSuperClassName}SUPERPROXY";

        if ( !class_exists( $sProxyClassName, false ) ) {

            $oReflection = new ReflectionClass( $sSuperClassName );

            $aClass = file( $oReflection->getFileName() );
            $iStart = $oReflection->getStartLine() - 1;
            $iEnd = $oReflection->getEndLine() - 1;

            foreach ( $aClass as $iKey => $sValue ) {
                if ( $iStart <= $iKey && $iKey <= $iEnd ) {
                    $sClass .= $sValue . PHP_EOL;
                }
            }

            $sClass = str_replace( $sSuperClassName, $sProxyClassName, $sClass );

            $sClass = preg_replace( '/(.*)(protected|private) (.*function|.*\$.*)/i', '$1public $3', $sClass );

            eval( $sClass );
        }

        if ( !empty( $aParams ) ) {
            $oClass = new ReflectionClass( $sProxyClassName );
            $oInstance = $oClass->newInstanceArgs( $aParams );
        } else {
            $oInstance = new $sProxyClassName();
        }

        return $oInstance;
    }
}
Return current item: Super Proxy