当前位置: 首页>>代码示例>>PHP>>正文


PHP Params::generic方法代码示例

本文整理汇总了PHP中Params::generic方法的典型用法代码示例。如果您正苦于以下问题:PHP Params::generic方法的具体用法?PHP Params::generic怎么用?PHP Params::generic使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Params的用法示例。


在下文中一共展示了Params::generic方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: populate

 /**
  * Populates the given DatabaseObject with dummy data
  *
  * @param DatabaseObject $obj
  * @return void
  */
 protected function populate(DatabaseObject &$obj)
 {
     $meta = $obj->meta();
     $key = $meta->getKey();
     $fields = $meta->getColumnMap();
     foreach ($fields as $property => $field) {
         if ($field == $key && isset($obj->{$property})) {
             continue;
         }
         $def = $meta->getColumnDefinition($field);
         $type = strtolower(Params::generic($def, 'native_type'));
         switch ($type) {
             case 'int':
             case 'integer':
             case 'float':
             case 'currency':
             case 'decimal':
             case 'double':
             case 'real':
             case 'tinyint':
             case 'short':
             case 'long':
                 $obj->{$property} = mt_rand(0, 100);
                 break;
             case 'date':
             case 'datetime':
             case 'timestamp':
                 // Fuzz two weeks around now
                 $window = 1209600;
                 // 14 days * 24 hours * 60 minutes * 60 seconds
                 $time = time() - $window / 2 + mt_rand(0, $window);
                 if ($type == 'date') {
                     $lt = localtime($time, true);
                     $time = mktime(0, 0, 0, $lt['tm_mday'], $lt['tm_mon'] + 1, $lt['tm_year'] + 1900);
                     $lt = null;
                 }
                 $obj->{$property} = $time;
                 break;
             case 'time':
                 // range is +- 838:59:59, but since this populate thing
                 // isn't really all it could be anyhow, let's just do
                 // positive values
                 $obj->{$property} = mt_rand(1, 839 * 60 * 60 - 1);
                 break;
             case 'var_string':
                 $obj->{$property} = 'dummy string content ' . uniqid();
                 break;
             default:
                 $obj->{$property} = uniqid();
                 break;
         }
     }
 }
开发者ID:jcorbinredtree,项目名称:framework,代码行数:59,代码来源:FrameworkTestCase.php

示例2: getFieldSetSQL

 /**
  * Builds the needed SQL fragment to update or insert fields.
  *
  * @param bindByName boolean whether to generate named bind parameters, true by
  * default.
  * @param glue mixed if set to null, than an array of columns is returned,
  * otherwise glue is used to implode the array and a string is returned.
  * The default is to implode on ', '.
  *
  * @return string like "col1=:?, col2=:?" or "col1=:col1, col2=:col2"
  */
 public function getFieldSetSQL($cols = null, $bindByName = true, $glue = ', ')
 {
     if (!isset($cols)) {
         $cols = $this->getAutomaticColumns();
     }
     $set = array();
     foreach ($cols as $column) {
         if ($this->isManualColumn($column)) {
             continue;
         }
         if ($bindByName) {
             $value = ":{$column}";
         } else {
             $value = '?';
         }
         $def = $this->getColumnDefinition($column);
         switch (strtolower(Params::generic($def, 'native_type'))) {
             case 'time':
                 $value = "SEC_TO_TIME({$value})";
                 break;
             case 'date':
             case 'datetime':
             case 'timestamp':
                 $value = "FROM_UNIXTIME({$value})";
                 break;
         }
         array_push($set, "`{$column}`={$value}");
     }
     if ($glue) {
         return implode($glue, $set);
     } else {
         return $set;
     }
 }
开发者ID:jcorbinredtree,项目名称:framework,代码行数:45,代码来源:DatabaseObjectAbstractMeta.php

示例3: testGeneric

 public function testGeneric()
 {
     $generic = array('existingkey' => 23);
     $this->assertTrue(23 == Params::generic($generic, 'existingkey'), 'finds key');
     $this->assertTrue('default' == Params::generic($generic, 'badkey', 'default'), 'gets default');
 }
开发者ID:jcorbinredtree,项目名称:framework,代码行数:6,代码来源:ParamsTest.php


注:本文中的Params::generic方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。