jlawrence/eos 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

jlawrence/eos

Composer 安装命令:

composer require jlawrence/eos

包简介

Parse and solve math equations without using 'eval()'.

README 文档

README

Build Status Latest Stable Version Latest Unstable Version Total Downloads License Code Climate Test Coverage

Installation

Install EOS with Composer

Add the dependency:

"require": {
    "jlawrence/eos": "3.*"
}

Run composer update and you're done.

Equation Operating System

jlawrence\eos\

This class makes it incredibly easy to use and parse/solve equations in your own applications. NOTE ALL of the functions within these classes are static. It is also important to note that these classes throw exceptions if running in to errors, please read the beginning of the Math.php file for the defines of the exceptions thrown. Exceptions includes a descriptive message of the error encountered and within Parser will also typically include the full equation used.

Parser

This class has one important function, Parser::solve() which does all the legwork, so we'll start there and end with examples.

use jlawrence\eos\Parser;
solve($infix, $variables)

To use this function:

$value = Parser::solve($eq, $vars);
$infix

Is simply a standard equation with variable support.

Example Equations:

2(4x)
5+((1+2)*4)+3
5+4(1+2)+3
10*sin(x)
10*cos(x)

The parser has good implied multiplication.

$variables

The variables are fairly simple to understand. If it contains a scalar (ie a non-array value) every variable within the equation will be replaced with that number. If it contains an array, there will be a by-variable replacement - note that the array MUST be in the format of 'variable' => value
Such as:

array(
    'x' => 2,
    'y' => 3
);

Given the equation:

5x^y

If this is called by:

Parser::solveIF('5x^y', 2);

It will equal '20', as every variable is replaced by 2. However, if called like:

Parser::solveIF('5x^y', array(
                            'x' => 2,
                            'y' => 3));

You will get the result of '40' as it would equate to 5*2^3, as expected.

jlawrence\eos\Graph

To use:

use jlawrence\eos\Graph;

This is the fun class that can create graphs. The image will default to 640x480, to initialize a different size use:

Graph::init($width, $height);

The $width and $height are the values used for the image size.

graph($eq, $xLow, $xHigh, [$xStep, $xyGrid, $yGuess, ...])

This method will generate the graph for the equation ($eq) with a min and max x range that it will parse through. All Variables explained:

  • $eq The Standard Equation to use. Must have a variable in it. (ie x)
  • $xLow The starting point for the calculations - the left side of the graph.
  • $xHigh The last point calculated for the variable - the right side of the graph.
  • $xStep Stepping point for the variable. Set to null/false to use the smart xStep feature within the graph class.
  • $xyGrid = false Show x/y gridlines on the graph. Defaults to false. Each grid line is set at an integer, with a max of 30 lines, so it will calculate the stepping for it. When the grid is show, the lines are labeled along the top and left side of the image.
  • $yGuess = true Guess the Lower and Upper y-bounds (The bottom and top of the image respectively.) This will set the the bounds to the lowest y value encountered for the $yLow, and the largest y value for $yHigh.
  • $yLow = null Lower bound for y. Will be reset if a lower value for y is found if $yGuess is true.
  • $yHigh = null Upper bound for y. Will be reset if a larger y value is found if $yGuess is true.

If you don't want the axis' labeled with their numbers, you can turn off the default behavior with:

Graph::$labelAxis = false;

TODO:

  • Allow user-defined colors for all aspects of the graph.

To set up a graph with a 21x21 window (ie -10 to 10) for the equation sin(x) and output as PNG, would use as:

Graph::graph('sin(x)', -10, 10, 0.01, true, false, -10, 10);
Graph::outPNG();

It would look like:
Sin(x)

Development

Testing

Run the unit tests by first installing phpunit with (from the repository root)

composer update

Then run the tests with

phpunit

When creating classes for adding functions to the package, make sure to call Parser::solveIF() instead of Parser::solve() so that the class retains the full original equation used by the user.

jlawrence/eos 适用场景与选型建议

jlawrence/eos 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.16M 次下载、GitHub Stars 达 105, 最近一次更新时间为 2015 年 03 月 23 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「math」 「eos」 「solve」 「equations」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 jlawrence/eos 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 jlawrence/eos 我们能提供哪些服务?
定制开发 / 二次开发

基于 jlawrence/eos 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 1.16M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 107
  • 点击次数: 24
  • 依赖项目数: 17
  • 推荐数: 0

GitHub 信息

  • Stars: 105
  • Watchers: 10
  • Forks: 22
  • 开发语言: PHP

其他信息

  • 授权协议: LGPL-2.1
  • 更新时间: 2015-03-23