Changeset View
Changeset View
Standalone View
Standalone View
src/applications/conduit/call/ConduitCall.php
| Show First 20 Lines • Show All 162 Lines • ▼ Show 20 Lines | if (!$this->shouldForceLocal() && $this->servers) { | ||||
| return $this->handler->executeMethod($this->request); | return $this->handler->executeMethod($this->request); | ||||
| } | } | ||||
| } | } | ||||
| protected function pickRandomServer($servers) { | protected function pickRandomServer($servers) { | ||||
| return $servers[array_rand($servers)]; | return $servers[array_rand($servers)]; | ||||
| } | } | ||||
| protected function buildMethodHandler($method) { | protected function buildMethodHandler($method_name) { | ||||
| $method_class = ConduitAPIMethod::getClassNameFromAPIMethodName($method); | $method = ConduitAPIMethod::getConduitMethod($method_name); | ||||
| // Test if the method exists. | if (!$method) { | ||||
| $ok = false; | |||||
| try { | |||||
| $ok = class_exists($method_class); | |||||
| } catch (Exception $ex) { | |||||
| // Discard, we provide a more specific exception below. | |||||
| } | |||||
| if (!$ok) { | |||||
| throw new ConduitException( | |||||
| "Conduit method '{$method}' does not exist."); | |||||
| } | |||||
| $class_info = new ReflectionClass($method_class); | |||||
| if ($class_info->isAbstract()) { | |||||
| throw new ConduitException( | |||||
| "Method '{$method}' is not valid; the implementation is an abstract ". | |||||
| "base class."); | |||||
| } | |||||
| $method = newv($method_class, array()); | |||||
| if (!($method instanceof ConduitAPIMethod)) { | |||||
| throw new ConduitException( | throw new ConduitException( | ||||
| "Method '{$method_class}' is not valid; the implementation must be ". | "Conduit method '{$method_name}' does not exist."); | ||||
| "a subclass of ConduitAPIMethod."); | |||||
| } | } | ||||
| $application = $method->getApplication(); | $application = $method->getApplication(); | ||||
| if ($application && !$application->isInstalled()) { | if ($application && !$application->isInstalled()) { | ||||
| $app_name = $application->getName(); | $app_name = $application->getName(); | ||||
| throw new ConduitException( | throw new ConduitException( | ||||
| "Method '{$method_class}' belongs to application '{$app_name}', ". | "Method '{$method_name}' belongs to application '{$app_name}', ". | ||||
| "which is not installed."); | "which is not installed."); | ||||
| } | } | ||||
| return $method; | return $method; | ||||
| } | } | ||||
| } | } | ||||