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


PHP DataSource::describe方法代码示例

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


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

示例1: _alterTable

 /**
  * Alter Table method
  *
  * @param string $type Type of operation to be done
  * @param array $tables List of tables and fields
  * @return boolean Return true in case of success, otherwise false
  * @access protected
  */
 protected function _alterTable($type, $tables)
 {
     foreach ($tables as $table => $fields) {
         $indexes = array();
         if (isset($fields['indexes'])) {
             $indexes = $fields['indexes'];
             unset($fields['indexes']);
         }
         foreach ($fields as $field => $col) {
             $model = new Model(array('table' => $table, 'ds' => $this->connection));
             $tableFields = $this->db->describe($model);
             if ($type === 'drop') {
                 $field = $col;
             }
             if ($type !== 'add' && !isset($tableFields[$field])) {
                 throw new MigrationException($this, sprintf(__d('migrations', 'Field "%s" does not exists in "%s".', true), $field, $table));
             }
             switch ($type) {
                 case 'add':
                     if (isset($tableFields[$field])) {
                         throw new MigrationException($this, sprintf(__d('migrations', 'Field "%s" already exists in "%s".', true), $field, $table));
                     }
                     $sql = $this->db->alterSchema(array($table => array('add' => array($field => $col))));
                     break;
                 case 'drop':
                     $sql = $this->db->alterSchema(array($table => array('drop' => array($field => array()))));
                     break;
                 case 'change':
                     $sql = $this->db->alterSchema(array($table => array('change' => array($field => array_merge($tableFields[$field], $col)))));
                     break;
                 case 'rename':
                     $sql = $this->db->alterSchema(array($table => array('change' => array($field => array_merge($tableFields[$field], array('name' => $col))))));
                     break;
             }
             if ($type == 'rename') {
                 $data = array('table' => $table, 'old_name' => $field, 'new_name' => $col);
             } else {
                 $data = array('table' => $table, 'field' => $field);
             }
             $this->_invokeCallbacks('beforeAction', $type . '_field', $data);
             if (@$this->db->execute($sql) === false) {
                 throw new MigrationException($this, sprintf(__d('migrations', 'SQL Error: %s', true), $this->db->error));
             }
             $this->_invokeCallbacks('afterAction', $type . '_field', $data);
         }
         foreach ($indexes as $key => $index) {
             if (is_numeric($key)) {
                 $key = $index;
                 $index = array();
             }
             $sql = $this->db->alterSchema(array($table => array($type => array('indexes' => array($key => $index)))));
             $this->_invokeCallbacks('beforeAction', $type . '_index', array('table' => $table, 'index' => $key));
             if (@$this->db->execute($sql) === false) {
                 throw new MigrationException($this, sprintf(__d('migrations', 'SQL Error: %s', true), $this->db->error));
             }
             $this->_invokeCallbacks('afterAction', $type . '_index', array('table' => $table, 'index' => $key));
         }
     }
     return true;
 }
开发者ID:vinicius-ianni,项目名称:PHPMyScrum,代码行数:68,代码来源:cake_migration.php

示例2: describe

 /**
  * Since Datasource has the method `describe()`, it won't be caught `__call()`.
  * This ensures it is called on the original datasource properly.
  *
  * @param mixed $model
  * @return mixed
  */
 public function describe($model)
 {
     if (method_exists($this->source, 'describe')) {
         return $this->source->describe($model);
     }
     return $this->describe($model);
 }
开发者ID:jeremyharris,项目名称:cacher,代码行数:14,代码来源:CacheSource.php

示例3: _alterTable

 /**
  * Alter Table method
  *
  * @param string $type Type of operation to be done
  * @param array $tables List of tables and fields
  * @return boolean Return true in case of success, otherwise false
  * @access protected
  */
 public function _alterTable($type, $tables)
 {
     foreach ($tables as $table => $fields) {
         $indexes = array();
         if (isset($fields['indexes'])) {
             $indexes = $fields['indexes'];
             unset($fields['indexes']);
         }
         foreach ($fields as $field => $col) {
             switch ($type) {
                 case 'add':
                     $sql = $this->db->alterSchema(array($table => array('add' => array($field => $col))));
                     break;
                 case 'drop':
                     $field = $col;
                     $sql = $this->db->alterSchema(array($table => array('drop' => array($field => array()))));
                     break;
                 case 'change':
                     $model = new Model(array('table' => $table, 'ds' => $this->connection));
                     $tableFields = $this->db->describe($model);
                     $sql = $this->db->alterSchema(array($table => array('change' => array($field => array_merge($tableFields[$field], $col)))));
                     break;
                 case 'rename':
                     $model = new Model(array('table' => $table, 'ds' => $this->connection));
                     $tableFields = $this->db->describe($model);
                     $sql = $this->db->alterSchema(array($table => array('change' => array($field => array_merge($tableFields[$field], array('name' => $col))))));
                     break;
             }
             if ($type == 'rename') {
                 $data = array('table' => $table, 'old_name' => $field, 'new_name' => $col);
             } else {
                 $data = array('table' => $table, 'field' => $field);
             }
             $this->__invokeCallbacks('beforeAction', $type . '_field', $data);
             $this->db->execute($sql);
             $this->__invokeCallbacks('afterAction', $type . '_field', $data);
         }
         foreach ($indexes as $key => $index) {
             if (is_numeric($key)) {
                 $key = $index;
                 $index = array();
             }
             $sql = $this->db->alterSchema(array($table => array($type => array('indexes' => array($key => $index)))));
             $this->__invokeCallbacks('beforeAction', $type . '_index', array('table' => $table, 'index' => $key));
             $this->db->execute($sql);
             $this->__invokeCallbacks('afterAction', $type . '_index', array('table' => $table, 'index' => $key));
         }
     }
     return true;
 }
