mirror of
https://github.com/Part-DB/Part-DB-server.git
synced 2025-06-20 17:15:51 +02:00
Added first API endpoint
This commit is contained in:
parent
a43ee52086
commit
6d3b0261b3
14 changed files with 599 additions and 22 deletions
4
.env
4
.env
|
@ -206,3 +206,7 @@ APP_SECRET=a03498528f5a5fc089273ec9ae5b2849
|
|||
# postgresql+advisory://db_user:db_password@localhost/db_name
|
||||
LOCK_DSN=flock
|
||||
###< symfony/lock ###
|
||||
|
||||
###> nelmio/cors-bundle ###
|
||||
CORS_ALLOW_ORIGIN='^https?://(localhost|127\.0\.0\.1)(:[0-9]+)?$'
|
||||
###< nelmio/cors-bundle ###
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
"ext-intl": "*",
|
||||
"ext-json": "*",
|
||||
"ext-mbstring": "*",
|
||||
"api-platform/core": "^3.1",
|
||||
"beberlei/doctrineextensions": "^1.2",
|
||||
"brick/math": "^0.11.0",
|
||||
"composer/package-versions-deprecated": "^1.11.99.5",
|
||||
|
@ -33,6 +34,7 @@
|
|||
"liip/imagine-bundle": "^2.2",
|
||||
"nbgrp/onelogin-saml-bundle": "^1.3",
|
||||
"nelexa/zip": "^4.0",
|
||||
"nelmio/cors-bundle": "^2.3",
|
||||
"nelmio/security-bundle": "^3.0",
|
||||
"nyholm/psr7": "^1.1",
|
||||
"ocramius/proxy-manager": "2.2.*",
|
||||
|
@ -40,6 +42,7 @@
|
|||
"part-db/label-fonts": "^1.0",
|
||||
"php-translation/symfony-bundle": "^0.14.0",
|
||||
"phpdocumentor/reflection-docblock": "^5.2",
|
||||
"phpstan/phpdoc-parser": "^1.23",
|
||||
"s9e/text-formatter": "^2.1",
|
||||
"scheb/2fa-backup-code": "^6.8.0",
|
||||
"scheb/2fa-bundle": "^6.8.0",
|
||||
|
@ -83,7 +86,8 @@
|
|||
"twig/intl-extra": "^3.0",
|
||||
"twig/markdown-extra": "^3.0",
|
||||
"web-auth/webauthn-symfony-bundle": "^4.0.0",
|
||||
"webmozart/assert": "^1.4"
|
||||
"webmozart/assert": "^1.4",
|
||||
"webonyx/graphql-php": "^15.6"
|
||||
},
|
||||
"require-dev": {
|
||||
"dama/doctrine-test-bundle": "^7.0",
|
||||
|
|
362
composer.lock
generated
362
composer.lock
generated
|
@ -4,8 +4,177 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"content-hash": "b1ad5ff23ca8d2cc779fed986a8e2c9a",
|
||||
"content-hash": "1a2a25bc47002e077096b2aceaee7c7f",
|
||||
"packages": [
|
||||
{
|
||||
"name": "api-platform/core",
|
||||
"version": "v3.1.13",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/api-platform/core.git",
|
||||
"reference": "190bb4eabeafbe8e830af4a8ccac1feaf5b74e96"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/api-platform/core/zipball/190bb4eabeafbe8e830af4a8ccac1feaf5b74e96",
|
||||
"reference": "190bb4eabeafbe8e830af4a8ccac1feaf5b74e96",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"doctrine/inflector": "^1.0 || ^2.0",
|
||||
"php": ">=8.1",
|
||||
"psr/cache": "^1.0 || ^2.0 || ^3.0",
|
||||
"psr/container": "^1.0 || ^2.0",
|
||||
"symfony/deprecation-contracts": "^3.1",
|
||||
"symfony/http-foundation": "^6.1",
|
||||
"symfony/http-kernel": "^6.1",
|
||||
"symfony/property-access": "^6.1",
|
||||
"symfony/property-info": "^6.1",
|
||||
"symfony/serializer": "^6.1",
|
||||
"symfony/web-link": "^6.1",
|
||||
"willdurand/negotiation": "^3.0"
|
||||
},
|
||||
"conflict": {
|
||||
"doctrine/common": "<3.2.2",
|
||||
"doctrine/dbal": "<2.10",
|
||||
"doctrine/mongodb-odm": "<2.4",
|
||||
"doctrine/orm": "<2.14.0",
|
||||
"doctrine/persistence": "<1.3",
|
||||
"elasticsearch/elasticsearch": ">=8.0",
|
||||
"phpspec/prophecy": "<1.15",
|
||||
"phpunit/phpunit": "<9.5",
|
||||
"symfony/service-contracts": "<3",
|
||||
"symfony/var-exporter": "<6.1.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"behat/behat": "^3.1",
|
||||
"behat/mink": "^1.9",
|
||||
"doctrine/cache": "^1.11 || ^2.1",
|
||||
"doctrine/common": "^3.2.2",
|
||||
"doctrine/dbal": "^3.4.0",
|
||||
"doctrine/doctrine-bundle": "^1.12 || ^2.0",
|
||||
"doctrine/mongodb-odm": "^2.2",
|
||||
"doctrine/mongodb-odm-bundle": "^4.0",
|
||||
"doctrine/orm": "^2.14",
|
||||
"elasticsearch/elasticsearch": "^7.11.0",
|
||||
"friends-of-behat/mink-browserkit-driver": "^1.3.1",
|
||||
"friends-of-behat/mink-extension": "^2.2",
|
||||
"friends-of-behat/symfony-extension": "^2.1",
|
||||
"guzzlehttp/guzzle": "^6.0 || ^7.0",
|
||||
"jangregor/phpstan-prophecy": "^1.0",
|
||||
"justinrainbow/json-schema": "^5.2.1",
|
||||
"phpspec/prophecy-phpunit": "^2.0",
|
||||
"phpstan/extension-installer": "^1.1",
|
||||
"phpstan/phpdoc-parser": "^1.13",
|
||||
"phpstan/phpstan": "^1.1",
|
||||
"phpstan/phpstan-doctrine": "^1.0",
|
||||
"phpstan/phpstan-phpunit": "^1.0",
|
||||
"phpstan/phpstan-symfony": "^1.0",
|
||||
"psr/log": "^1.0 || ^2.0 || ^3.0",
|
||||
"ramsey/uuid": "^3.9.7 || ^4.0",
|
||||
"ramsey/uuid-doctrine": "^1.4 || ^2.0",
|
||||
"soyuka/contexts": "v3.3.9",
|
||||
"soyuka/stubs-mongodb": "^1.0",
|
||||
"symfony/asset": "^6.1",
|
||||
"symfony/browser-kit": "^6.1",
|
||||
"symfony/cache": "^6.1",
|
||||
"symfony/config": "^6.1",
|
||||
"symfony/console": "^6.1",
|
||||
"symfony/css-selector": "^6.1",
|
||||
"symfony/dependency-injection": "^6.1.12",
|
||||
"symfony/doctrine-bridge": "^6.1",
|
||||
"symfony/dom-crawler": "^6.1",
|
||||
"symfony/error-handler": "^6.1",
|
||||
"symfony/event-dispatcher": "^6.1",
|
||||
"symfony/expression-language": "^6.1",
|
||||
"symfony/finder": "^6.1",
|
||||
"symfony/form": "^6.1",
|
||||
"symfony/framework-bundle": "^6.1",
|
||||
"symfony/http-client": "^6.1",
|
||||
"symfony/intl": "^6.1",
|
||||
"symfony/maker-bundle": "^1.24",
|
||||
"symfony/mercure-bundle": "*",
|
||||
"symfony/messenger": "^6.1",
|
||||
"symfony/phpunit-bridge": "^6.1",
|
||||
"symfony/routing": "^6.1",
|
||||
"symfony/security-bundle": "^6.1",
|
||||
"symfony/security-core": "^6.1",
|
||||
"symfony/twig-bundle": "^6.1",
|
||||
"symfony/uid": "^6.1",
|
||||
"symfony/validator": "^6.1",
|
||||
"symfony/web-profiler-bundle": "^6.1",
|
||||
"symfony/yaml": "^6.1",
|
||||
"twig/twig": "^1.42.3 || ^2.12 || ^3.0",
|
||||
"webonyx/graphql-php": "^14.0 || ^15.0"
|
||||
},
|
||||
"suggest": {
|
||||
"doctrine/mongodb-odm-bundle": "To support MongoDB. Only versions 4.0 and later are supported.",
|
||||
"elasticsearch/elasticsearch": "To support Elasticsearch.",
|
||||
"ocramius/package-versions": "To display the API Platform's version in the debug bar.",
|
||||
"phpstan/phpdoc-parser": "To support extracting metadata from PHPDoc.",
|
||||
"psr/cache-implementation": "To use metadata caching.",
|
||||
"ramsey/uuid": "To support Ramsey's UUID identifiers.",
|
||||
"symfony/cache": "To have metadata caching when using Symfony integration.",
|
||||
"symfony/config": "To load XML configuration files.",
|
||||
"symfony/expression-language": "To use authorization features.",
|
||||
"symfony/http-client": "To use the HTTP cache invalidation system.",
|
||||
"symfony/messenger": "To support messenger integration.",
|
||||
"symfony/security": "To use authorization features.",
|
||||
"symfony/twig-bundle": "To use the Swagger UI integration.",
|
||||
"symfony/uid": "To support Symfony UUID/ULID identifiers.",
|
||||
"symfony/web-profiler-bundle": "To use the data collector.",
|
||||
"webonyx/graphql-php": "To support GraphQL."
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "3.2.x-dev"
|
||||
},
|
||||
"symfony": {
|
||||
"require": "^6.1"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"ApiPlatform\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Kévin Dunglas",
|
||||
"email": "kevin@dunglas.fr",
|
||||
"homepage": "https://dunglas.fr"
|
||||
}
|
||||
],
|
||||
"description": "Build a fully-featured hypermedia or GraphQL API in minutes!",
|
||||
"homepage": "https://api-platform.com",
|
||||
"keywords": [
|
||||
"Hydra",
|
||||
"JSON-LD",
|
||||
"api",
|
||||
"graphql",
|
||||
"hal",
|
||||
"jsonapi",
|
||||
"openapi",
|
||||
"rest",
|
||||
"swagger"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/api-platform/core/issues",
|
||||
"source": "https://github.com/api-platform/core/tree/v3.1.13"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://tidelift.com/funding/github/packagist/api-platform/core",
|
||||
"type": "tidelift"
|
||||
}
|
||||
],
|
||||
"time": "2023-08-03T16:44:18+00:00"
|
||||
},
|
||||
{
|
||||
"name": "beberlei/assert",
|
||||
"version": "v3.3.2",
|
||||
|
@ -4100,6 +4269,68 @@
|
|||
},
|
||||
"time": "2022-06-17T11:17:46+00:00"
|
||||
},
|
||||
{
|
||||
"name": "nelmio/cors-bundle",
|
||||
"version": "2.3.1",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/nelmio/NelmioCorsBundle.git",
|
||||
"reference": "185d2c0ae50a3f0b628790170164d5f1c5b7c281"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/nelmio/NelmioCorsBundle/zipball/185d2c0ae50a3f0b628790170164d5f1c5b7c281",
|
||||
"reference": "185d2c0ae50a3f0b628790170164d5f1c5b7c281",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"psr/log": "^1.0 || ^2.0 || ^3.0",
|
||||
"symfony/framework-bundle": "^4.4 || ^5.4 || ^6.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"mockery/mockery": "^1.2",
|
||||
"symfony/phpunit-bridge": "^4.4 || ^5.4 || ^6.0"
|
||||
},
|
||||
"type": "symfony-bundle",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "2.x-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Nelmio\\CorsBundle\\": ""
|
||||
},
|
||||
"exclude-from-classmap": [
|
||||
"/Tests/"
|
||||
]
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nelmio",
|
||||
"homepage": "http://nelm.io"
|
||||
},
|
||||
{
|
||||
"name": "Symfony Community",
|
||||
"homepage": "https://github.com/nelmio/NelmioCorsBundle/contributors"
|
||||
}
|
||||
],
|
||||
"description": "Adds CORS (Cross-Origin Resource Sharing) headers support in your Symfony application",
|
||||
"keywords": [
|
||||
"api",
|
||||
"cors",
|
||||
"crossdomain"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/nelmio/NelmioCorsBundle/issues",
|
||||
"source": "https://github.com/nelmio/NelmioCorsBundle/tree/2.3.1"
|
||||
},
|
||||
"time": "2023-02-16T08:49:29+00:00"
|
||||
},
|
||||
{
|
||||
"name": "nelmio/security-bundle",
|
||||
"version": "v3.0.0",
|
||||
|
@ -14128,6 +14359,135 @@
|
|||
"source": "https://github.com/webmozarts/assert/tree/1.11.0"
|
||||
},
|
||||
"time": "2022-06-03T18:03:27+00:00"
|
||||
},
|
||||
{
|
||||
"name": "webonyx/graphql-php",
|
||||
"version": "v15.6.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/webonyx/graphql-php.git",
|
||||
"reference": "d950e2b542ee5c092c5d1375240b561282c06af1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/webonyx/graphql-php/zipball/d950e2b542ee5c092c5d1375240b561282c06af1",
|
||||
"reference": "d950e2b542ee5c092c5d1375240b561282c06af1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-json": "*",
|
||||
"ext-mbstring": "*",
|
||||
"php": "^7.4 || ^8"
|
||||
},
|
||||
"require-dev": {
|
||||
"amphp/amp": "^2.6",
|
||||
"amphp/http-server": "^2.1",
|
||||
"dms/phpunit-arraysubset-asserts": "dev-master",
|
||||
"ergebnis/composer-normalize": "^2.28",
|
||||
"mll-lab/php-cs-fixer-config": "^5",
|
||||
"nyholm/psr7": "^1.5",
|
||||
"phpbench/phpbench": "^1.2",
|
||||
"phpstan/extension-installer": "^1.1",
|
||||
"phpstan/phpstan": "1.10.26",
|
||||
"phpstan/phpstan-phpunit": "1.3.13",
|
||||
"phpstan/phpstan-strict-rules": "1.5.1",
|
||||
"phpunit/phpunit": "^9.5 || ^10",
|
||||
"psr/http-message": "^1 || ^2",
|
||||
"react/http": "^1.6",
|
||||
"react/promise": "^2.9",
|
||||
"rector/rector": "^0.17",
|
||||
"symfony/polyfill-php81": "^1.23",
|
||||
"symfony/var-exporter": "^5 || ^6",
|
||||
"thecodingmachine/safe": "^1.3 || ^2"
|
||||
},
|
||||
"suggest": {
|
||||
"amphp/http-server": "To leverage async resolving with webserver on AMPHP platform",
|
||||
"psr/http-message": "To use standard GraphQL server",
|
||||
"react/promise": "To leverage async resolving on React PHP platform"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"GraphQL\\": "src/"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"description": "A PHP port of GraphQL reference implementation",
|
||||
"homepage": "https://github.com/webonyx/graphql-php",
|
||||
"keywords": [
|
||||
"api",
|
||||
"graphql"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/webonyx/graphql-php/issues",
|
||||
"source": "https://github.com/webonyx/graphql-php/tree/v15.6.0"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
"url": "https://opencollective.com/webonyx-graphql-php",
|
||||
"type": "open_collective"
|
||||
}
|
||||
],
|
||||
"time": "2023-08-04T09:43:22+00:00"
|
||||
},
|
||||
{
|
||||
"name": "willdurand/negotiation",
|
||||
"version": "3.1.0",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/willdurand/Negotiation.git",
|
||||
"reference": "68e9ea0553ef6e2ee8db5c1d98829f111e623ec2"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/willdurand/Negotiation/zipball/68e9ea0553ef6e2ee8db5c1d98829f111e623ec2",
|
||||
"reference": "68e9ea0553ef6e2ee8db5c1d98829f111e623ec2",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"php": ">=7.1.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"symfony/phpunit-bridge": "^5.0"
|
||||
},
|
||||
"type": "library",
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-master": "3.0-dev"
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Negotiation\\": "src/Negotiation"
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"MIT"
|
||||
],
|
||||
"authors": [
|
||||
{
|
||||
"name": "William Durand",
|
||||
"email": "will+git@drnd.me"
|
||||
}
|
||||
],
|
||||
"description": "Content Negotiation tools for PHP provided as a standalone library.",
|
||||
"homepage": "http://williamdurand.fr/Negotiation/",
|
||||
"keywords": [
|
||||
"accept",
|
||||
"content",
|
||||
"format",
|
||||
"header",
|
||||
"negotiation"
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/willdurand/Negotiation/issues",
|
||||
"source": "https://github.com/willdurand/Negotiation/tree/3.1.0"
|
||||
},
|
||||
"time": "2022-01-30T20:08:53+00:00"
|
||||
}
|
||||
],
|
||||
"packages-dev": [
|
||||
|
|
|
@ -31,4 +31,6 @@ return [
|
|||
Symfony\UX\Translator\UxTranslatorBundle::class => ['all' => true],
|
||||
Jbtronics\DompdfFontLoaderBundle\DompdfFontLoaderBundle::class => ['all' => true],
|
||||
KnpU\OAuth2ClientBundle\KnpUOAuth2ClientBundle::class => ['all' => true],
|
||||
Nelmio\CorsBundle\NelmioCorsBundle::class => ['all' => true],
|
||||
ApiPlatform\Symfony\Bundle\ApiPlatformBundle::class => ['all' => true],
|
||||
];
|
||||
|
|
6
config/packages/api_platform.yaml
Normal file
6
config/packages/api_platform.yaml
Normal file
|
@ -0,0 +1,6 @@
|
|||
api_platform:
|
||||
|
||||
title: 'Part-DB API'
|
||||
description: 'API of Part-DB'
|
||||
|
||||
version: '0.1.0'
|
10
config/packages/nelmio_cors.yaml
Normal file
10
config/packages/nelmio_cors.yaml
Normal file
|
@ -0,0 +1,10 @@
|
|||
nelmio_cors:
|
||||
defaults:
|
||||
origin_regex: true
|
||||
allow_origin: ['%env(CORS_ALLOW_ORIGIN)%']
|
||||
allow_methods: ['GET', 'OPTIONS', 'POST', 'PUT', 'PATCH', 'DELETE']
|
||||
allow_headers: ['Content-Type', 'Authorization']
|
||||
expose_headers: ['Link']
|
||||
max_age: 3600
|
||||
paths:
|
||||
'^/': null
|
4
config/routes/api_platform.yaml
Normal file
4
config/routes/api_platform.yaml
Normal file
|
@ -0,0 +1,4 @@
|
|||
api_platform:
|
||||
resource: .
|
||||
type: api_platform
|
||||
prefix: /api
|
|
@ -277,6 +277,15 @@ services:
|
|||
$search_limit: '%env(int:PROVIDER_OCTOPART_SEARCH_LIMIT)%'
|
||||
$onlyAuthorizedSellers: '%env(bool:PROVIDER_OCTOPART_ONLY_AUTHORIZED_SELLERS)%'
|
||||
|
||||
####################################################################################################################
|
||||
# API system
|
||||
####################################################################################################################
|
||||
App\State\PartDBInfoProvider:
|
||||
arguments:
|
||||
$default_uri: '%partdb.default_uri%'
|
||||
$global_locale: '%partdb.locale%'
|
||||
$global_timezone: '%partdb.timezone%'
|
||||
|
||||
####################################################################################################################
|
||||
# Symfony overrides
|
||||
####################################################################################################################
|
||||
|
@ -319,6 +328,12 @@ services:
|
|||
arguments:
|
||||
$check_for_updates: '%partdb.check_for_updates%'
|
||||
|
||||
App\Services\System\BannerHelper:
|
||||
arguments:
|
||||
$partdb_banner: '%partdb.banner%'
|
||||
$project_dir: '%kernel.project_dir%'
|
||||
|
||||
|
||||
####################################################################################################################
|
||||
# Monolog
|
||||
####################################################################################################################
|
||||
|
|
0
src/ApiResource/.gitignore
vendored
Normal file
0
src/ApiResource/.gitignore
vendored
Normal file
63
src/ApiResource/PartDBInfo.php
Normal file
63
src/ApiResource/PartDBInfo.php
Normal file
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2023 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\ApiResource;
|
||||
|
||||
use ApiPlatform\Metadata\ApiResource;
|
||||
use ApiPlatform\Metadata\Get;
|
||||
use App\State\PartDBInfoProvider;
|
||||
|
||||
/**
|
||||
* This class is used to provide various information about the system.
|
||||
*/
|
||||
#[ApiResource(
|
||||
uriTemplate: '/info',
|
||||
description: 'Basic information about Part-DB like version, title, etc.',
|
||||
operations: [new Get()],
|
||||
provider: PartDBInfoProvider::class
|
||||
)]
|
||||
class PartDBInfo
|
||||
{
|
||||
public function __construct(
|
||||
/** The installed Part-DB version */
|
||||
public readonly string $version,
|
||||
/** The Git branch name of the Part-DB version (or null, if not installed via git) */
|
||||
public readonly string|null $git_branch,
|
||||
/** The Git branch commit of the Part-DB version (or null, if not installed via git) */
|
||||
public readonly string|null $git_commit,
|
||||
/** The name of this Part-DB instance */
|
||||
public readonly string $title,
|
||||
/** The banner, shown on homepage (markdown encoded) */
|
||||
public readonly string $banner,
|
||||
/** The configured default URI for Part-DB */
|
||||
public readonly string $default_uri,
|
||||
/** The global timezone of this Part-DB */
|
||||
public readonly string $global_timezone,
|
||||
/** The base currency of Part-DB, used as internal representation of monetary values */
|
||||
public readonly string $base_currency,
|
||||
/** The configured default language of Part-DB */
|
||||
public readonly string $global_locale,
|
||||
) {
|
||||
|
||||
}
|
||||
}
|
|
@ -25,6 +25,7 @@ namespace App\Controller;
|
|||
use App\DataTables\LogDataTable;
|
||||
use App\Entity\Parts\Part;
|
||||
use App\Services\Misc\GitVersionInfo;
|
||||
use App\Services\System\BannerHelper;
|
||||
use App\Services\System\UpdateAvailableManager;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use const DIRECTORY_SEPARATOR;
|
||||
|
@ -38,29 +39,11 @@ use Symfony\Contracts\Cache\CacheInterface;
|
|||
|
||||
class HomepageController extends AbstractController
|
||||
{
|
||||
public function __construct(protected CacheInterface $cache, protected KernelInterface $kernel, protected DataTableFactory $dataTable)
|
||||
public function __construct(private readonly DataTableFactory $dataTable, private readonly BannerHelper $bannerHelper)
|
||||
{
|
||||
}
|
||||
|
||||
public function getBanner(): string
|
||||
{
|
||||
$banner = $this->getParameter('partdb.banner');
|
||||
if (!is_string($banner)) {
|
||||
throw new \RuntimeException('The parameter "partdb.banner" must be a string.');
|
||||
}
|
||||
if (empty($banner)) {
|
||||
$banner_path = $this->kernel->getProjectDir()
|
||||
.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'banner.md';
|
||||
|
||||
$tmp = file_get_contents($banner_path);
|
||||
if (false === $tmp) {
|
||||
throw new \RuntimeException('The banner file could not be read.');
|
||||
}
|
||||
$banner = $tmp;
|
||||
}
|
||||
|
||||
return $banner;
|
||||
}
|
||||
|
||||
#[Route(path: '/', name: 'homepage')]
|
||||
public function homepage(Request $request, GitVersionInfo $versionInfo, EntityManagerInterface $entityManager,
|
||||
|
@ -94,7 +77,7 @@ class HomepageController extends AbstractController
|
|||
}
|
||||
|
||||
return $this->render('homepage.html.twig', [
|
||||
'banner' => $this->getBanner(),
|
||||
'banner' => $this->bannerHelper->getBanner(),
|
||||
'git_branch' => $versionInfo->getGitBranchName(),
|
||||
'git_commit' => $versionInfo->getGitCommitHash(),
|
||||
'show_first_steps' => $show_first_steps,
|
||||
|
|
59
src/Services/System/BannerHelper.php
Normal file
59
src/Services/System/BannerHelper.php
Normal file
|
@ -0,0 +1,59 @@
|
|||
<?php
|
||||
/*
|
||||
* This file is part of Part-DB (https://github.com/Part-DB/Part-DB-symfony).
|
||||
*
|
||||
* Copyright (C) 2019 - 2023 Jan Böhmer (https://github.com/jbtronics)
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published
|
||||
* by the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
|
||||
namespace App\Services\System;
|
||||
|
||||
/**
|
||||
* Helper service to retrieve the banner of this Part-DB installation
|
||||
*/
|
||||
class BannerHelper
|
||||
{
|
||||
public function __construct(private readonly string $project_dir, private readonly string $partdb_banner)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieves the banner from either the env variable or the banner.md file.
|
||||
* @return string
|
||||
*/
|
||||
public function getBanner(): string
|
||||
{
|
||||
$banner = $this->partdb_banner;
|
||||
if (!is_string($banner)) {
|
||||
throw new \RuntimeException('The parameter "partdb.banner" must be a string.');
|
||||
}
|
||||
if (empty($banner)) {
|
||||
$banner_path = $this->project_dir
|
||||
.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'banner.md';
|
||||
|
||||
$tmp = file_get_contents($banner_path);
|
||||
if (false === $tmp) {
|
||||
throw new \RuntimeException('The banner file could not be read.');
|
||||
}
|
||||
$banner = $tmp;
|
||||
}
|
||||
|
||||
return $banner;
|
||||
}
|
||||
}
|
42
src/State/PartDBInfoProvider.php
Normal file
42
src/State/PartDBInfoProvider.php
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
namespace App\State;
|
||||
|
||||
use ApiPlatform\Metadata\Operation;
|
||||
use ApiPlatform\State\ProviderInterface;
|
||||
use App\ApiResource\PartDBInfo;
|
||||
use App\Services\Misc\GitVersionInfo;
|
||||
use App\Services\System\BannerHelper;
|
||||
use Shivas\VersioningBundle\Service\VersionManagerInterface;
|
||||
|
||||
class PartDBInfoProvider implements ProviderInterface
|
||||
{
|
||||
|
||||
public function __construct(private readonly VersionManagerInterface $versionManager,
|
||||
private readonly GitVersionInfo $gitVersionInfo,
|
||||
private readonly string $partdb_title,
|
||||
private string $base_currency,
|
||||
private readonly BannerHelper $bannerHelper,
|
||||
private readonly string $default_uri,
|
||||
private readonly string $global_timezone,
|
||||
private readonly string $global_locale
|
||||
)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
|
||||
{
|
||||
return new PartDBInfo(
|
||||
version: $this->versionManager->getVersion()->toString(),
|
||||
git_branch: $this->gitVersionInfo->getGitBranchName(),
|
||||
git_commit: $this->gitVersionInfo->getGitCommitHash(),
|
||||
title: $this->partdb_title,
|
||||
banner: $this->bannerHelper->getBanner(),
|
||||
default_uri: $this->default_uri,
|
||||
global_timezone: $this->global_timezone,
|
||||
base_currency: $this->base_currency,
|
||||
global_locale: $this->global_locale,
|
||||
);
|
||||
}
|
||||
}
|
25
symfony.lock
25
symfony.lock
|
@ -5,6 +5,19 @@
|
|||
"amphp/byte-stream": {
|
||||
"version": "v1.6.1"
|
||||
},
|
||||
"api-platform/core": {
|
||||
"version": "3.1",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "3.0",
|
||||
"ref": "0330386d716d3eecc52ee5ac66976e733eb8f961"
|
||||
},
|
||||
"files": [
|
||||
"./config/routes/api_platform.yaml",
|
||||
"./src/ApiResource/.gitignore"
|
||||
]
|
||||
},
|
||||
"beberlei/assert": {
|
||||
"version": "v3.2.6"
|
||||
},
|
||||
|
@ -220,6 +233,18 @@
|
|||
"nbgrp/onelogin-saml-bundle": {
|
||||
"version": "v1.3.2"
|
||||
},
|
||||
"nelmio/cors-bundle": {
|
||||
"version": "2.3",
|
||||
"recipe": {
|
||||
"repo": "github.com/symfony/recipes",
|
||||
"branch": "main",
|
||||
"version": "1.5",
|
||||
"ref": "6bea22e6c564fba3a1391615cada1437d0bde39c"
|
||||
},
|
||||
"files": [
|
||||
"./config/packages/nelmio_cors.yaml"
|
||||
]
|
||||
},
|
||||
"nelmio/security-bundle": {
|
||||
"version": "2.4",
|
||||
"recipe": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue