/** * PHP method calls overloading * * This method will reroute all the call on this object to the SOAP server * object. * * @param string The name of the called method * @param array The arguments for the called method * @return mixed The result of the SOAP server method called * @throws Woops_Soap_Server_Exception If the called method does not exist */ public function __call($name, array $args = array()) { // Checks if the method can be called if (!is_callable(array($this->_soapServer, $name))) { // Called method does not exist throw new Woops_Soap_Server_Exception('The method \'' . $name . '\' cannot be called on the PDO object', Woops_Soap_Server_Exception::EXCEPTION_BAD_METHOD); } // Creates a callback $callback = new Woops_Core_Callback(array($this->_soapServer, $name)); // Invokes the callback and returns it's result return $callback->invoke($args); }
/** * Calls a specific join point * * This method is used to redirect calls on a specific join point to it's * internal method, executing all available AOP advices registered for * the join point. * * @param string The name of the join point to invoke * @param array The arguments to pass to the join point method * @return mixed The return value of the join point method * @throws Woops_Core_Aop_Advisor_Exception If the called join point has not been registered */ public function __call($name, array $args = array()) { // Checks if the join point has been registered if (!isset(self::$_joinPoints[$this->_className][$this->_objectHash][$name])) { // Error - The join point has not been registered throw new Woops_Core_Aop_Advisor_Exception('No joint point named ' . $name . '. Call to undefined method ' . $this->_className . '::' . $name . '()', Woops_Core_Aop_Advisor_Exception::EXCEPTION_NO_JOINPOINT); } // Gets the method to use and the allowed advices type for the join point $method = self::$_joinPoints[$this->_className][$this->_objectHash][$name][0]; $allowedAdviceType = self::$_joinPoints[$this->_className][$this->_objectHash][$name][1]; // Creates a callback for the internal method $methodCallback = new Woops_Core_Callback(array($this, $method)); // Creates a reflection object for the internal method $ref = Woops_Core_Reflection_Method::getInstance($this, $method); // By default, the call on the join point internal method is allowed $valid = true; // Checks if we can have advices to validate the call to the internal method if (self::ADVICE_TYPE_VALID_CALL & $allowedAdviceType) { // Process each validation advice foreach (self::$_advices[self::ADVICE_TYPE_VALID_CALL][$this->_className][$name] as $advice) { // Checks if the advice can be called on the current instance if ($advice[1] === false || $advice[1] === $this->_objectHash) { // Invokes the validation advice $valid = $advice[0]->invoke($args); // Checks if an advice is preventing the execution of the internal method if ($valid === false) { // Internal method won't be executed - No need to process the following advices break; } } } } // Checks if the internal method can be executed if ($valid) { // Checks if we can have advices before the call to the internal method if (self::ADVICE_TYPE_BEFORE_CALL & $allowedAdviceType) { // Process each 'beforeCall' advice foreach (self::$_advices[self::ADVICE_TYPE_BEFORE_CALL][$this->_className][$name] as $advice) { // Checks if the advice can be called on the current instance if ($advice[1] === false || $advice[1] === $this->_objectHash) { // Invokes the advice $advice[0]->invoke($args); } } } // Flag to know if an exception was thrown $exceptionThrown = false; // We are catching exceptions from the internal method, so we'll be able to run the 'afterThrowing' advices try { // Checks if the internal method returns a reference if ($ref->returnsReference()) { // Gets the return value of the internal method $returnValue =& $methodCallback->invoke($args); } else { // Gets the return value of the internal method $returnValue = $methodCallback->invoke($args); } } catch (Exception $e) { // An exception was thrown $exceptionThrown = true; // Checks if we can have advices to catch exceptions thrown from the internal method, and if so, if such advices are available if (!count(self::$_advices[self::ADVICE_TYPE_AFTER_THROWING][$this->_className][$name]) || !(self::ADVICE_TYPE_AFTER_THROWING & $allowedAdviceType)) { // No - Throws the original exception back throw $e; } else { // Boolean value to check if the exception has been caught, and so should not be thrown $exceptionCaught = false; // Process each 'afterThrowing' advice foreach (self::$_advices[self::ADVICE_TYPE_AFTER_THROWING][$this->_className][$name] as $advice) { // Checks if the advice can be called on the current instance if ($advice[1] === false || $advice[1] === $this->_objectHash) { // Invokes the advice $exceptionCaught = $advice[0]->invoke(array($e, $this)); // Checks if the exception has been caught by the advice if ($exceptionCaught === true) { // Exception was caught - Do not executes the next advices break; } } } // Checks if the exception has been caught by the advice if ($exceptionCaught !== true) { // Exception was not caught by an advice - Throws it back throw $e; } } } // Checks if we have a return value, meaning no exception was thrown if (!$exceptionThrown) { // Checks if we ca have advices that will be able to modify the return value of the internal method if (self::ADVICE_TYPE_BEFORE_RETURN & $allowedAdviceType) { // Process each 'beforeReturn' advice foreach (self::$_advices[self::ADVICE_TYPE_BEFORE_RETURN][$this->_className][$name] as $advice) { // Checks if the advice can be called on the current instance if ($advice[1] === false || $advice[1] === $this->_objectHash) { // Invokes the advice and stores the return value $returnValue = $advice[0]->invoke(array($returnValue, $args)); } } } // Checks if we can have advices after the call to the internal method if (self::ADVICE_TYPE_AFTER_CALL & $allowedAdviceType) { // Process each 'afterCall' advice foreach (self::$_advices[self::ADVICE_TYPE_AFTER_CALL][$this->_className][$name] as $advice) { // Checks if the advice can be called on the current instance if ($advice[1] === false || $advice[1] === $this->_objectHash) { // Invokes the advice $advice[0]->invoke($args); } } } // Returns the return value return $returnValue; } } }
/** * PHP method calls overloading * * This method will reroute all the call on this object to the ADODB object. * * @param string The name of the called method * @param array The arguments for the called method * @return mixed The result of the ADODB method called * @throws Woops_Mod_Adodb_Database_Engine_Exception If the called method does not exist */ public function __call($name, array $args = array()) { // Checks if the method can be called if (!is_callable(array($this->_adodb, $name))) { // Called method does not exist throw new Woops_Mod_Adodb_Database_Engine_Exception('The method \'' . $name . '\' cannot be called on the ADODB object', Woops_Mod_Adodb_Database_Engine_Exception::EXCEPTION_BAD_METHOD); } // Creates a callback $callback = new Woops_Core_Callback(array($this->_adodb, $name)); // Not sure ADODB is completely error free $this->_errorReporting->disableErrorReporting(E_NOTICE | E_STRICT); // Invokes the callback and returns it's result $ret = $callback->invoke($args); // Resets the error reporting $this->_errorReporting->resetErrorReporting(); return $ret; }