framework/extensions/package-manager/extend.php

64 lines
3.1 KiB
PHP
Raw Normal View History

2021-09-02 00:20:06 +08:00
<?php
2021-10-21 17:52:51 +08:00
/*
* This file is part of Flarum.
2021-09-02 00:20:06 +08:00
*
2021-10-21 17:52:51 +08:00
* For detailed copyright and license information, please view the
* LICENSE file that was distributed with this source code.
2021-09-02 00:20:06 +08:00
*/
2021-10-21 17:52:51 +08:00
namespace Flarum\PackageManager;
2021-09-02 00:20:06 +08:00
use Flarum\Extend;
use Flarum\Foundation\Paths;
use Flarum\Frontend\Document;
2021-10-21 17:52:51 +08:00
use Flarum\PackageManager\Exception\ComposerCommandFailedException;
use Flarum\PackageManager\Exception\ComposerRequireFailedException;
use Flarum\PackageManager\Exception\ComposerUpdateFailedException;
use Flarum\PackageManager\Exception\ExceptionHandler;
use Flarum\PackageManager\Exception\MajorUpdateFailedException;
use Flarum\PackageManager\Settings\LastUpdateCheck;
use Flarum\PackageManager\Settings\LastUpdateRun;
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/why-not', 'package-manager.why-not', Api\Controller\WhyNotController::class)
->post('/package-manager/minor-update', 'package-manager.minor-update', Api\Controller\MinorUpdateController::class)
->post('/package-manager/major-update', 'package-manager.major-update', Api\Controller\MajorUpdateController::class)
2021-09-29 19:07:53 +08:00
->post('/package-manager/global-update', 'package-manager.global-update', Api\Controller\GlobalUpdateController::class),
2021-09-02 00:20:06 +08:00
(new Extend\Frontend('admin'))
->css(__DIR__.'/less/admin.less')
->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-02 00:20:06 +08:00
new Extend\Locales(__DIR__.'/locale'),
2021-09-02 00:20:06 +08:00
(new Extend\Settings())
->default(LastUpdateCheck::key(), json_encode(LastUpdateCheck::default()))
->default(LastUpdateRun::key(), json_encode(LastUpdateRun::default())),
2021-09-02 00:20:06 +08:00
(new Extend\ServiceProvider)
2021-09-02 02:49:44 +08:00
->register(PackageManagerServiceProvider::class),
(new Extend\ErrorHandling)
->handler(ComposerCommandFailedException::class, ExceptionHandler::class)
->handler(ComposerRequireFailedException::class, ExceptionHandler::class)
->handler(ComposerUpdateFailedException::class, ExceptionHandler::class)
->handler(MajorUpdateFailedException::class, ExceptionHandler::class)
2021-09-29 18:03:13 +08:00
->status('extension_already_installed', 409)
->status('extension_not_installed', 409)
->status('no_new_major_version', 409),
2021-09-02 00:20:06 +08:00
];