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-25 20:59:59 +08:00
|
|
|
use Flarum\Settings\SettingsRepositoryInterface;
|
2021-09-23 05:08:51 +08:00
|
|
|
use SychO\PackageManager\Exception\ComposerCommandFailedExceptionHandler;
|
|
|
|
use SychO\PackageManager\Exception\ComposerRequireFailedException;
|
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)
|
|
|
|
->post('/package-manager/check-for-updates', 'package-manager.check-for-updates', Api\Controller\CheckForUpdatesController::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
|
|
|
|
|
|
|
$document->payload['lastUpdateCheck'] = json_decode(resolve(SettingsRepositoryInterface::class)->get('sycho-package-manager.last_update_check', '{}'), true);
|
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)
|
|
|
|
->handler(ComposerRequireFailedException::class, ComposerCommandFailedExceptionHandler::class),
|
2021-09-02 00:20:06 +08:00
|
|
|
];
|