2021-09-02 00:20:06 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace SychO\PackageManager;
|
|
|
|
|
|
|
|
use Flarum\Extend;
|
|
|
|
use Flarum\Foundation\Paths;
|
2021-09-23 05:08:51 +08:00
|
|
|
use Flarum\Frontend\Document;
|
2021-09-27 17:16:01 +08:00
|
|
|
use SychO\PackageManager\Exception\ComposerCommandFailedException;
|
2021-09-23 05:08:51 +08:00
|
|
|
use SychO\PackageManager\Exception\ComposerCommandFailedExceptionHandler;
|
|
|
|
use SychO\PackageManager\Exception\ComposerRequireFailedException;
|
2021-09-27 17:16:01 +08:00
|
|
|
use SychO\PackageManager\Exception\ComposerUpdateFailedException;
|
2021-09-02 00:20:06 +08:00
|
|
|
|
|
|
|
return [
|
|
|
|
(new Extend\Routes('api'))
|
|
|
|
->post('/package-manager/extensions', 'package-manager.extensions.require', Api\Controller\RequireExtensionController::class)
|
|
|
|
->patch('/package-manager/extensions/{id}', 'package-manager.extensions.update', Api\Controller\UpdateExtensionController::class)
|
2021-09-25 20:59:59 +08:00
|
|
|
->delete('/package-manager/extensions/{id}', 'package-manager.extensions.remove', Api\Controller\RemoveExtensionController::class)
|
2021-09-27 17:16:01 +08:00
|
|
|
->post('/package-manager/check-for-updates', 'package-manager.check-for-updates', Api\Controller\CheckForUpdatesController::class)
|
|
|
|
->post('/package-manager/minor-update', 'package-manager.minor-update', Api\Controller\MinorFlarumUpdateController::class),
|
2021-09-02 00:20:06 +08:00
|
|
|
|
|
|
|
(new Extend\Frontend('admin'))
|
|
|
|
->css(__DIR__ . '/less/admin.less')
|
2021-09-23 05:08:51 +08:00
|
|
|
->js(__DIR__ . '/js/dist/admin.js')
|
|
|
|
->content(function (Document $document) {
|
|
|
|
$paths = resolve(Paths::class);
|
|
|
|
|
|
|
|
$document->payload['isRequiredDirectoriesWritable'] = is_writable($paths->vendor)
|
|
|
|
&& is_writable($paths->storage.'/.composer')
|
|
|
|
&& is_writable($paths->base.'/composer.json')
|
|
|
|
&& is_writable($paths->base.'/composer.lock');
|
2021-09-25 20:59:59 +08:00
|
|
|
|
2021-09-27 17:16:01 +08:00
|
|
|
$document->payload['lastUpdateCheck'] = resolve(LastUpdateCheck::class)->get();
|
2021-09-23 05:08:51 +08:00
|
|
|
}),
|
2021-09-02 00:20:06 +08:00
|
|
|
|
|
|
|
new Extend\Locales(__DIR__ . '/locale'),
|
|
|
|
|
|
|
|
(new Extend\ServiceProvider)
|
2021-09-02 02:49:44 +08:00
|
|
|
->register(PackageManagerServiceProvider::class),
|
2021-09-23 05:08:51 +08:00
|
|
|
|
|
|
|
(new Extend\ErrorHandling)
|
2021-09-27 17:16:01 +08:00
|
|
|
->handler(ComposerCommandFailedException::class, ComposerCommandFailedExceptionHandler::class)
|
|
|
|
->handler(ComposerRequireFailedException::class, ComposerCommandFailedExceptionHandler::class)
|
|
|
|
->handler(ComposerUpdateFailedException::class, ComposerCommandFailedExceptionHandler::class),
|
2021-09-02 00:20:06 +08:00
|
|
|
];
|