Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
14 / 14
Proxiable
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
3 / 3
6
100.00% covered (success)
100.00%
14 / 14
 __call
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
11 / 11
 __set
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
 __get
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
1 / 1
<?php
/**
 * AMF (http://amf.artera.it/).
 *
 * @link      http://amf.artera.it
 *
 * @copyright Copyright (c) 2012-2013 Artera
 * @license   http://amf.artera.it/LICENSE.txt MIT License
 */
namespace Amf\Proxy;
/**
 * Proxy trait.
 *
 * @author  Massimiliano Torromeo
 */
trait Proxiable
{
    protected $object;
    /**
     * Function calls proxy method.
     *
     * This function should never be called manually. Just call the original
     * function names instead.
     *
     * @param string $name      The method name
     * @param array  $arguments The method arguments
     *
     * @return mixed The proxied method result
     */
    public function __call($name, $arguments)
    {
        if (!method_exists($this->object, $name) && !method_exists($this->object, '__call')) {
            $class = get_class($this->object);
            $trace = debug_backtrace();
            $file = $trace[0]['file'];
            $line = $trace[0]['line'];
            trigger_error("Call to undefined method $class::$name() in $file on line $line", E_USER_ERROR);
        } else {
            $references = [];
            foreach ($arguments as $i => &$arg) {
                $references[] = &$arg;
            }
            return call_user_func_array([$this->object, $name], $arguments);
        }
    }
    /**
     * Property setter proxy method.
     *
     * This function should never be called manually. Just access the original
     * object properties instead.
     *
     * @param string $name  The property name
     * @param array  $value The value to set the property to
     */
    public function __set($name, $value)
    {
        $this->object->$name = $value;
    }
    /**
     * Property getter proxy method.
     *
     * This function should never be called manually. Just access the original
     * object properties instead.
     *
     * @param string $name The property name
     *
     * @return mixed The proxied object property
     */
    public function __get($name)
    {
        return $this->object->$name;
    }
}