levtechdev / simpaas
SimPass framework
dev-main
2022-04-19 13:22 UTC
Requires
- php: ^8.0
- ext-curl: *
- ext-pcntl: *
- ext-posix: *
- ext-redis: *
- ext-simplexml: *
- elasticsearch/elasticsearch: ^7.0
- firebase/php-jwt: ^6.1
- guzzlehttp/guzzle: ^7.4
- illuminate/redis: ^9.7
- illuminate/support: ^9.6
- laravel/lumen-framework: ^9.0
- ongr/elasticsearch-dsl: ^7.2
- php-amqplib/php-amqplib: ^3.2
- psr/log: ^3.0
- swaggest/json-schema: ^0.12.39
- zircote/swagger-php: ^4.2
This package is not auto-updated.
Last update: 2024-04-14 22:18:54 UTC
README
System Requirements
Software | Version |
---|---|
PHP Composer | 2.3.x |
PHP Framework | Lumen 9.0.x |
Web Server | Nginx 1.x |
PHP FPM | 8.0.x |
PHP Modules | curl, procps, pcntl, gd, iconv, intl, mbstring, bcmath, sockets, opcache, openssl, SimpleXML, soap, libxml, zip, json, xmlrpc, xsl |
ElasticSearch | 7.16.4 |
Redis (backend cache) | 6.2.x |
Redis (database storage) | 6.2.x |
RabittMQ | RabbitMQ 3.8.x Erlang 23.2.x |
Install Simpaas framework in the app
composer require levtechdev\simpaaas
Required configs
copy configs (global, log) from simpass/config to app/config
// bootstrap $app->configure('global'); $app->configure('log');
Required Service Providers
// bootstrap/app.php $app->register(Levtechdev\Simpaas\RedisProvider::class); $app->register(Levtechdev\Simpaas\CoreProvider::class);
Register Middlewares
// bootstrap/app.php use Levtechdev\Simpaas\Middleware\Http\{JwtMiddleware, JsonSchemaMiddleware, CorsMiddleware, MaintenanceModeMiddleware, LoggerMiddleware}; // .... $app->routeMiddleware([ JwtMiddleware::NAME => JwtMiddleware::class, JsonSchemaMiddleware::NAME => JsonSchemaMiddleware::class, ] ); $app->middleware( [ CorsMiddleware::class, MaintenanceModeMiddleware::class, LoggerMiddleware::class ] ); // ....
Routing configuration
Change routes/web.php to routes/api.php
All routers must be under a prefix like 'v*'
$router->group(['prefix' => 'v1'], function () use ($router) { $router->..... });
// bootstrap/app.php // .... $app->router->group([], function ($router) { require __DIR__ . DS . '..' . DS . 'routes' . DS . 'api.php'; }); $router = $app->router->getRoutes(); foreach ($router as $key => $value) { $app->router->addRoute($value['method'], str_replace('/v1/', '/', $value['uri']), $value['action']); } return $app;
Authorization
- Override Authorization/Migration/SampleData.php in your app with new role rules and Register it in app Service Provider
- Init users
php artisan app:init --initUsers
Elasticsearch
- Add to bootstrap
// bootstrap $app->configure('database') // and configure env ... $app->register(Levtechdev\Simpaas\ElasticsearchProvider::class);
- Define Entity in the Elasticsearch scope (Model, Resource, Collection)
- Create Class witch are implemented EntityResourceModelMapperInterface example:
class NewClass implements EntityResourceModelMapperInterface protected array $mapping = [ TestElasticModel::ENTITY => TestElasticResourceModel::class, ]; public function getResourceModelClassNameByEntityType(string $type): string|false { return $this->mapping[$type] ?? false; } public function getInstalledResources(): array { return $this->mapping; } }
NOTE: Bind this interface with NewClass in app service provider
- Create entity json schema into public/json-schema/v1/definitions/catalog.json
- Create index
php artisan elastic:create catalog_entity
Swagger
- Copy Levtechdev\Simpaas\Helper\Swagger to any app folder (for example: app/Core/Helper) and configure comments according to the app
- Copy swagger folder with static(from IMS or CDMS public/swagger) content to public/ folder
- run
php artisan swag:gen (NOTE: Required user initialization)
RabbitMq
- Copy simpaas\config\queue.php to app/config/queue.php and configure exchanges, queues, consumers, publishers
- Configure env according to queue.php
- Add to your app bootrstrap
$app->configure('queue'); $app->register(Levtechdev\Simpaas\RabbitMqProvider::class);
- Init queue entities
php artisan rabbitmq:setup
- Queue entities list is
php artisan rabbitmq:list
- copy shell/queue to shell/queue folder and create processor and workers
- NOTE: Enable queue consuming: add queue name into local/queue/enabled_queue (separator is ,)
- In your App implement
Queue/RabbitMq/Processor/AbstractMessageProcessor::class, Queue/Manager/AbstractConsumer::class Queue/Manager/AbstractPublisher::class
Cams
.env
CAMS_HOST=
CAMS_AUTH_USER=
CAMS_AUTH_PASSWORD=
CAMS_QUEUE_MAX_NUMBER_WORKERS=
- Configure cams queue entity in config/queue.php.. See example in simpaas\config\queue.php
- Use Levtechdev\Simpaas\Queue\PublisherManager class for sending items to cams queue
Option config
Log
- Debug level, see Levtechdev\Simpaas\Service\DebugLogTrait
DEBUG_LEVEL=true - write debug log see