ems/xtype 问题修复 & 功能扩展

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

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

ems/xtype

Composer 安装命令:

composer require ems/xtype

包简介

Semantic types for PHP

README 文档

README

Semantic atomic types for PHP

Usage

XType classifies datatypes. They are mainly used to scaffold forms and get centralized string formatting.

Instead of saying:

echo number_format($myObject->price,2,'.');

with xtype you can write:

class MyObject{

    public $price;
    
    public function getType(){
        return NamedFieldType::create()
           ->set('price', UnitType::create()->setUnit('$')->setDecimals(2));
    }
}

// Then in you're view:

$myObject = new MyObject();
echo $myObject->getType('price')->valueToString($myObject->price);

Where this seems to be very clumsy it offers its powers in big applications or big data centric applications. Imagine you have a class customer:

   class Customer{
   
       public $id;
       public $doubts;
       public $lastLogin;
       public $taxes;
       
       public function getType(){
           $type = NamedField::create();
           $type->set('id', NumberType::create()->setNativeType('int'))
           $type->set('doubts', CurrencyType::create()->setCurrency(''));
           $type->set('lastLogin', TemporalType::create();
           $type->set('taxes', PercentageType::create());
           return $type;
       }
   }
   
   $c = new Customer();
   
   foreach($c->getType() as $key=>$type){
       echo "\n$key=>".$type->valueToString($c->{$key});
   }

And in every part of youre application you can just forget any string formatting. But string formatting isn't the only usage of xtype. (i know about SOLID...)

Its on the other hand extremly useful to describe types. So you can build a database scheme of xtypes.

Another possibility is to scaffold forms with xtype.

Factory

To simply create an XType you can use XType\TemplateFactory::create($native) which creates a AbstractType by a native php variable.

Caution

This lib is in beta quality. The classes don't do much so it's not that dangerous to use em. So no docs or at this time

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-05-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固