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
"/...");
47 for (
int i = 0; i < action->numberOfArgs(); ++i) {
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, {u
"Path"_s, u
"Private"_s}, u
"Loaded Path actions:"_s);
70 auto it = d->paths.constFind(path);
71 if (it == d->paths.constEnd()) {
76 int numberOfArgs = args.size();
77 for (
Action *action : it->actions) {
81 if (action->numberOfArgs() == numberOfArgs) {
87 }
else if (action->numberOfArgs() == -1 && !c->
action()) {
106 const auto range = attributes.equal_range(u
"Path"_s);
107 for (
auto i = range.first; i != range.second; ++i) {
108 if (d->registerPath(*i, action)) {
120 return !d->paths.isEmpty();
126 if (captures.isEmpty()) {
128 auto it = attributes.constFind(u
"Path"_s);
129 if (it != attributes.constEnd()) {
130 const QString &path = it.value();
131 if (path.isEmpty()) {
133 }
else if (!path.startsWith(u
'/')) {
143bool DispatchTypePathPrivate::registerPath(
const QString &path,
Action *action)
145 QString _path = path;
147 if (_path.isEmpty()) {
149 }
else if (!_path.startsWith(u
'/')) {
153 auto it = paths.find(_path);
154 if (it != paths.end()) {
156 auto &actions = it->actions;
157 for (
const Action *regAction : actions) {
158 if (regAction->numberOfArgs() == actionNumberOfArgs) {
159 qCCritical(CUTELYST_DISPATCHER_PATH)
160 <<
"Not registering Action" << action->
name() <<
"of controller"
161 << action->
controller()->objectName() <<
"because it conflicts with"
162 << regAction->name() <<
"of controller"
163 << regAction->controller()->objectName();
168 actions.push_back(action);
169 std::ranges::sort(actions, [](
Action *a,
Action *b) ->
bool {
174 DispatchTypePathReplacement{
182#include "moc_dispatchtypepath.cpp"
This class represents a Cutelyst Action.
virtual qint8 numberOfArgs() const
ParamsMultiMap attributes() const noexcept
Controller * controller() const noexcept
QString name() const noexcept
Describes a path dispatch type.
~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
Abstract class to described a dispatch type.
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.