framework/extensions/package-manager/extend.php

45 lines
1.8 KiB
PHP
Raw Normal View History

2021-09-02 00:20:06 +08:00
<?php
/**
*
*/
namespace SychO\PackageManager;
use Flarum\Extend;
use Flarum\Foundation\Paths;
use Flarum\Frontend\Document;
2021-09-25 20:59:59 +08:00
use Flarum\Settings\SettingsRepositoryInterface;
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')
->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-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),
(new Extend\ErrorHandling)
->handler(ComposerRequireFailedException::class, ComposerCommandFailedExceptionHandler::class),
2021-09-02 00:20:06 +08:00
];