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


PHP Table::constraints方法代码示例

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


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

示例1: _generateSchema

 /**
  * Generates a string representation of a schema.
  *
  * @param \Cake\Database\Schema\Table $table Table schema
  * @return string fields definitions
  */
 protected function _generateSchema(Table $table)
 {
     $cols = $indexes = $constraints = [];
     foreach ($table->columns() as $field) {
         $fieldData = $table->column($field);
         $properties = implode(', ', $this->_values($fieldData));
         $cols[] = "        '{$field}' => [{$properties}],";
     }
     foreach ($table->indexes() as $index) {
         $fieldData = $table->index($index);
         $properties = implode(', ', $this->_values($fieldData));
         $indexes[] = "            '{$index}' => [{$properties}],";
     }
     foreach ($table->constraints() as $index) {
         $fieldData = $table->constraint($index);
         $properties = implode(', ', $this->_values($fieldData));
         $constraints[] = "            '{$index}' => [{$properties}],";
     }
     $options = $this->_values($table->options());
     $content = implode("\n", $cols) . "\n";
     if (!empty($indexes)) {
         $content .= "        '_indexes' => [\n" . implode("\n", $indexes) . "\n        ],\n";
     }
     if (!empty($constraints)) {
         $content .= "        '_constraints' => [\n" . implode("\n", $constraints) . "\n        ],\n";
     }
     if (!empty($options)) {
         foreach ($options as &$option) {
             $option = '            ' . $option;
         }
         $content .= "        '_options' => [\n" . implode(",\n", $options) . "\n        ],\n";
     }
     return "[\n{$content}    ]";
 }
开发者ID:AmuseXperience,项目名称:api,代码行数:40,代码来源:FixtureTask.php

示例2: fieldValidation

 /**
  * Does individual field validation handling.
  *
  * @param \Cake\Database\Schema\Table $schema The table schema for the current field.
  * @param string $fieldName Name of field to be validated.
  * @param array $metaData metadata for field
  * @param string $primaryKey The primary key field
  * @return array Array of validation for the field.
  */
 public function fieldValidation($schema, $fieldName, array $metaData, $primaryKey)
 {
     $ignoreFields = ['created', 'modified', 'updated'];
     if (in_array($fieldName, $ignoreFields)) {
         return false;
     }
     $rule = false;
     if ($fieldName === 'email') {
         $rule = 'email';
     } elseif ($metaData['type'] === 'uuid') {
         $rule = 'uuid';
     } elseif ($metaData['type'] === 'integer') {
         $rule = 'numeric';
     } elseif ($metaData['type'] === 'float') {
         $rule = 'numeric';
     } elseif ($metaData['type'] === 'decimal') {
         $rule = 'decimal';
     } elseif ($metaData['type'] === 'boolean') {
         $rule = 'boolean';
     } elseif ($metaData['type'] === 'date') {
         $rule = 'date';
     } elseif ($metaData['type'] === 'time') {
         $rule = 'time';
     } elseif ($metaData['type'] === 'datetime') {
         $rule = 'datetime';
     } elseif ($metaData['type'] === 'inet') {
         $rule = 'ip';
     }
     $allowEmpty = false;
     if (in_array($fieldName, $primaryKey)) {
         $allowEmpty = 'create';
     } elseif ($metaData['null'] === true) {
         $allowEmpty = true;
     }
     $validation = ['valid' => ['rule' => $rule, 'allowEmpty' => $allowEmpty]];
     foreach ($schema->constraints() as $constraint) {
         $constraint = $schema->constraint($constraint);
         if (!in_array($fieldName, $constraint['columns']) || count($constraint['columns']) > 1) {
             continue;
         }
         if ($constraint['type'] === SchemaTable::CONSTRAINT_UNIQUE) {
             $validation['unique'] = ['rule' => 'validateUnique', 'provider' => 'table'];
         }
     }
     return $validation;
 }
开发者ID:gbauso,项目名称:asirb,代码行数:55,代码来源:ModelTask.php

