Small Clean Application

WBOY
Release: 2024-07-27 06:43:22
Original
720 people have browsed it

Small Clean Application

This project is a set of class to manage dependency injection of application's part of a clean architecture app,
independently of the framework used.

Git : https://git.small-project.dev/lib/small-clean-application
Packagist : https://packagist.org/packages/small/clean-application

Install

composer require small/clean-application
Copy after login

Parameters

Parameters are managed to automatically inject them in UseCase constructor.

You can set parameters through the facade static object :

\Small\CleanApplication\Facade::setParameter('test', [ 'host' => 'http://clean.com', 'port' => 80 ]);
Copy after login

You can also get them through the facade :

echo \Small\CleanApplication\Facade::getParameter('test.host');
Copy after login

Output :

http://clean.com
Copy after login

UseCase class

Simple case

A use case is a class materialization of use case that implement SmallCleanApplicationContractUseCaseInterface.

For example, here is simply use case that return a string :


        
Copy after login

You can use it using facade :

use Small\CleanApplication\Test\Feature\Fixture\UseCase\TestUseCase; use \Small\CleanApplication\Test\Feature\Fixture\UseCase\TestRequest; echo \Small\CleanApplication\Facade::execute(TestUseCase::class, new TestRequest());
Copy after login

Output :

a
Copy after login

Injecting another use case in your use case

You can inject another use case in the use case constructor :

getBefore() . $this->testUseCase->execute($request)->getStatus() ); } }
Copy after login

The property testUseCase will automatically be created as TestUseCase object.

Injecting parameters in your use case

You can inject parameters in your use case by typing and naming property in your use case constructor :

testUseCase_param . $request->getBefore() . $this->testUseCase->execute($request)->getStatus() ); } }
Copy after login

The underscrore ('_') separate array keys of parameters structure. Here is an example matching with the
$testUseCase_param :

\Small\CleanApplication\Facade::setParameter('testUseCase', ['param' => 'p']);
Copy after login

Interfaces

Three interface structure your code :

  • SmallCleanApplicationContractUseCaseInterface: All your use cases must implement this interface
  • SmallCleanApplicationContractRequest: All your use case requests must implement this interface
  • SmallCleanApplicationContractResponse: All your use case response must implement this interface

Here's ourTestDependencyexample request class :

before; } }
Copy after login

And his interface :


        
Copy after login

And here is the response implementation :

status; } }
Copy after login

And his interface :


        
Copy after login

The above is the detailed content of Small Clean Application. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!