feat(plugin): manually load a plugin

This commit is contained in:
Jérémy Dufraisse 2023-02-26 02:43:54 +01:00
parent 764d9567e4
commit 37e65ce780
4 changed files with 96 additions and 4 deletions

View File

@ -9,6 +9,7 @@ namespace SeaCMS;
use Exception; use Exception;
use Pico; use Pico;
use SeacmsAppPlugin;
use Throwable; use Throwable;
set_error_handler(function ( set_error_handler(function (
@ -74,6 +75,7 @@ class App
self::PLUGINS_PATH, // plugins dir self::PLUGINS_PATH, // plugins dir
self::THEMES_PATH // themes dir self::THEMES_PATH // themes dir
); );
$this->pico->loadPlugin(new SeacmsAppPlugin($this->pico));
} }
public function runPico(): string public function runPico(): string

38
SeacmsAppPlugin.php Normal file
View File

@ -0,0 +1,38 @@
<?php
// SPDX-License-Identifier: EUPL-1.2
// Authors: see README.md
use SeaCMS\Api\JsonResponse;
/**
* A plugin for SeaCMS-app.
*/
class SeacmsAppPlugin extends AbstractPicoPlugin
{
/**
* Pico API version.
* @var int
*/
const API_VERSION = 3;
/**
* return api routes
* @return array
*/
public function registerOnPageRenderedApiRoutes():array
{
return [
'pages/(.*)/create' => 'createPage', // TODO only define for POST
];
}
/**
* method to create a page
* @return JsonResponse
*/
public function createPage(string $pageName): JsonResponse
{
return new JsonResponse(501,['code'=>501,'reason'=>"work in progress for '$pageName'"]);
}
}

View File

@ -13,7 +13,8 @@
"ext-pcre": "*", "ext-pcre": "*",
"composer": "^2.4", "composer": "^2.4",
"picocms/composer-installer": "dev-pico-3.0", "picocms/composer-installer": "dev-pico-3.0",
"picocms/pico": "dev-fix-compatibility-php8 as v3.0.0-alpha.2" "picocms/pico": "dev-fix-compatibility-php8 as v3.0.0-alpha.2",
"seacms/seacms-api": "dev-master"
}, },
"config": { "config": {
"optimize-autoloader": true, "optimize-autoloader": true,
@ -30,7 +31,7 @@
"picocms/pico-theme": "Default pico theme : revision ^3.0" "picocms/pico-theme": "Default pico theme : revision ^3.0"
}, },
"autoload": { "autoload": {
"classmap": ["App.php"] "classmap": ["App.php","SeacmsAppPlugin.php"]
}, },
"extra": { "extra": {
"pico-plugin-dir": "vendor/picocms/plugins/", "pico-plugin-dir": "vendor/picocms/plugins/",
@ -51,6 +52,10 @@
{ {
"type": "vcs", "type": "vcs",
"url": "https://git.defis.info/SeaCMS/pico" "url": "https://git.defis.info/SeaCMS/pico"
},
{
"type": "vcs",
"url": "https://git.defis.info/SeaCMS/seacms-api"
} }
] ]
} }

51
composer.lock generated
View File

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "c22d26de0ca3ffbcb24e1c63a66f1a18", "content-hash": "535fa433099487b5d89809ec52ba3b4d",
"packages": [ "packages": [
{ {
"name": "erusev/parsedown", "name": "erusev/parsedown",
@ -258,6 +258,52 @@
}, },
"time": "2023-01-24T10:20:23+00:00" "time": "2023-01-24T10:20:23+00:00"
}, },
{
"name": "seacms/seacms-api",
"version": "dev-master",
"source": {
"type": "git",
"url": "https://git.defis.info/SeaCMS/seacms-api",
"reference": "49ad30f7da79a42d19df66b1b535897e55cc9bae"
},
"require": {
"php": "^8.0"
},
"default-branch": true,
"type": "pico-plugin",
"autoload": {
"psr-4": {
"SeaCMS\\Api\\": "src"
},
"classmap": [
"SeacmsApi.php"
]
},
"license": [
"EUPL-1.2"
],
"authors": [
{
"name": "Jérémy Dufraisse",
"homepage": "https://github.com/J9rem",
"role": "SeaCMS developer"
}
],
"description": "API route for SeaCMS",
"homepage": "https://git.defis.info/SeaCMS/seacms-api",
"keywords": [
"api",
"pico",
"picocms",
"picocms-plugin"
],
"support": {
"docs": "https://git.defis.info/SeaCMS/seacms-api/src/branch/master/README.md",
"issues": "https://git.defis.info/SeaCMS/seacms-api/issues",
"source": "https://git.defis.info/SeaCMS/seacms-api"
},
"time": "2023-02-26T00:32:51+00:00"
},
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",
"version": "v1.27.0", "version": "v1.27.0",
@ -663,7 +709,8 @@
"minimum-stability": "dev", "minimum-stability": "dev",
"stability-flags": { "stability-flags": {
"picocms/composer-installer": 20, "picocms/composer-installer": 20,
"picocms/pico": 20 "picocms/pico": 20,
"seacms/seacms-api": 20
}, },
"prefer-stable": true, "prefer-stable": true,
"prefer-lowest": false, "prefer-lowest": false,