self::PAGE_HOME]; } // Post page: /a/{slug} if (preg_match('#^/a/([^/]+)$#', $path, $matches)) { return [ 'type' => self::PAGE_POST, 'slug' => $matches[1], ]; } // Category page: /{slug} if (preg_match('#^/([^/]+)/?$#', $path, $matches)) { $slug = $matches[1]; // Find category by slug foreach ($categories as $category) { if ($category->slug === $slug) { return [ 'type' => self::PAGE_CATEGORY, 'slug' => $slug, 'category' => $category, ]; } } // Slug doesn't match any category return ['type' => self::PAGE_NOT_FOUND]; } return ['type' => self::PAGE_NOT_FOUND]; } }