Esempio n. 1
0
 /**
  * Run the RPC and return its output
  *
  * @param  RPC       $rpc
  * @return array
  * @throws Exception when parameters are not valid
  */
 protected function dispatchRPC(RPC $rpc)
 {
     $response = array('type' => 'rpc', 'tid' => $rpc->getId(), 'action' => $rpc->getAction(), 'method' => $rpc->getMethod(), 'result' => null);
     if (!$this->api->hasAction($rpc->getAction())) {
         throw new Exception('Action ' . $rpc->getAction() . ' does not exist');
     }
     $action = $this->api->getAction($rpc->getAction());
     // Verify the method exists
     if (!$action->hasMethod($rpc->getMethod())) {
         throw new Exception('Method ' . $rpc->getMethod() . ' does not exist');
     }
     // Verify that we received enough parameters to call the method
     if ($action->getMethod($rpc->getMethod())->getNumberOfParameters() > count($rpc->getData())) {
         throw new Exception('Invalid parameter count');
     }
     $object = $this->manager->get($action->getObjectName());
     // Trigger a RPC dispatch event
     $eventVars = array('object' => $object, 'rpc' => $rpc);
     $result = $this->getEventManager()->trigger(DirectEvent::EVENT_DISPATCH_RPC, $this, $eventVars);
     if ($result->stopped()) {
         return $result->last();
     }
     try {
         // Fetch result from the function call
         $response['result'] = call_user_func_array(array($object, $rpc->getMethod()), $rpc->getData());
     } catch (Exception $e) {
         $error = array('type' => 'exception', 'message' => 'An unhandled exception occured', 'where' => '');
         if ($this->isDebugMode()) {
             $error['message'] = $e->getMessage();
             $error['where'] = $e->getTraceAsString();
         }
         $response = $error;
     }
     return $response;
 }
Esempio n. 2
0
    $doctrineParser->registerAnnotation('KJSencha\\Annotation\\Interval');
    $doctrineParser->registerAnnotation('KJSencha\\Annotation\\Formhandler');
    $doctrineParser->registerAnnotation('KJSencha\\Annotation\\Group');
    $annotationManager = new AnnotationManager();
    $annotationManager->attach($doctrineParser);
    return $annotationManager;
}, 'kjsencha.apibuilder' => function (ServiceLocatorInterface $sl) {
    /* @var $annotationManager AnnotationManager */
    $annotationManager = $sl->get('kjsencha.annotationmanager');
    /* @var $directManager DirectManager */
    $directManager = $sl->get('kjsencha.direct.manager');
    return new ApiBuilder($annotationManager, $directManager);
}, 'kjsencha.cache' => function (ServiceLocatorInterface $sl) {
    $config = $sl->get('Config');
    $storage = StorageFactory::factory($config['kjsencha']['cache']);
    return $storage;
}, 'kjsencha.bootstrap' => function (ServiceLocatorInterface $sl) {
    $config = $sl->get('Config');
    $bootstrap = new Bootstrap($config['kjsencha']['bootstrap']['default']);
    $bootstrap->addVariables(array('App' => array('basePath' => $sl->get('Request')->getBasePath())));
    /* @var $directApi \KJSencha\Direct\Remoting\Api\Api */
    $directApi = $sl->get('kjsencha.api');
    $bootstrap->setDirectApi($directApi);
    return $bootstrap;
}, 'kjsencha.direct.manager' => function (ServiceManager $sm) {
    $directManager = new DirectManager();
    $directManager->addPeeringServiceManager($sm);
    return $directManager;
}, 'kjsencha.echo' => function () {
    return new TestEchoService('Hello ');
}));