php flarum info
Flarum core: 1.8.9
PHP version: 8.3.14
MySQL version: 10.3.39-MariaDB-0ubuntu0.20.04.2
Loaded extensions: Core, date, libxml, openssl, pcre, zlib, filter, hash, json, pcntl, random, Reflection, SPL, session, standard, sodium, mysqlnd, PDO, xml, bcmath, calendar, ctype, curl, dom, mbstring, FFI, fileinfo, ftp, gd, gettext, iconv, imagick, intl, exif, msgpack, mysqli, pdo_mysql, Phar, posix, readline, shmop, SimpleXML, sockets, sysvmsg, sysvsem, sysvshm, tokenizer, xmlreader, xmlwriter, xsl, Zend OPcache, xdebug
+----------------------+------------+--------+
| Flarum Extensions | | |
+----------------------+------------+--------+
| ID | Version | Commit |
+----------------------+------------+--------+
| flarum-flags | v1.8.2 | |
| flarum-approval | v1.8.2 | |
| flarum-tags | v1.8.3 | |
| flarum-markdown | v1.8.1 | |
| flarum-suspend | v1.8.4 | |
| flarum-subscriptions | v1.8.1 | |
| flarum-sticky | v1.8.2 | |
| flarum-statistics | v1.8.1 | |
| flarum-mentions | v1.8.5 | |
| flarum-lock | v1.8.2 | |
| flarum-likes | v1.8.1 | |
| flarum-lang-russian | 1.40.0 | |
| flarum-emoji | v1.8.1 | |
| flarum-bbcode | v1.8.0 | |
| askvortsov-rich-text | v2.1.7 | |
| acme-hello-world | dev-master | |
+----------------------+------------+--------+
Base URL: http://forums.ser5lexx.ru/flarum
Installation path: /var/www/forums/htdocs/flarum
Queue driver: sync
Session driver: file
Mail driver: mail
Debug mode: off
For first take I tried to find some event that can be used to alter selection from database. But found only events that allow to handle posts submission, deletion, etc.
Then I found that the data for showing messages list is collected by \Flarum\Api\Controller\ShowDiscussionController::data()
method. Tried to tune the dependency injection container inside root extend.php
. Here I tried to write my register()
method to see if it can initialize default ShowDiscussionController
.
<?php
use Flarum\Extend;
use Flarum\Foundation\AbstractServiceProvider;
use Illuminate\Contracts\Container\Container;
use Flarum\Api\Controller\ShowDiscussionController;
class CustomServiceProvider extends AbstractServiceProvider {
public function register () {
//var_dump('register start');
$this->container->resolving(ShowDiscussionController::class, function (Container $container) {
var_dump('This line is never being reached'); exit();
return new ShowDiscussionController(
$container->make(\Flarum\Discussion\DiscussionRepository::class),
$container->make(\Flarum\Post\PostRepository::class),
$container->make(\Flarum\Http\SlugManager::class),
);
});
//var_dump('register end'); exit();
}
}
return [
(new Extend\ServiceProvider())->register(CustomServiceProvider::class),
];
This way the discussion page breaks, in source code I can see a message like "Something went wrong trying to load full version of the site...", which can mean that something is changed. "register start" and "register end" works normally, but the line with exit()
is never reached. Probably this means that $this->container->resolving()
call is technically valid, but when the engine tries to access something in the container, it breaks.
Next, I tried to change routes, to change the controller responding to discussion. Found the routed in vendor/flarum/core/src/Forum/routes.php
. Saw this line:
$map->get(
'/d/{id:\d+(?:-[^/]*)?}[/{near:[^/]*}]',
'discussion',
$route->toForum(Content\Discussion::class)
);
It doesn't simply directs to a dedicated controller, but calls complex \Flarum\Http\RouteHandlerFactory::toForum()
method. I tried to debug it, but quickly drown in container stuff, ton of callbacks, and other smart things.
So, what really is the right way to solve the task?