6 #include "controller.h"
7 #include "dispatchtypepath_p.h"
12 #include <QRegularExpression>
18 , d_ptr(new DispatchTypePathPrivate)
35 auto keys = d->paths.keys();
38 return a.compare(b, Qt::CaseInsensitive) < 0;
40 for (
const auto &path : keys) {
41 const auto paths = d->paths.value(path);
42 for (
Action *action : paths.actions) {
51 _path.
replace(multipleSlashes, u
"/"_qs);
58 table.
append({_path, privateName});
62 return Utils::buildTable(table, {u
"Path"_qs, u
"Private"_qs}, u
"Loaded Path actions:"_qs);
70 auto it = d->paths.constFind(path);
71 if (it == d->paths.constEnd()) {
76 int numberOfArgs = args.
size();
77 for (
Action *action : it->actions) {
106 const auto range = attributes.
equal_range(u
"Path"_qs);
107 for (
auto i = range.first; i != range.second; ++i) {
108 if (d->registerPath(*i, action)) {
120 return !d->paths.isEmpty();
128 auto it = attributes.
constFind(u
"Path"_qs);
129 if (it != attributes.constEnd()) {
130 const QString &path = it.value();
143 bool DispatchTypePathPrivate::registerPath(
const QString &path,
Action *action)
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"
162 << regAction->name() <<
"of controller"
163 << regAction->controller()->objectName();
168 actions.push_back(action);
169 std::sort(actions.begin(), actions.end(), [](
Action *a,
Action *b) ->
bool {
170 return a->numberOfArgs() < b->numberOfArgs();
173 paths.insert(_path, DispatchTypePathReplacement{_path, {action}});
178 #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
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.
void append(QList::parameter_type value)
bool isEmpty() const const
qsizetype size() const const
QMultiMap::const_iterator constFind(const Key &key) const const
QPair< QMultiMap::iterator, QMultiMap::iterator > equal_range(const Key &key)
QString & append(QChar ch)
bool isEmpty() const const
QString & prepend(QChar ch)
QString & replace(QChar before, QChar after, Qt::CaseSensitivity cs)
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const