示例3: dropConstraintSql

 /**
  * {@inheritDoc}
  */
 public function dropConstraintSql(Table $table)
 {
     $sqlPattern = 'ALTER TABLE %s DROP CONSTRAINT %s;';
     $sql = [];
     foreach ($table->constraints() as $name) {
         $constraint = $table->constraint($name);
         if ($constraint['type'] === Table::CONSTRAINT_FOREIGN) {
             $tableName = $this->_driver->quoteIdentifier($table->name());
             $constraintName = $this->_driver->quoteIdentifier($name);
             $sql[] = sprintf($sqlPattern, $tableName, $constraintName);
         }
     }
     return $sql;
 }
开发者ID:AlexandreSGV,项目名称:siteentec,代码行数:17,代码来源:PostgresSchema.php

示例4: _getPrimaryKey

 /**
  * Returns table primary key.
  *
  * @param Table $table Table schema object.
  * @return array|null
  */
 protected function _getPrimaryKey(Table $table)
 {
     $constraints = $table->constraints();
     foreach ($constraints as $name) {
         $constraint = $table->constraint($name);
         if ($this->_isSingleKey($table, [$constraint])) {
             return $constraint;
         }
     }
     return null;
 }
开发者ID:cakedc,项目名称:cakephp-oracle-driver,代码行数:17,代码来源:OracleSchema.php

示例5: findTableReferencedBy

 /**
  * find the table, if any, actually referenced by the passed key field.
  * Search tables in db for keyField; if found search key constraints
  * for the table to which it refers.
  *
  * @param \Cake\Database\Schema\Table $schema The table schema to find a constraint for.
  * @param string $keyField The field to check for a constraint.
  * @return string|null Either the referenced table or null if the field has no constraints.
  */
 public function findTableReferencedBy($schema, $keyField)
 {
     if (!$schema->column($keyField)) {
         return null;
     }
     foreach ($schema->constraints() as $constraint) {
         $constraintInfo = $schema->constraint($constraint);
         if (in_array($keyField, $constraintInfo['columns'])) {
             if (!isset($constraintInfo['references'])) {
                 continue;
             }
             return $constraintInfo['references'][0];
         }
     }
     return null;
 }
开发者ID:ansidev,项目名称:cakephp_blog,代码行数:25,代码来源:ModelTask.php

示例6: testAddConstraintForeignKey

 /**
  * Add a basic foreign key constraint.
  *
  * @return void
  */
 public function testAddConstraintForeignKey()
 {
     $table = new Table('articles');
     $table->addColumn('author_id', 'integer')->addConstraint('author_id_idx', ['type' => Table::CONSTRAINT_FOREIGN, 'columns' => ['author_id'], 'references' => ['authors', 'id'], 'update' => 'cascade', 'delete' => 'cascade']);
     $this->assertEquals(['author_id_idx'], $table->constraints());
 }
开发者ID:neilan35,项目名称:betterwindow1,代码行数:11,代码来源:TableTest.php

示例7: _generateDropForeignKeys

 /**
  * Generates SQL statements dropping foreign keys for the table.
  *
  * @param \Cake\Database\Connection $db Connection to run the SQL queries on.
  * @param  \Cake\Database\Schema\Table $table Drop foreign keys for this table.
  * @return array List of SQL statements dropping foreign keys.
  */
 protected function _generateDropForeignKeys($db, Schema $table)
 {
     $type = 'other';
     if ($db->driver() instanceof Mysql) {
         $type = 'mysql';
     }
     $queries = [];
     foreach ($table->constraints() as $constraintName) {
         $constraint = $table->constraint($constraintName);
         if ($constraint['type'] === Schema::CONSTRAINT_FOREIGN) {
             // TODO: Move this into the driver
             if ($type === 'mysql') {
                 $template = 'ALTER TABLE %s DROP FOREIGN KEY %s';
             } else {
                 $template = 'ALTER TABLE %s DROP CONSTRAINT %s';
             }
             $queries[] = sprintf($template, $table->name(), $constraintName);
         }
     }
     return $queries;
 }
开发者ID:scherersoftware,项目名称:cakephp-schema,代码行数:28,代码来源:SchemaLoadTask.php


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