Passed
Push — master ( 17804e...9c6a95 )
by Fran
06:14
created

Router::getRoutes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace PSFS\base;
4
5
use PSFS\base\config\Config;
6
use PSFS\base\exception\AccessDeniedException;
7
use PSFS\base\exception\ConfigException;
8
use PSFS\base\exception\RouterException;
9
use PSFS\base\types\helpers\AdminHelper;
10
use PSFS\base\types\helpers\GeneratorHelper;
11
use PSFS\base\types\helpers\I18nHelper;
12
use PSFS\base\types\helpers\RequestHelper;
13
use PSFS\base\types\helpers\RouterHelper;
14
use PSFS\base\types\helpers\SecurityHelper;
15
use PSFS\base\types\SingletonTrait;
16
use PSFS\controller\base\Admin;
17
use PSFS\services\AdminServices;
18
use Symfony\Component\Finder\Finder;
19
20
21
/**
22
 * Class Router
23
 * @package PSFS
24
 */
25
class Router
26
{
27
28
    use SingletonTrait;
29
30
    protected $routing;
31
    protected $slugs;
32
    private $domains;
33
    /**
34
     * @var Finder $finder
35
     */
36
    private $finder;
37
    /**
38
     * @var \PSFS\base\Cache $cache
39
     */
40
    private $cache;
41
    /**
42
     * @var bool headersSent
43
     */
44
    protected $headersSent = false;
45
46
    /**
47
     * Constructor Router
48
     * @throws ConfigException
49
     */
50 6
    public function __construct()
51
    {
52 6
        $this->finder = new Finder();
53 6
        $this->cache = Cache::getInstance();
54 6
        $this->init();
55 6
    }
56
57
    /**
58
     * Inicializador Router
59
     * @throws ConfigException
60
     */
61 1
    public function init()
62
    {
63 1
        if (!file_exists(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json") || Config::getInstance()->getDebugMode()) {
64 1
            $this->hydrateRouting();
65 1
            $this->simpatize();
66
        } else {
67 1
            list($this->routing, $this->slugs) = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", Cache::JSON, TRUE);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 146 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
68 1
            $this->domains = $this->cache->getDataFromFile(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", Cache::JSON, TRUE);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 129 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
69 1
            $this->checkExternalModules(false);
70
        }
71 1
    }
72
73
    /**
74
     * Método que deriva un error HTTP de página no encontrada
75
     *
76
     * @param \Exception $e
77
     *
78
     * @return string HTML
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
79
     */
80
    public function httpNotFound(\Exception $e = NULL)
0 ignored issues
show
Comprehensibility introduced by
Avoid variables with short names like $e. Configured minimum length is 3.

Short variable names may make your code harder to understand. Variable names should be self-descriptive. This check looks for variable names who are shorter than a configured minimum.

Loading history...
81
    {
82
        Logger::log('Throw not found exception');
83
        if (NULL === $e) {
84
            Logger::log('Not found page throwed without previous exception', LOG_WARNING);
85
            $e = new \Exception(_('Page not found'), 404);
86
        }
87
        $template = Template::getInstance()->setStatus($e->getCode());
88
        if (preg_match('/json/i', Request::getInstance()->getServer('CONTENT_TYPE'))) {
89
            return $template->output(json_encode(array(
90
                "success" => FALSE,
91
                "error" => $e->getMessage(),
92
            )), 'application/json');
93
        } else {
94
            return $template->render('error.html.twig', array(
95
                'exception' => $e,
96
                'trace' => $e->getTraceAsString(),
97
                'error_page' => TRUE,
98
            ));
99
        }
100
    }
101
102
    /**
103
     * Método que devuelve las rutas
104
     * @return string|null
105
     */
106
    public function getSlugs()
107
    {
108
        return $this->slugs;
109
    }
110
111
    /**
112
     * @return mixed
113
     */
114 1
    public function getRoutes() {
115 1
        return $this->routing;
116
    }
117
118
    /**
119
     * Method that extract all routes in the platform
120
     * @return array
121
     */
122
    public function getAllRoutes()
123
    {
124
        $routes = [];
125
        foreach ($this->getRoutes() as $path => $route) {
126
            if (array_key_exists('slug', $route)) {
127
                $routes[$route['slug']] = $path;
128
            }
129
        }
130
        return $routes;
131
    }
132
133
    /**
134
     * Método que calcula el objeto a enrutar
135
     *
136
     * @param string|null $route
137
     *
138
     * @throws \Exception
139
     * @return string HTML
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
140
     */
141
    public function execute($route)
142
    {
143
        Logger::log('Executing the request');
144
        try {
145
            //Check CORS for requests
146
            RequestHelper::checkCORS();
147
            // Checks restricted access
148
            SecurityHelper::checkRestrictedAccess($route);
149
            //Search action and execute
150
            $this->searchAction($route);
151
        } catch (AccessDeniedException $e) {
152
            Logger::log(_('Solicitamos credenciales de acceso a zona restringida'));
153
            return Admin::staticAdminLogon($route);
154
        } catch (RouterException $r) {
155
            Logger::log($r->getMessage(), LOG_WARNING);
156
        } catch (\Exception $e) {
157
            Logger::log($e->getMessage(), LOG_ERR);
158
            throw $e;
159
        }
160
161
        return $this->httpNotFound();
162
    }
163
164
    /**
165
     * Método que busca el componente que ejecuta la ruta
166
     *
167
     * @param string $route
168
     *
169
     * @throws \PSFS\base\exception\RouterException
170
     */
171
    protected function searchAction($route)
172
    {
173
        Logger::log('Searching action to execute: ' . $route, LOG_INFO);
174
        //Revisamos si tenemos la ruta registrada
175
        $parts = parse_url($route);
176
        $path = (array_key_exists('path', $parts)) ? $parts['path'] : $route;
177
        $httpRequest = Request::getInstance()->getMethod();
178
        foreach ($this->routing as $pattern => $action) {
179
            list($httpMethod, $routePattern) = RouterHelper::extractHttpRoute($pattern);
180
            $matched = RouterHelper::matchRoutePattern($routePattern, $path);
181
            if ($matched && ($httpMethod === "ALL" || $httpRequest === $httpMethod) && RouterHelper::compareSlashes($routePattern, $path)) {
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 140 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
182
                $get = RouterHelper::extractComponents($route, $routePattern);
183
                /** @var $class \PSFS\base\types\Controller */
184
                $class = RouterHelper::getClassToCall($action);
185
                try {
186
                    $this->executeCachedRoute($route, $action, $class, $get);
187
                } catch (\Exception $e) {
188
                    Logger::log($e->getMessage(), LOG_ERR);
189
                    throw new RouterException($e->getMessage(), 404, $e);
190
                }
191
            }
192
        }
193
        throw new RouterException(_("Ruta no encontrada"));
194
    }
195
196
    /**
197
     * Método que manda las cabeceras de autenticación
198
     * @return string HTML
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
199
     */
200
    protected function sentAuthHeader()
201
    {
202
        return AdminServices::getInstance()->setAdminHeaders();
203
    }
204
205
    /**
206
     * Method that check if the proyect has sub project to include
207
     * @param boolean $hydrateRoute
208
     */
209 1
    private function checkExternalModules($hydrateRoute = true)
210
    {
211 1
        $externalModules = Config::getParam('modules.extend');
212 1
        if (null !== $externalModules) {
213
            $externalModules = explode(',', $externalModules);
214
            foreach ($externalModules as &$module) {
215
                $module = preg_replace('/(\\\|\/)/', DIRECTORY_SEPARATOR, $module);
216
                $externalModulePath = VENDOR_DIR . DIRECTORY_SEPARATOR . $module . DIRECTORY_SEPARATOR . 'src';
217
                if (file_exists($externalModulePath)) {
218
                    $externalModule = $this->finder->directories()->in($externalModulePath)->depth(0);
219
                    if (!empty($externalModule)) {
220
                        foreach ($externalModule as $modulePath) {
221
                            $extModule = $modulePath->getBasename();
222
                            $moduleAutoloader = realpath($externalModulePath . DIRECTORY_SEPARATOR . $extModule . DIRECTORY_SEPARATOR . 'autoload.php');
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 152 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
223
                            if (file_exists($moduleAutoloader)) {
224
                                @include $moduleAutoloader;
225
                                if ($hydrateRoute) {
226
                                    $this->routing = $this->inspectDir($externalModulePath . DIRECTORY_SEPARATOR . $extModule, '\\' . $extModule, $this->routing);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 162 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
227
                                }
228
                            }
229
                        }
230
                    }
231
                }
232
            }
233
        }
234 1
    }
235
236
    /**
237
     * Method that gather all the routes in the project
238
     */
239 1
    private function generateRouting()
240
    {
241 1
        $base = SOURCE_DIR;
242 1
        $modulesPath = realpath(CORE_DIR);
243 1
        $this->routing = $this->inspectDir($base, "PSFS", array());
244 1
        if (file_exists($modulesPath)) {
245
            $modules = $this->finder->directories()->in($modulesPath)->depth(0);
246
            foreach ($modules as $modulePath) {
247
                $module = $modulePath->getBasename();
248
                $this->routing = $this->inspectDir($modulesPath . DIRECTORY_SEPARATOR . $module, $module, $this->routing);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 122 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
249
            }
250
        }
251 1
        $this->checkExternalModules();
252 1
        $this->cache->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "domains.json", $this->domains, Cache::JSON, TRUE);
253 1
    }
254
255
    /**
256
     * Método que regenera el fichero de rutas
257
     * @throws ConfigException
258
     */
259 1
    public function hydrateRouting()
260
    {
261 1
        $this->generateRouting();
262 1
        $home = Config::getInstance()->get('home_action');
263 1
        if (NULL !== $home || $home !== '') {
264 1
            $home_params = NULL;
265 1
            foreach ($this->routing as $pattern => $params) {
266 1
                list($method, $route) = RouterHelper::extractHttpRoute($pattern);
267 1
                if (preg_match("/" . preg_quote($route, "/") . "$/i", "/" . $home)) {
268 1
                    $home_params = $params;
269
                }
270
            }
271 1
            if (NULL !== $home_params) {
272
                $this->routing['/'] = $home_params;
273
            }
274
        }
275 1
    }
276
277
    /**
278
     * Método que inspecciona los directorios en busca de clases que registren rutas
279
     *
280
     * @param string $origen
281
     * @param string $namespace
282
     * @param array $routing
283
     *
284
     * @return array
285
     * @throws ConfigException
286
     */
287 1
    private function inspectDir($origen, $namespace = 'PSFS', $routing = [])
288
    {
289 1
        $files = $this->finder->files()->in($origen)->path('/(controller|api)/i')->depth(1)->name("*.php");
290 1
        foreach ($files as $file) {
291 1
            $filename = str_replace("/", '\\', str_replace($origen, '', $file->getPathname()));
292 1
            $routing = $this->addRouting($namespace . str_replace('.php', '', $filename), $routing, $namespace);
293
        }
294 1
        $this->finder = new Finder();
295
296 1
        return $routing;
297
    }
298
299
    /**
300
     * Checks that a namespace exists
301
     * @param string $namespace
302
     * @return bool
303
     */
304 1
    public static function exists($namespace)
305
    {
306 1
        return (class_exists($namespace) || interface_exists($namespace) || trait_exists($namespace));
307
    }
308
309
    /**
310
     * Método que añade nuevas rutas al array de referencia
311
     *
312
     * @param string $namespace
313
     * @param array $routing
314
     * @param string $module
315
     *
316
     * @return array
317
     * @throws ConfigException
318
     */
319 1
    private function addRouting($namespace, &$routing, $module = 'PSFS')
320
    {
321 1
        if (self::exists($namespace)) {
322 1
            $reflection = new \ReflectionClass($namespace);
323 1
            if (FALSE === $reflection->isAbstract() && FALSE === $reflection->isInterface()) {
324 1
                $this->extractDomain($reflection);
325 1
                $classComments = $reflection->getDocComment();
326 1
                preg_match('/@api\ (.*)\n/im', $classComments, $apiPath);
327 1
                $api = '';
328 1
                if (count($apiPath)) {
329
                    $api = array_key_exists(1, $apiPath) ? $apiPath[1] : $api;
330
                }
331 1
                foreach ($reflection->getMethods(\ReflectionMethod::IS_PUBLIC) as $method) {
332 1
                    if (preg_match('/@route\ /i', $method->getDocComment())) {
333 1
                        list($route, $info) = RouterHelper::extractRouteInfo($method, str_replace('\\', '', $api), str_replace('\\', '', $module));
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 147 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
334
335 1
                        if (null !== $route && null !== $info) {
336 1
                            $info['class'] = $namespace;
337 1
                            $routing[$route] = $info;
338
                        }
339
                    }
340
                }
341
            }
342
        }
343
344 1
        return $routing;
345
    }
346
347
    /**
348
     * Método que extrae de la ReflectionClass los datos necesarios para componer los dominios en los templates
349
     *
350
     * @param \ReflectionClass $class
351
     *
352
     * @return Router
353
     * @throws ConfigException
354
     */
355 1
    protected function extractDomain(\ReflectionClass $class)
356
    {
357
        //Calculamos los dominios para las plantillas
358 1
        if ($class->hasConstant("DOMAIN") && !$class->isAbstract()) {
359 1
            if (!$this->domains) {
360 1
                $this->domains = [];
361
            }
362 1
            $domain = "@" . $class->getConstant("DOMAIN") . "/";
363 1
            if (!array_key_exists($domain, $this->domains)) {
364 1
                $this->domains[$domain] = RouterHelper::extractDomainInfo($class, $domain);
365
            }
366
        }
367
368 1
        return $this;
369
    }
370
371
    /**
372
     * Método que genera las urls amigables para usar dentro del framework
373
     * @return Router
374
     */
375 1
    public function simpatize()
376
    {
377 1
        $translationFileName = "translations" . DIRECTORY_SEPARATOR . "routes_translations.php";
378 1
        $absoluteTranslationFileName = CACHE_DIR . DIRECTORY_SEPARATOR . $translationFileName;
379 1
        $this->generateSlugs($absoluteTranslationFileName);
380 1
        GeneratorHelper::createDir(CONFIG_DIR);
381 1
        Cache::getInstance()->storeData(CONFIG_DIR . DIRECTORY_SEPARATOR . "urls.json", array($this->routing, $this->slugs), Cache::JSON, TRUE);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 144 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
382
383 1
        return $this;
384
    }
385
386
    /**
387
     * Método que devuelve una ruta del framework
388
     *
389
     * @param string $slug
390
     * @param boolean $absolute
391
     * @param array $params
392
     *
393
     * @return string|null
394
     * @throws RouterException
395
     */
396 1
    public function getRoute($slug = '', $absolute = FALSE, $params = [])
397
    {
398 1
        if (strlen($slug) === 0) {
399
            return ($absolute) ? Request::getInstance()->getRootUrl() . '/' : '/';
400
        }
401 1
        if (NULL === $slug || !array_key_exists($slug, $this->slugs)) {
402
            throw new RouterException(_("No existe la ruta especificada"));
403
        }
404 1
        $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->slugs[$slug] : $this->slugs[$slug];
405 1
        if (!empty($params)) foreach ($params as $key => $value) {
406
            $url = str_replace("{" . $key . "}", $value, $url);
407 1
        } elseif (!empty($this->routing[$this->slugs[$slug]]["default"])) {
408 1
            $url = ($absolute) ? Request::getInstance()->getRootUrl() . $this->routing[$this->slugs[$slug]]["default"] : $this->routing[$this->slugs[$slug]]["default"];
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 168 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
409
        }
410
411 1
        return preg_replace('/(GET|POST|PUT|DELETE|ALL)\#\|\#/', '', $url);
412
    }
413
414
    /**
415
     * Método que devuelve las rutas de administración
416
     * @deprecated
417
     * @return array
418
     */
419
    public function getAdminRoutes()
420
    {
421
        return AdminHelper::getAdminRoutes($this->routing);
422
    }
423
424
    /**
425
     * Método que devuelve le controlador del admin
426
     * @deprecated
427
     * @return Admin
428
     */
429
    public function getAdmin()
430
    {
431
        return Admin::getInstance();
432
    }
433
434
    /**
435
     * Método que extrae los dominios
436
     * @return array
437
     */
438
    public function getDomains()
439
    {
440
        return $this->domains ?: [];
441
    }
442
443
    /**
444
     * Método que ejecuta una acción del framework y revisa si lo tenemos cacheado ya o no
445
     *
446
     * @param string $route
447
     * @param array|null $action
448
     * @param types\Controller $class
449
     * @param array $params
0 ignored issues
show
Documentation introduced by
Should the type for parameter $params not be array|null? Also, consider making the array more specific, something like array<String>, or String[].

This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.

It makes a suggestion as to what type it considers more descriptive. In addition it looks for parameters that have the generic type array and suggests a stricter type like array<String>.

Most often this is a case of a parameter that can be null in addition to its declared types.

Loading history...
450
     */
451
    protected function executeCachedRoute($route, $action, $class, $params = NULL)
452
    {
453
        Logger::log('Executing route ' . $route, LOG_INFO);
454
        Security::getInstance()->setSessionKey("__CACHE__", $action);
455
        $cache = Cache::needCache();
456
        $execute = TRUE;
457
        if (FALSE !== $cache && Config::getInstance()->getDebugMode() === FALSE) {
458
            $cacheDataName = $this->cache->getRequestCacheHash();
459
            $tmpDir = substr($cacheDataName, 0, 2) . DIRECTORY_SEPARATOR . substr($cacheDataName, 2, 2) . DIRECTORY_SEPARATOR;
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 126 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
460
            $cachedData = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $tmpDir . $cacheDataName,
461
                $cache, function () {
0 ignored issues
show
Bug introduced by
It seems like $cache defined by \PSFS\base\Cache::needCache() on line 455 can also be of type boolean; however, PSFS\base\Cache::readFromCache() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
462
                });
463
            if (NULL !== $cachedData) {
464
                $headers = $this->cache->readFromCache("json" . DIRECTORY_SEPARATOR . $tmpDir . $cacheDataName . ".headers",
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 124 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
465
                    $cache, function () {
0 ignored issues
show
Bug introduced by
It seems like $cache defined by \PSFS\base\Cache::needCache() on line 455 can also be of type boolean; however, PSFS\base\Cache::readFromCache() does only seem to accept integer, maybe add an additional type check?

If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:

/**
 * @return array|string
 */
function returnsDifferentValues($x) {
    if ($x) {
        return 'foo';
    }

    return array();
}

$x = returnsDifferentValues($y);
if (is_array($x)) {
    // $x is an array.
}

If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.

Loading history...
466
                    }, Cache::JSON);
467
                Template::getInstance()->renderCache($cachedData, $headers);
468
                $execute = FALSE;
469
            }
470
        }
471
        if ($execute) {
472
            Logger::log(_('Start executing action'), LOG_DEBUG);
473
            if (false === call_user_func_array(array($class, $action['method']), $params)) {
474
                Logger::log(_('An error ocurred trying to execute the action'), LOG_ERR, [error_get_last()]);
475
            }
476
        }
477
    }
478
479
    /**
480
     * Parse slugs to create translations
481
     *
482
     * @param string $absoluteTranslationFileName
483
     */
484 1
    private function generateSlugs($absoluteTranslationFileName)
485
    {
486 1
        $translations = I18nHelper::generateTranslationsFile($absoluteTranslationFileName);
487 1
        foreach ($this->routing as $key => &$info) {
488 1
            $keyParts = $key;
489 1
            if (FALSE === strstr("#|#", $key)) {
490 1
                $keyParts = explode("#|#", $key);
491 1
                $keyParts = array_key_exists(1, $keyParts) ? $keyParts[1] : '';
492
            }
493 1
            $slug = RouterHelper::slugify($keyParts);
494 1
            if (NULL !== $slug && !array_key_exists($slug, $translations)) {
495 1
                $translations[$slug] = $key;
496 1
                file_put_contents($absoluteTranslationFileName, "\$translations[\"{$slug}\"] = _(\"{$slug}\");\n", FILE_APPEND);
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 128 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
497
            }
498 1
            $this->slugs[$slug] = $key;
499 1
            $info["slug"] = $slug;
500
        }
501 1
    }
502
503
}
504