예제 #1
0
 /**
  * Invoke
  *
  * @return string
  */
 public function invoke()
 {
     SCA::$logger->log('Entering');
     //component_name, string reference_name, string method_name, array arguments
     //           Reflection::export(new ReflectionObject($this->mediator));
     try {
         // get the arguments from the mediator
         $arg_array = $this->mediator->getArgArray();
         if ($this->class_name != null) {
             SCA::$logger->log('Attempt to create a service');
             $this->service = new $this->class_name();
             $reflection = new ReflectionObject($this->service);
             $reader = new SCA_CommentReader($reflection->getDocComment());
             // if it's an SCA service recreate the instance
             // with all the references filled in
             if ($reader->isService()) {
                 SCA::$logger->log('Create SCA service');
                 $this->service = SCA::createInstanceAndFillInReferences($this->class_name);
             } else {
                 SCA::$logger->log('Create PHP object');
             }
         }
         //invoke the function
         if ($this->service != null) {
             SCA::$logger->log('Invoke service as PHP object');
             // it's a class with a member function
             // so call it. Even if it's an SCA service
             // we are not relying of SCA service bindings
             // at this point. We just want the references
             // that will have been set up on initialization
             // above.
             $return = call_user_func_array(array($this->service, $this->method_name), $arg_array);
         } else {
             if (function_exists($this->method_name)) {
                 SCA::$logger->log('Invoke service as PHP function');
                 // it's not just a script so turn
                 // off output buffering and then call
                 // the function
                 ob_end_clean();
                 $return = call_user_func_array($this->method_name, $arg_array);
             } else {
                 SCA::$logger->log('Invoke service as PHP script');
                 // the script will have already executed
                 // because it was included so all we have to
                 // do here is return the contents of the
                 // output buffer.
                 $return = ob_get_contents();
                 ob_end_clean();
             }
         }
     } catch (Exception $e) {
         SCA::$logger->log('Caught ' . $e->getMessage());
         throw $e;
     }
     SCA::$logger->log('Exiting');
     return $return;
 }