vitexsoftware/multiflexi-api-server

dev-main 2024-12-21 19:45 UTC

This package is auto-updated.

Last update: 2024-12-21 19:46:26 UTC


README

This server has been generated with Slim PSR-7 implementation. PHP-DI package used as dependency container.

Requirements

  • Web server with URL rewriting
  • PHP 7.4 or newer

This package contains .htaccess for Apache configuration. If you use another server(Nginx, HHVM, IIS, lighttpd) check out Web Servers doc.

Installation via Composer

Navigate into your project's root directory and execute the bash command shown below. This command downloads the Slim Framework and its third-party dependencies into your project's vendor/ directory.

$ composer install

Add configs

PHP-DI package helps to decouple configuration from implementation. App loads configuration files in straight order($env can be prod or dev):

  1. config/$env/default.inc.php (contains safe values, can be committed to vcs)
  2. config/$env/config.inc.php (user config, excluded from vcs, can contain sensitive values, passwords etc.)
  3. lib/App/RegisterDependencies.php

Start devserver

Run the following command in terminal to start localhost web server, assuming ./php-slim-server/public/ is public-accessible directory with index.php file:

$ php -S localhost:8888 -t php-slim-server/public

Warning This web server was designed to aid application development. It may also be useful for testing purposes or for application demonstrations that are run in controlled environments. It is not intended to be a full-featured web server. It should not be used on a public network.

Tests

PHPUnit

This package uses PHPUnit 8 or 9(depends from your PHP version) for unit testing. Test folder contains templates which you can fill with real test assertions. How to write tests read at 2. Writing Tests for PHPUnit - PHPUnit 8.5 Manual.

Run

Config

Package contains fully functional config ./phpunit.xml.dist file. Create ./phpunit.xml in root folder to override it.

Quote from 3. The Command-Line Test Runner — PHPUnit 8.5 Manual:

If phpunit.xml or phpunit.xml.dist (in that order) exist in the current working directory and --configuration is not used, the configuration will be automatically read from that file.

PHP CodeSniffer

PHP CodeSniffer Documentation. This tool helps to follow coding style and avoid common PHP coding mistakes.

Run

$ composer phpcs

Config

Package contains fully functional config ./phpcs.xml.dist file. It checks source code against PSR-1 and PSR-2 coding standards. Create ./phpcs.xml in root folder to override it. More info at Using a Default Configuration File

PHPLint

PHPLint Documentation. Checks PHP syntax only.

Run

$ composer phplint

Show errors

Switch your app environment to development

  • When using with some webserver => in public/.htaccess file:
## .htaccess
<IfModule mod_env.c>
    SetEnv APP_ENV 'development'
</IfModule>
  • Or when using whatever else, set APP_ENV environment variable like this:
export APP_ENV=development

or simply

export APP_ENV=dev

Mock Server

Since this feature should be used for development only, change environment to development and send additional HTTP header X-MultiFlexi\Api-Mock: ping with any request to get mocked response. CURL example:

curl --request GET \
    --url 'http://localhost:8888/v2/pet/findByStatus?status=available' \
    --header 'accept: application/json' \
    --header 'X-MultiFlexi\Api-Mock: ping'
[{"id":-8738629417578509312,"category":{"id":-4162503862215270400,"name":"Lorem ipsum dol"},"name":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem i","photoUrls":["Lor"],"tags":[{"id":-3506202845849391104,"name":"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Lorem ipsum dolor sit amet, consectet"}],"status":"pending"}]

Used packages:

Logging

Build contains pre-configured monolog/monolog package. Make sure that logs folder is writable. Add required log handlers/processors/formatters in lib/App/RegisterDependencies.php.

API Endpoints

All URIs are relative to https://virtserver.swaggerhub.com/VitexSoftware/MultiFlexi/1.0.0

Important! Do not modify abstract API controllers directly! Instead extend them by implementation classes like:

// src/Api/PetApi.php

namespace MultiFlexi\Api\Server;

use MultiFlexi\Api\Server\AbstractPetApi;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Message\ResponseInterface;

class PetApi extends AbstractPetApi
{
    public function addPet(
        ServerRequestInterface $request,
        ResponseInterface $response
    ): ResponseInterface {
        // your implementation of addPet method here
    }
}

When you need to inject dependencies into API controller check PHP-DI - Controllers as services guide.

Place all your implementation classes in ./src folder accordingly. For instance, when abstract class located at ./lib/Api/AbstractPetApi.php you need to create implementation class at ./src/Api/PetApi.php.

Models

  • MultiFlexi\Api\Model\App
  • MultiFlexi\Api\Model\Company
  • MultiFlexi\Api\Model\ConfField
  • MultiFlexi\Api\Model\Configuration
  • MultiFlexi\Api\Model\Credential
  • MultiFlexi\Api\Model\CredentialType
  • MultiFlexi\Api\Model\Customer
  • MultiFlexi\Api\Model\GetCredential200Response
  • MultiFlexi\Api\Model\GetCredentialType200Response
  • MultiFlexi\Api\Model\GetTopic200Response
  • MultiFlexi\Api\Model\Job
  • MultiFlexi\Api\Model\JobsStatus
  • MultiFlexi\Api\Model\RunTemplate
  • MultiFlexi\Api\Model\Status
  • MultiFlexi\Api\Model\Tag
  • MultiFlexi\Api\Model\Topic
  • MultiFlexi\Api\Model\User

Authentication

Security schema basicAuth

Important! To make Basic authentication work you need to extend \MultiFlexi\Api\Auth\AbstractAuthenticator class by \MultiFlexi\Api\Auth\BasicAuthenticator class.

Advanced middleware configuration

Ref to used Slim Token Middleware dyorg/slim-token-authentication