枚举功能类

enum.php

/**
 * 本类主要是实现枚举的功能
 * @param unknown_type $base_class
 * @param unknown_type $args
 * @param unknown_type $codeArgs
 */
function enum($base_class, array $args,array $codeArgs){
    $class_parts = preg_split('/\s+/', $base_class);
    $base_class_name = array_shift($class_parts);
    $enums = array();
    $array=null;
    $arrayFlip = null;
    foreach ($args as $k => $enum) {
        $array .= '\''.$k.'\' => \''.$codeArgs[$k].'\' ,';
        $arrayFlip .= '\''.$enum.'\' => \''.$k.'\' ,';
        if(is_integer($k)){
            $valuestr = 'protected $value = '. $k .' ;';
        }else{
            $valuestr = 'protected $value = \''. $k . '\';';
        }
        $static_method = 'public static function ' . $enum .
            '() { return ' . $base_class_name.'_'.$enum . '::instance(); }';
        $enums[$static_method] = '
            class ' . $base_class_name.'_'.$enum . ' extends ' . $base_class_name . '{
                private static $instance = null;
               '.$valuestr.'private function __construct() {}
                private function __clone() {}
                public function getLabel() {return \''.$codeArgs[$k] .'\'; }
                public static function instance() {
                    if (self::$instance === null) { self::$instance = new self(); }
                    return self::$instance;
                }
            }';
                         
    }
    $base_class_declaration = sprintf('
        abstract class %s {
            protected $value = null;
            %s
            public static function iterator() { return %sIterator::instance(); }
            public function value() { return $this->value; }
            public function __toString() { return (string) $this->value; }
            public function compare($code) {return  (string)$code === (string)$this->value; }
            public static function compareNull($code) {return  $code== "-1"; }
            public static function toArray() { return array(%s); }
            public static function toArrayforkey() { return array_flip(array(%s)); }
            public static function toArrayflipforkey() { return array(%s); }
            public static function toLabel($code) { $a=array(%s); if($code === "" ){return "" ; }else{ return $a[$code];} }
            public static function toArrayMerge($fdarray = null) {if($fdarray == null)
            {return array("-1"=>"请选择")+array(%s);}else{if(is_array($fdarray))
            {return $fdarray+array(%s);}else{return array("-1"=>$fdarray)+array(%s);}}}
        };',
        $base_class,
        implode(PHP_EOL, array_keys($enums)),
        $base_class_name,
        $array,$arrayFlip,$arrayFlip,$array,$array,$array,$array
        );
    $iterator_declaration = sprintf('
        class %sIterator implements Iterator {
            private static $instance = null;
            private $values = array(\'%s\');
            private function __construct() {}
            private function __clone() {}
            public static function instance() {
                if (self::$instance === null) { self::$instance = new self(); }
                return self::$instance;
            }
            public function current() {
                $value = current($this->values);
                if ($value === false) { return false; }
                return call_user_func(array(\'%s\', $value));
            }
            public function key() { return key($this->values); }
            public function next() {
                next($this->values);
                return $this->current();
            }
            public function rewind() { return reset($this->values); }
            public function valid() { return (bool) $this->current(); }
        };',
        $base_class_name,
        implode('\',\'', $args),
        $base_class_name);
    eval($base_class_declaration);
    eval($iterator_declaration);
    eval(implode(PHP_EOL, $enums));
}


code.php

<?php
enum('SQ_isDelete',array(0=>'notDelete',1=>'deleted'),array(0=>'未删除',1=>'已删除' ));
enum('SQ_sex',array(1=>'male',2=>'female'),array(1=>'男',2=>'女' ));
enum('SQ_areaLevel',array(1=>'provice',2=>'city',3=>'district'),array(1=>'省',2=>'市',3=>'区' ));
enum('SQ_whiteFlg',array(0=>'no',1=>'yes'),array(0=>'不是白名单',1=>'是白名单' ));
enum('SQ_propertyDiff',array(0=>'normal',1=>'sale'),array(0=>'普通属性',1=>'销售属性' ));
enum('SQ_isMust',array(0=>'no',1=>'yes'),array(0=>'否',1=>'是' ));
enum('SQ_selectDiff',array(0=>'notShow',1=>'show'),array(0=>'前台不显示',1=>'前台显示' ));
enum('SQ_isAllowAlias',array(0=>'no',1=>'yes'),array(0=>'不允许',1=>'允许' ));
enum('SQ_viewDiff',array(0=>'words',1=>'picture'),array(0=>'文字',1=>'图片' ));
enum('SQ_state',array(1=>'shopOpen',2=>'shopClose'),array(1=>'开店',2=>'闭店' ));
enum('SQ_filePath',array(1=>'goods',2=>'shop',3=>'market',4=>'goodssort',5=>'shopsort',6=>'member',7=>'home',8=>'advert'),array(1=>'goods',2=>'shop',3=>'market',4=>'goodssort',5=>'shopsort',6=>'member',7=>'home',8=>'advert' ));
enum('SQ_leaf',array(0=>'notLeaf',1=>'isLeaf'),array(0=>'否',1=>'是' ));
enum('SQ_shopLevel',array(1=>'firstLevel',2=>'secondLevel'),array(1=>'一级',2=>'二级' ));
enum('SQ_goodsLevel',array(1=>'firstLevel',2=>'secondLevel',3=>'thirdLevel'),array(1=>'一级',2=>'二级',3=>'三级' ));
enum('SQ_memberState',array(0=>'memberOpen',1=>'memberClose'),array(0=>'停用',1=>'启用' ));
enum('SQ_activationState',array(0=>'activate',1=>'noactivate'),array(0=>'未激活',1=>'已激活' ));
enum('SQ_son',array(1=>'need',2=>'supply'),array(1=>'需求方',2=>'供应方' ));
enum('SQ_amtype',array(1=>'announcement',2=>'important'),array(1=>'公告',2=>'重要' ));
enum('SQ_oddType',array(1=>'orderNum',2=>'deliveryNum'),array(1=>'订单号',2=>'发货单号' ));
enum('SQ_activitytype',array(1=>'group',2=>'flash'),array(1=>'团购',2=>'闪购' ));
enum('SQ_judgetype',array(0=>'badreputation',1=>'goodreputation'),array(0=>'差评',1=>'好评' ));
enum('SQ_optenstate',array(0=>'unopened',1=>'opened'),array(0=>'未公开',1=>'已公开' ));
enum('SQ_replystate',array(0=>'unreturned',1=>'returned'),array(0=>'未回复',1=>'已回复' ));
enum('SQ_activitystate',array(1=>'noreview',2=>'reviewing',3=>'notpass',4=>'pass',5=>'onshelf',6=>'offshelf'),array(1=>'未审核',2=>'审核中',3=>'审核未通过',4=>'审核通过',5=>'已上架',6=>'已下架' ));
enum('SQ_paymentmethod',array(0=>'online',1=>'cash'),array(0=>'网上付款',1=>'货到付款' ));
enum('SQ_adtype',array(1=>'rollingadvertising',2=>'recommend',3=>'brandstreet'),array(1=>'超市滚动广告位',2=>'超市精品推荐',3=>'品牌街头部广告' ));
enum('SQ_roleid',array(1=>'shop',2=>'market',3=>'station',4=>'delivery'),array(1=>'品牌店',2=>'超市',3=>'工作站',4=>'配送员' ));
enum('SQ_retype',array(1=>'new1',2=>'good'),array(1=>'新品',2=>'精品' ));
enum('SQ_entityDistinguish',array(1=>'shop',2=>'market'),array(1=>'品牌店',2=>'超市' ));
enum('SQ_orderstate',array(0=>'waitsend',1=>'sended',2=>'received',9=>'canceled'),array(0=>'待发货',1=>'已发货',2=>'已收货',9=>'已取消' ));
enum('SQ_itemStatus',array(1=>'onsell',2=>'offsell'),array(1=>'上架',2=>'下架 ' ));
enum('SQ_sellerorderstate',array(0=>'waitsend',1=>'packing',2=>'sended',3=>'received'),array(0=>'待发货',1=>'打包中',2=>'已发货',3=>'已收货' ));
enum('SQ_memorderstate',array(0=>'waitsend',1=>'sended',2=>'received'),array(0=>'待发货',1=>'已发货',2=>'已收货' ));
enum('SQ_stationorderstate',array(0=>'waitreceived',1=>'waitsend',2=>'sended',3=>'received'),array(0=>'待收中',1=>'待发货',2=>'已发货',3=>'已收货' ));
enum('SQ_timetype',array(1=>'week',2=>'month',3=>'year'),array(1=>'周',2=>'月',3=>'年' ));


使用:
$param['optenstate'] = SQ_optenstate::opened()->value();

你可能感兴趣的:(function,null)