Example #1
0
    /**
     * Allow extended Objects to be called in this Object context
     *
     * IMPORTANT!
     *
     * Watch out when use Fluent Interfaces, because the "bridging"
     * feature WILL return the METHOD called, not the invoker object
     *
     * @param string $method
     *   Method trying to be invoked
     *
     * @param array|optional $args
     *   Variable list of arguments to the method
     *
     * @return mixed|boolean
     *   Return what extended method returns
     *
     * @throws Next\Components\Debug\Exception
     *   Object Constructor was overwritten without invoking it through
     *   parent:: context
     */
    public function __call($method, array $args = array())
    {
        if (is_null($this->context)) {
            throw \Next\Components\Debug\Exception::unfullfilledRequirements('<p>
                    Method <strong>%s</strong> is not known by
                    <strong>%s</strong> and was not trapped by
                    <em>__call()</em>.
                </p>

                <p>
                    Could you possibly overwrote <em>Object::__construct()</em>
                    without invoke it under parent context?
                </p>', array($method, $this));
        }
        // Trying to call as an extended method
        try {
            return $this->context->call($this, $method, $args);
        } catch (\Next\Components\Debug\Exception $e) {
            // Trying to call as a prototyped method
            return $this->call($this, $method, $args);
        }
    }