/** * @param string $url * @return ServiceDescription */ public function createServiceDescription($url) { $serviceDescription = new ServiceDescription($url, $this->namespace); foreach ($this->serviceRegistry->getAllServices() as $actionMetadata) { if (!$actionMetadata) { continue; } $actionDescription = new ActionDescription($actionMetadata->alias); foreach ($actionMetadata->methodMetadata as $methodMetadata) { /** @var MethodMetadata $methodMetadata */ if (!$methodMetadata->isMethod) { continue; } $parameters = array(); foreach ($methodMetadata->parameters as $parameter) { if (($class = $parameter->getClass()) === null || $class->name !== HttpRequest::class && $class->name !== DirectRequest::class && $class->name !== ArgumentValidationResult::class) { $parameters[] = $parameter->name; } } $actionDescription->addMethod(new MethodDescription($methodMetadata->name, $methodMetadata->isFormHandler, $parameters, $methodMetadata->hasNamedParams, $methodMetadata->isStrict)); } if (count($actionDescription->getMethods())) { $serviceDescription->addAction($actionDescription); } } return $serviceDescription; }
/** * @return ServiceDescription */ protected function createServiceDescription() { $d = new ServiceDescription('https://example.com/router'); $a1 = new ActionDescription('action1', array(new MethodDescription('method1'))); $d->addAction($a1); return $d; }
public function testSetAction() { $d = new ServiceDescription('https://example.com/router'); $a1 = new ActionDescription('action1', array(new MethodDescription('method1'))); $d->addAction($a1); $a2 = new ActionDescription('action2', array(new MethodDescription('method1'))); $a3 = new ActionDescription('action3', array(new MethodDescription('method1'))); $d->setActions(array($a2, $a3)); $this->assertCount(2, $d->getActions()); $this->assertJsonStringEqualsJsonString(json_encode(array('type' => 'remoting', 'url' => 'https://example.com/router', 'namespace' => 'Ext.global', 'actions' => array('action2' => array(array('name' => 'method1', 'len' => 0)), 'action3' => array(array('name' => 'method1', 'len' => 0))))), json_encode($d)); }