定制 miguelcalderonb/meta-statements 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

miguelcalderonb/meta-statements

Composer 安装命令:

composer require miguelcalderonb/meta-statements

包简介

Meta-statements is a PHP library that allows execute statements dinamically.

README 文档

README

miguelcalderonb/meta-statements is a PHP library that allows execute statements dinamically from methods.

This allows to modify business rules or behaviours only modifying your data sources.

Installation

The preferred method of installation is via [Composer][]. Run the following command to install the package and add it as a requirement to your project's

composer.json:

composer require miguelcalderonb/meta-statements

Examples

If:

Simple (Static Syntax)

use Miguelcalderonb\MTStatements\Conditionals\StmIfExec;

StmIfExec::run(10, '==', 10);
//Output: bool(true)

Simple (Object Syntax)

use Miguelcalderonb\MTStatements\Conditionals\StmIf;

$ifStatement = new StmIf(10, '==', 10);
$ifStatement->run(); 
//Output: bool(true)

Execute function after statement executed

use Miguelcalderonb\MTStatements\Conditionals\StmIfExec;

$customFunction = function ($result ) {
    if ($result) {
        return 'Allowed';
    }

    return 'Rejected';
};

StmIfExec::run(10, '==', 10, $customFunction);
//Output: Allowed

StmIfExec::run(10, '==', 20, $customFunction);
//Output: Rejected

Execute function after statement executed (Object Syntax)

use Miguelcalderonb\MTStatements\Conditionals\StmIf;

$customFunction = function ($result ) {
    if ($result) {
        return 'Allowed';
    }

    return 'Rejected';
};


$ifStatement = new StmIf(10, '==', 10, $customFunction);
$ifStatement->run(); //Output: Allowed

$ifStatement->second =  20;
$ifStatement->run();
//Output: Rejected

If Complex:

Execute three if at the same time (Object Syntax)

use Miguelcalderonb\MTStatements\Conditionals\StmIf;
use Miguelcalderonb\MTStatements\Structs\StatementIfList;
use Miguelcalderonb\MTStatements\Conditionals\StmIfMulti;

$value = 7;

$firstStm = new StmIf($value, '>=', 1, null, '&&');
$secondStm = new StmIf($value, '<=', 7, null);

$listStm = new StatementIfList();
$listStm->add($firstStm);
$listStm->add($secondStm);

$customFunction = function($result) {
    if ($result) {
        return 'Value between 1 and 7';
    }

    return 'Value is not between 1 and 7';
};

$stmMulti = new StmIfMulti($listStm, $customFunction);
$stmMulti->run();

//Output: Value between 1 and 7

While Loop:

use Miguelcalderonb\MTStatements\Structs\LoopRestriction;
use Miguelcalderonb\MTStatements\Loops\StmWhileExec;

$execInEachLoop = function($firstValue) {
    echo $firstValue."\n";
};

$restrict = new LoopRestriction('+', 'before', 1);
StmWhileExec::run(0, '<=', 10, $restrict, $execInEachLoop);

// Output
// 1
// 2
// 3
// 4
// 5
// 6
// 7
// 8
// 9
// 10
// 11

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-08-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固