ruslander-rulez / laravel-buisiness-logic-encapsulator
此包的最新版本(v1.0)没有可用的许可信息。
在Laravel项目中封装业务逻辑
v1.0
2019-11-26 21:10 UTC
Requires
- php: ^7.0
- laravel/framework: >5.6
This package is not auto-updated.
Last update: 2024-09-26 19:11:58 UTC
README
此包是为了在类中封装业务逻辑而创建的。您可以在项目的不同位置(视图、控制器、作业、测试等)使用封装的业务逻辑。
##用法 通过composer安装
composer require ruslander-rulez/laravel-buisiness-logic-encapsulator
创建新类
<?php
namespace Some\Namespace;
use RuslanderRulez\Encapsulator\AbstractCommand;
class SomeName extents AbstractCommand
{
private $input1;
private $input2;
private $someInjection;
public function __construct($inputVariable1, $inputVariable2, SomeInjection $someInjection)
{
$this->input1 = $inputVariable1;
$this->input2 = $inputVariable2;
$this->someInjection = $someInjection;
}
public function handle()
{
/*
SOME LOGIC
*/
return $this->input1 === $this->input2;
}
/**
* @retunn boolean
**/
public function executeFromParams($inputVariable1, $inputVariable2)
{
return self::execute(compact("inputVariable1", "inputVariable2"));
}
}
在需要的地方使用创建的类
//some code here
$result = SomeName::executeFromParams($value1, $value2);
//some code here
if ($result) {
//some code here
}
//some code here