承接 jhumayun/shapes 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

jhumayun/shapes

Composer 安装命令:

composer require jhumayun/shapes

包简介

Library of shapes to calculate their area and perimeter

README 文档

README

Library of shapes to calculate their area and perimeter.

Composer install command

composer require jhumayun/shapes

Usage

The shapes class can be loaded in two ways

  1. Method 1: using namespace of the class
  2. Method 2: using ShapeFactory object (Recommended)

Loading shape using namespace

<?php
    // Require Autoloader
    require_once '../vendor/autoload.php';

    // Namespaces of the shapes in use
    use jhumayun\Shapes\shapes\Circle;
    use jhumayun\Shapes\shapes\Square;

    try{
        $circle_params = array(
                                'r'=>'10'
                            );
        $Circle = new Circle($circle_params);
        echo "<pre>Parameters of Circle: ".print_r($Circle->getParams() ,1)."</pre>";
        echo "<pre>Radius = 10</pre>";
        echo "<pre>Circle Perimeter: ".print_r($Circle->calculatePerimeter() ,1)."</pre>";
        echo "<pre>Circle Area: ".print_r($Circle->calculateArea() ,1)."</pre>";

        $Circle->setParam('r',2);
        echo "<pre>Radius = 2</pre>";
        echo "<pre>Circle Perimeter: ".print_r($Circle->calculatePerimeter() ,1)."</pre>";
        echo "<pre>Circle Area: ".print_r($Circle->calculateArea() ,1)."</pre>";
        
        $square_params = array(
            's'=>'1'
        );
        $Square = new Square($square_params);
        echo "<pre>Parameters of Square: ".print_r($Square->getParams() ,1)."</pre>";
        echo "<pre>Side = 1</pre>";
        echo "<pre>Square Perimeter: ".print_r($Square->calculatePerimeter() ,1)."</pre>";
        echo "<pre>Square Area: ".print_r($Square->calculateArea() ,1)."</pre>";
    }
    catch(\Exception $e){
        die('Caught exception '.$e->getMessage());
    }
?>

Loading Shape using ShapeFactory Class

<?php
    require_once '../vendor/autoload.php';
    
    use jhumayun\Shapes\core\ShapesFactory;

    try{
        $factory = new ShapesFactory();
        
        $circle_params = array(
            'r'=>'10'
        );
        $Circle = $factory::create('Circle'); // instentiating without parameters
        echo "<pre>Parameters of Circle: ".print_r($Circle->getParams() ,1)."</pre>";

        $Circle = $factory::create('Circle', $circle_params); // instentiating with parameters
        echo "<pre>Radius = 10</pre>";
        echo "<pre>Circle Perimeter: ".print_r($Circle->calculatePerimeter() ,1)."</pre>";
        echo "<pre>Circle Area: ".print_r($Circle->calculateArea() ,1)."</pre>";

        $Circle->setParam('r',2);
        echo "<pre>Radius = 2</pre>";
        echo "<pre>Circle Perimeter: ".print_r($Circle->calculatePerimeter() ,1)."</pre>";
        echo "<pre>Circle Area: ".print_r($Circle->calculateArea() ,1)."</pre>";

        $square_params = array(
        's'=>'1'
        );
        $Square = $factory::create('Square', $square_params);
        echo "<pre>Parameters of Square: ".print_r($Square->getParams() ,1)."</pre>";
        echo "<pre>Side = 1</pre>";
        echo "<pre>Square Perimeter: ".print_r($Square->calculatePerimeter() ,1)."</pre>";
        echo "<pre>Square Area: ".print_r($Square->calculateArea() ,1)."</pre>";
    }
    catch(\Exception $e){
        die('Caught exception '.$e->getMessage());
    }
?>

Method Description

MethodDescriptionReturn Type
getNameget Name of the shapestring
getDimensionsget dimensions of the shapenumeric
getParamsget parameter structure of the shapearray
setParamset value of single parameter of the shapevoid
calculatePerimetercalculate Perimeter of the shapenumeric
calculateAreacalculate Area of the shapenumeric

Adding a new Shape

Each shape extends ShapesBase Class which is an abstract class, and the ShapesBase implements ShapesTemplate. All the core functions are already defined in ShapesBase Class therefore new shape will need to define only constructor, calculatePerimeter method, calculateArea method.

Lets say, name of your new shape is myShape then you need to add a file myShape.php into 'src\shapes' directory as following.

<?php

namespace jhumayun\Shapes\shapes;

use jhumayun\Shapes\core\ShapesBase;

class myShape extends ShapesBase{

    protected $Name = 'myShape';

    protected $Dimensions = '2';

    protected $valid_params = array(
        'p1' => 'where p1 is the perameter 1 of myShape',
        'p2' => 'where p1 is the perameter 2 of myShape'
    );

    public function __construct($params){
        parent::__construct($this->Name, $this->Dimensions, $params);
    }

    public function calculatePerimeter(){
        // assume that formula of Perimeter of myShape is p1+p2
        $res = floatval($this->Params['p1']['value']) + floatval($this->Params['p2']['value']);
        return number_format($res,2,'.','');
    }

    public function calculateArea(){
        // assume that formula of Perimeter of myShape is p1*p2
        $res = floatval($this->Params['p1']['value']) * floatval($this->Params['p2']['value']);
        return number_format($res,2,'.','');
    }
}

jhumayun/shapes 适用场景与选型建议

jhumayun/shapes 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 17 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 12 月 31 日, 在 PHP 生态内属于活跃度较高的组件。

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: proprietary
  • 更新时间: 2018-12-31