7 declare(strict_types=1);
26 private $allowedRouteMethods = [
41 $result = [self::KEY_SERVICES => []];
43 $services =
$source->getElementsByTagName(
'service');
46 if (!$this->canConvertXmlNode(
$service)) {
49 $serviceClass = $this->getServiceClass(
$service);
50 $serviceMethod = $this->getServiceMethod(
$service);
53 $this->initServiceMethodsKey(
$result, $serviceClass, $serviceMethod);
54 $this->mergeSynchronousInvocationMethodsData(
$service,
$result, $serviceClass, $serviceMethod);
69 private function mergeSynchronousInvocationMethodsData(
76 $result[self::KEY_SERVICES][$serviceClass][self::KEY_METHODS][$serviceMethod],
78 self::KEY_SYNCHRONOUS_INVOCATION_ONLY => $this->isSynchronousMethodInvocationOnly(
$service)
87 private function canConvertXmlNode(\DOMElement $node)
89 if ($node->nodeType !== XML_ELEMENT_NODE) {
93 if ($this->getServiceClass($node) ===
null) {
97 if ($this->getServiceMethod($node) ===
null) {
111 private function initServiceMethodsKey(array &
$result, $serviceClass, $serviceMethod)
113 if (!isset(
$result[self::KEY_SERVICES][$serviceClass])) {
117 if (!isset(
$result[self::KEY_SERVICES][$serviceClass][self::KEY_METHODS][$serviceMethod])) {
126 private function getServiceClass(\DOMElement
$service)
128 $serviceClass =
$service->attributes->getNamedItem(
'class')->nodeValue;
130 return mb_strlen((
string) $serviceClass) === 0 ? null : $serviceClass;
137 private function getServiceMethod(\DOMElement
$service)
139 $serviceMethod =
$service->attributes->getNamedItem(
'method')->nodeValue;
141 return mb_strlen((
string) $serviceMethod) === 0 ? null : $serviceMethod;
148 private function isSynchronousMethodInvocationOnly(\DOMElement $serviceNode)
150 $synchronousInvocationOnlyNodes = $serviceNode->getElementsByTagName(
'synchronousInvocationOnly');
152 return $this->isSynchronousInvocationOnlyTrue($synchronousInvocationOnlyNodes->item(0));
159 private function isSynchronousInvocationOnlyTrue(\DOMElement $synchronousInvocationOnlyNode =
null)
161 if ($synchronousInvocationOnlyNode ===
null) {
165 if (mb_strlen((
string) $synchronousInvocationOnlyNode->nodeValue) === 0) {
169 return filter_var($synchronousInvocationOnlyNode->nodeValue, FILTER_VALIDATE_BOOLEAN);
177 private function convertRouteCustomizations(
$source)
180 $routes =
$source->getElementsByTagName(
'route');
182 foreach ($routes as $route) {
183 $routeUrl = $this->getRouteUrl($route);
184 $routeMethod = $this->getRouteMethod($route);
185 $routeAlias = $this->getRouteAlias($route);
186 if ($routeUrl && $routeMethod && $routeAlias) {
187 if (!isset($customRoutes[$routeAlias])) {
188 $customRoutes[$routeAlias] = [];
190 $customRoutes[$routeAlias][$routeMethod] = $routeUrl;
193 return $customRoutes;
200 private function getRouteUrl($route)
202 $url = $route->attributes->getNamedItem(
'url')->nodeValue;
203 return mb_strlen((
string)
$url) === 0 ? null :
$url;
210 private function getRouteAlias($route)
212 $alias = $route->attributes->getNamedItem(
'alias')->nodeValue;
213 return mb_strlen((
string)
$alias) === 0 ? null : ltrim(
$alias,
'/');
220 private function getRouteMethod($route)
222 $method = $route->attributes->getNamedItem(
'method')->nodeValue;
231 private function validateRouteMethod(
$method)
233 return in_array(
$method, $this->allowedRouteMethods);
const KEY_SYNCHRONOUS_INVOCATION_ONLY