7#include "dispatchtypepath_p.h"
12#include <QRegularExpression>
15using namespace Qt::Literals::StringLiterals;
19 , d_ptr(new DispatchTypePathPrivate)
32 const static QRegularExpression multipleSlashes(u
"/{1,}"_s);
34 QVector<QStringList> table;
36 auto keys = d->paths.keys();
39 keys, [](QStringView a, QStringView b) {
return a.compare(b, Qt::CaseInsensitive) < 0; });
40 for (
const auto &path : std::as_const(keys)) {
41 const auto paths = d->paths.value(path);
42 for (
Action *action : paths.actions) {
43 QString _path = u
'/' + path;
44 if (action->
attribute(u
"Args"_s).isEmpty()) {
45 _path.append(u
"/...");
51 _path.replace(multipleSlashes, u
"/"_s);
53 QString privateName = action->
reverse();
54 if (!privateName.startsWith(u
'/')) {
55 privateName.prepend(u
'/');
58 table.append({_path, privateName});
62 return Utils::buildTable(table,
67 u
"Loaded Path actions:"_s);
75 auto it = d->paths.constFind(path);
76 if (it == d->paths.constEnd()) {
81 int numberOfArgs = args.size();
82 for (
Action *action : it->actions) {
111 const auto range = attributes.equal_range(u
"Path"_s);
112 for (
auto i = range.first; i != range.second; ++i) {
113 if (d->registerPath(*i, action)) {
125 return !d->paths.isEmpty();
131 if (captures.isEmpty()) {
133 auto it = attributes.constFind(u
"Path"_s);
134 if (it != attributes.constEnd()) {
135 const QString &path = it.value();
136 if (path.isEmpty()) {
138 }
else if (!path.startsWith(u
'/')) {
148bool DispatchTypePathPrivate::registerPath(
const QString &path,
Action *action)
150 QString _path = path;
152 if (_path.isEmpty()) {
154 }
else if (!_path.startsWith(u
'/')) {
158 auto it = paths.find(_path);
159 if (it != paths.end()) {
161 auto &actions = it->actions;
162 bool conflict = std::ranges::any_of(actions, [&](
const Action *regAction) {
164 qCCritical(CUTELYST_DISPATCHER_PATH)
165 <<
"Not registering Action" << action->
name() <<
"of controller"
166 << action->
controller()->objectName() <<
"because it conflicts with"
167 << regAction->
name() <<
"of controller"
177 actions.push_back(action);
178 std::ranges::sort(actions, [](
const Action *a,
const Action *b) ->
bool {
183 DispatchTypePathReplacement{
191#include "moc_dispatchtypepath.cpp"
This class represents a Cutelyst Action.
virtual qint8 numberOfArgs() const
ParamsMultiMap attributes() const noexcept
Controller * controller() const noexcept
QString attribute(const QString &name, const QString &defaultValue={}) const
QString reverse() const noexcept
QString name() const noexcept
~DispatchTypePath() override
DispatchTypePath(QObject *parent=nullptr)
QByteArray list() const override
MatchType match(Context *c, QStringView path, const QStringList &args) const override
QString uriForAction(Action *action, const QStringList &captures) const override
bool registerAction(Action *action) override
DispatchType(QObject *parent=nullptr)
void setupMatchedAction(Context *c, Action *action) const
void setArguments(const QStringList &arguments)
void setMatch(const QString &match)
The Cutelyst namespace holds all public Cutelyst API.