开发者ID:kiang,项目名称:olc_baker,代码行数:58,代码来源:CakeMigration.php

示例4: describe

 /**
  * Returns a Model description (metadata) or null if none found.
  *
  * @param Model|string $model Name of database table to inspect or model instance
  * @return array Array of Metadata for the $model
  */
 public function describe($model)
 {
     return parent::describe($model);
 }
开发者ID:oefenweb,项目名称:cakephp-redis,代码行数:10,代码来源:RedisSource.php

示例5: _alterTable

 /**
  * Alter Table method
  *
  * @param string $type Type of operation to be done
  * @param array $tables List of tables and fields
  * @return boolean Return true in case of success, otherwise false
  */
 protected function _alterTable($type, $tables)
 {
     foreach ($tables as $table => $fields) {
         $indexes = array();
         if (isset($fields['indexes'])) {
             $indexes = $fields['indexes'];
             unset($fields['indexes']);
         }
         if ($type == 'drop') {
             $this->_alterIndexes($indexes, $type, $table);
         }
         foreach ($fields as $field => $col) {
             $model = new Model(array('table' => $table, 'ds' => $this->connection));
             try {
                 $tableFields = $this->db->describe($model);
             } catch (Exception $e) {
                 throw new MigrationException($this, sprintf(__d('migrations', 'Table "%s" does not exists.'), $table));
             }
             if (!$tableFields) {
                 throw new MigrationException($this, sprintf(__d('migrations', 'Table "%s" does not exists.'), $table));
             }
             if ($type === 'drop') {
                 $field = $col;
             }
             if ($type !== 'add' && !isset($tableFields[$field])) {
                 throw new MigrationException($this, sprintf(__d('migrations', 'Field "%s" does not exists in "%s".'), $field, $table));
             }
             switch ($type) {
                 case 'add':
                     if (isset($tableFields[$field])) {
                         throw new MigrationException($this, sprintf(__d('migrations', 'Field "%s" already exists in "%s".'), $field, $table));
                     }
                     $sql = $this->db->alterSchema(array($table => array('add' => array($field => $col))));
                     break;
                 case 'drop':
                     $sql = $this->db->alterSchema(array($table => array('drop' => array($field => array()))));
                     break;
                 case 'change':
                     $def = array_merge($tableFields[$field], $col);
                     if (!empty($def['length']) && !empty($col['type']) && (substr($col['type'], 0, 4) == 'date' || substr($col['type'], 0, 4) == 'time')) {
                         $def['length'] = null;
                     }
                     $sql = $this->db->alterSchema(array($table => array('change' => array($field => $def))));
                     break;
                 case 'rename':
                     $sql = $this->db->alterSchema(array($table => array('change' => array($field => array_merge($tableFields[$field], array('name' => $col))))));
                     break;
             }
             if ($type == 'rename') {
                 $data = array('table' => $table, 'old_name' => $field, 'new_name' => $col);
             } else {
                 $data = array('table' => $table, 'field' => $field);
             }
             $this->_invokeCallbacks('beforeAction', $type . '_field', $data);
             if (@$this->db->execute($sql) === false) {
                 throw new MigrationException($this, sprintf(__d('migrations', 'SQL Error: %s'), $this->db->error));
             }
             $this->_invokeCallbacks('afterAction', $type . '_field', $data);
         }
         if ($type != 'drop') {
             $this->_alterIndexes($indexes, $type, $table);
         }
     }
     return true;
 }
开发者ID:Demired,项目名称:CakeWX,代码行数:72,代码来源:CakeMigration.php

示例6: describe

 /**
  * Returns a Model description (metadata) or null if none found.
  *
  * @param  object $model Reference to calling model
  * @return mixed         Model metadata
  */
 public function describe(&$model)
 {
     $cache = parent::describe($model);
     if ($cache != null) {
         return $cache;
     }
     $fields = (array) $this->read($model);
     return $fields;
 }
开发者ID:BigBlueHat,项目名称:divan,代码行数:15,代码来源:divan_source.php


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