| [ Index ] |
|
Code source de Symfony 1.0.0 |
1 <?php 2 3 /* 4 * $Id: PropelCreoleTransformTask.php 321 2006-01-03 17:44:56Z hans $ 5 * 6 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 7 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 8 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 9 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 10 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 11 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 12 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 13 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 14 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 15 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 16 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 17 * 18 * This software consists of voluntary contributions made by many individuals 19 * and is licensed under the LGPL. For more information please see 20 * <http://propel.phpdb.org>. 21 */ 22 23 include_once 'creole/Connection.php'; 24 require_once 'phing/Task.php'; 25 26 /** 27 * This class generates an XML schema of an existing database from 28 * Creole metadata. 29 * 30 * @author Hans Lellelid <hans@xmpl.org> (Propel) 31 * @author Jason van Zyl <jvanzyl@periapt.com> (Torque) 32 * @author Fedor Karpelevitch <fedor.karpelevitch@barra.com> (Torque) 33 * @version $Revision: 321 $ 34 * @package propel.phing 35 */ 36 class PropelCreoleTransformTask extends Task { 37 38 /** Name of XML database schema produced. */ 39 protected $xmlSchema; 40 41 /** Creole URL. */ 42 protected $dbUrl; 43 44 /** Creole driver. */ 45 protected $dbDriver; 46 47 /** Creole user name. */ 48 protected $dbUser; 49 50 /** Creole password. */ 51 protected $dbPassword; 52 53 /** DB encoding to use */ 54 protected $dbEncoding = 'iso-8859-1'; 55 56 /** DB schema to use. */ 57 protected $dbSchema; 58 59 /** parsed DB DSN */ 60 protected $dsn; 61 62 /** DOM document produced. */ 63 protected $doc; 64 65 /** The document root element. */ 66 protected $databaseNode; 67 68 /** Hashtable of columns that have primary keys. */ 69 protected $primaryKeys; 70 71 /** Hashtable to track what table a column belongs to. */ 72 // doesn't seem to be used 73 // protected $columnTableMap; 74 75 /** whether to use same name for phpName or not */ 76 protected $samePhpName; 77 78 /** whether to add vendor info or not */ 79 protected $addVendorInfo; 80 81 /** 82 * Bitfield to switch on/off which validators will be created. 83 * 84 * @var int 85 */ 86 protected $validatorBits; 87 88 /** 89 * Collect validatorInfos to create validators. 90 * 91 * @var int 92 */ 93 protected $validatorInfos; 94 95 /** 96 * Zero bit for no validators 97 */ 98 const VALIDATORS_NONE = 0; 99 100 /** 101 * Bit for maxLength validator 102 */ 103 const VALIDATORS_MAXLENGTH = 1; 104 105 /** 106 * Bit for maxValue validator 107 */ 108 const VALIDATORS_MAXVALUE = 2; 109 110 /** 111 * Bit for type validator 112 */ 113 const VALIDATORS_TYPE = 4; 114 115 /** 116 * Bit for required validator 117 */ 118 const VALIDATORS_REQUIRED = 8; 119 120 /** 121 * Bit for unique validator 122 */ 123 const VALIDATORS_UNIQUE = 16; 124 125 /** 126 * Bit for all validators 127 */ 128 const VALIDATORS_ALL = 255; 129 130 /** 131 * Maps validator type tokens to bits 132 * 133 * The tokens are used in the propel.addValidators property to define 134 * which validators are to be added 135 * 136 * @static 137 * @var array 138 */ 139 static protected $validatorBitMap = array ( 140 'none' => PropelCreoleTransformTask::VALIDATORS_NONE, 141 'maxlength' => PropelCreoleTransformTask::VALIDATORS_MAXLENGTH, 142 'maxvalue' => PropelCreoleTransformTask::VALIDATORS_MAXVALUE, 143 'type' => PropelCreoleTransformTask::VALIDATORS_TYPE, 144 'required' => PropelCreoleTransformTask::VALIDATORS_REQUIRED, 145 'unique' => PropelCreoleTransformTask::VALIDATORS_UNIQUE, 146 'all' => PropelCreoleTransformTask::VALIDATORS_ALL, 147 ); 148 149 /** 150 * Defines messages that are added to validators 151 * 152 * @static 153 * @var array 154 */ 155 static protected $validatorMessages = array ( 156 'maxlength' => array ( 157 'msg' => 'The field %s must be not longer than %s characters.', 158 'var' => array('colName', 'value') 159 ), 160 'maxvalue' => array ( 161 'msg' => 'The field %s must be not greater than %s.', 162 'var' => array('colName', 'value') 163 ), 164 'type' => array ( 165 'msg' => 'The field %s is not a valid value.', 166 'var' => array('colName') 167 ), 168 'required' => array ( 169 'msg' => 'The field %s is required.', 170 'var' => array('colName') 171 ), 172 'unique' => array ( 173 'msg' => 'This %s already exists in table %s.', 174 'var' => array('colName', 'tableName') 175 ), 176 ); 177 178 public function getDbSchema() 179 { 180 return $this->dbSchema; 181 } 182 183 public function setDbSchema($dbSchema) 184 { 185 $this->dbSchema = $dbSchema; 186 } 187 188 public function setDbUrl($v) 189 { 190 $this->dbUrl = $v; 191 } 192 193 public function setDbDriver($v) 194 { 195 $this->dbDriver = $v; 196 } 197 198 public function setDbUser($v) 199 { 200 $this->dbUser = $v; 201 } 202 203 public function setDbPassword($v) 204 { 205 $this->dbPassword = $v; 206 } 207 208 public function setDbEncoding($v) 209 { 210 $this->dbEncoding = $v; 211 } 212 213 public function setOutputFile($v) 214 { 215 $this->xmlSchema = $v; 216 } 217 218 public function setSamePhpName($v) 219 { 220 $this->samePhpName = $v; 221 } 222 223 public function setAddVendorInfo($v) 224 { 225 $this->addVendorInfo = (boolean) $v; 226 } 227 228 /** 229 * Sets set validator bitfield from propel.addValidators property 230 * 231 * @param string $v The propel.addValidators property 232 * @return void 233 */ 234 public function setAddValidators($v) 235 { 236 // lowercase input 237 $v = strtolower($v); 238 // make it a bit expression 239 $v = str_replace( 240 array_keys(self::$validatorBitMap), self::$validatorBitMap, $v); 241 // check if it's a valid boolean expression 242 if (!preg_match('/[^\d|&~ ]/', $v)) { 243 // eval the expression 244 eval("\$v = $v;"); 245 } else { 246 $this->log("\n\nERROR: NO VALIDATORS ADDED!\n\nThere is an error in propel.addValidators build property.\n\nAllowed tokens are: " . implode(', ', array_keys(self::$validatorBitMap)) . "\n\nAllowed operators are (like in php.ini):\n\n| bitwise OR\n& bitwise AND\n~ bitwise NOT\n\n", PROJECT_MSG_ERR); 247 $v = self::VALIDATORS_NONE; 248 } 249 $this->validatorBits = $v; 250 } 251 252 public function isSamePhpName() 253 { 254 return $this->samePhpName; 255 } 256 257 /** 258 * Default constructor. 259 * @return void 260 * @throws BuildException 261 */ 262 public function main() 263 { 264 $this->log("Propel - CreoleToXMLSchema starting"); 265 $this->log("Your DB settings are:"); 266 $this->log("driver : " . ($this->dbDriver ? $this->dbDriver : "(default)")); 267 $this->log("URL : " . $this->dbUrl); 268 269 //(not yet supported) $this->log("schema : " . $this->dbSchema); 270 //DocumentTypeImpl docType = new DocumentTypeImpl(null, "database", null, 271 // "http://jakarta.apache.org/turbine/dtd/database.dtd"); 272 273 $this->doc = new DOMDocument('1.0', 'utf-8'); 274 $this->doc->formatOutput = true; // pretty printing 275 276 $this->doc->appendChild($this->doc->createComment("Autogenerated by CreoleToXMLSchema!")); 277 278 try { 279 $this->generateXML(); 280 $this->log("Writing XML to file: " . $this->xmlSchema); 281 $outFile = new PhingFile($this->xmlSchema); 282 $out = new FileWriter($outFile); 283 $xmlstr = $this->doc->saveXML(); 284 $out->write($xmlstr); 285 $out->close(); 286 } catch (Exception $e) { 287 $this->log("There was an error building XML from metadata: " . $e->getMessage(), PROJECT_MSG_ERR); 288 } 289 $this->log("Propel - CreoleToXMLSchema finished"); 290 } 291 292 /** 293 * Generates an XML database schema from Creole metadata. 294 * 295 * @return void 296 * @throws Exception a generic exception. 297 */ 298 public function generateXML() 299 { 300 // Establish db connection 301 $con = $this->getConnection(); 302 303 // Get the database Metadata. 304 $dbInfo = $con->getDatabaseInfo(); 305 306 // create and add the database node 307 $databaseNode = $this->createDatabaseNode($dbInfo); 308 $this->doc->appendChild($databaseNode); 309 } 310 311 /** 312 * Establishes a Creole database connection 313 * 314 * @return object The connection 315 */ 316 protected function getConnection() { 317 318 // Attemtp to connect to a database. 319 $this->dsn = Creole::parseDSN($this->dbUrl); 320 if($this->dbUser) { 321 $this->dsn["username"] = $this->dbUser; 322 } 323 if ($this->dbPassword) { 324 $this->dsn["password"] = $this->dbPassword; 325 } 326 if ($this->dbDriver) { 327 Creole::registerDriver($this->dsn['phptype'], $this->dbDriver); 328 } 329 $con = Creole::getConnection($this->dsn); 330 $this->log("DB connection established"); 331 332 return $con; 333 } 334 335 /** 336 * Creates a database node 337 * 338 * @param object $dbInfo The dbInfo for this db 339 * @return object The database node instance 340 */ 341 protected function createDatabaseNode($dbInfo) { 342 343 $this->log("Processing database"); 344 345 $node = $this->doc->createElement("database"); 346 $node->setAttribute("name", $dbInfo->getName()); 347 348 if ($vendorNode = $this->createVendorInfoNode($dbInfo->getVendorSpecificInfo())) { 349 $node->appendChild($vendorNode); 350 } 351 352 // create and add table nodes 353 foreach($dbInfo->getTables() as $table) { 354 $tableNode = $this->createTableNode($table); 355 $node->appendChild($tableNode); 356 } 357 358 return $node; 359 } 360 361 /** 362 * Creates a table node 363 * 364 * @param object $table The table 365 * @return object The table node instance 366 */ 367 protected function createTableNode($table) { 368 369 $this->log("Processing table: " . $table->toString()); 370 371 $node = $this->doc->createElement("table"); 372 $node->setAttribute("name", $table->getName()); 373 if ($this->isSamePhpName()) { 374 $node->setAttribute("phpName", $table->getName()); 375 } 376 if ($vendorNode = $this->createVendorInfoNode($table->getVendorSpecificInfo())) { 377 $node->appendChild($vendorNode); 378 } 379 380 // Create and add column nodes, register column validators 381 $columns = $table->getColumns(); 382 foreach($columns as $column) { 383 $columnNode = $this->createColumnNode($column); 384 $node->appendChild($columnNode); 385 $this->registerValidatorsForColumn($column); 386 if ($column->isAutoIncrement()) { 387 $idMethod = 'native'; 388 } 389 } 390 if (isset($idMethod)) { 391 $node->setAttribute("idMethod", $idMethod); 392 } 393 394 // Create and add foreign key nodes. 395 $foreignKeys = $table->getForeignKeys(); 396 foreach($foreignKeys as $foreignKey) { 397 $foreignKeyNode = $this->createForeignKeyNode($foreignKey); 398 $node->appendChild($foreignKeyNode); 399 } 400 401 // Create and add index nodes. 402 $indices = $table->getIndices(); 403 foreach($indices as $index) { 404 $indexNode = $this->createIndexNode($index); 405 $node->appendChild($indexNode); 406 } 407 408 // add an id-method-parameter if we have a sequence that matches table_colname_seq 409 // 410 // 411 $pkey = $table->getPrimaryKey(); 412 if ($pkey) { 413 $cols = $pkey->getColumns(); 414 if (count($cols) === 1) { 415 $col = array_shift($cols); 416 if ($col->isAutoIncrement()) { 417 $seq_name = $table->getName().'_'.$col->getName().'_seq'; 418 if ($table->getDatabase()->isSequence($seq_name)) { 419 $idMethodParameterNode = $this->doc->createElement("id-method-parameter"); 420 $idMethodParameterNode->setAttribute("value", $seq_name); 421 $node->appendChild($idMethodParameterNode); 422 } 423 } 424 } 425 } 426 427 428 // Create and add validator and rule nodes. 429 $nodes = array(); 430 $tableName = $table->getName(); 431 if (isset($this->validatorInfos[$tableName])) { 432 foreach ($this->validatorInfos[$tableName] as $colName => $rules) { 433 $column = $table->getColumn($colName); 434 $colName = $column->getName(); 435 foreach ($rules as $rule) { 436 if (!isset($nodes[$colName])) { 437 $nodes[$colName] = $this->createValidator($column, $rule['type']); 438 $node->appendChild($nodes[$colName]); 439 } 440 $ruleNode = $this->createRuleNode($column, $rule); 441 $nodes[$colName]->appendChild($ruleNode); 442 } 443 } 444 } 445 446 return $node; 447 } 448 449 /** 450 * Creates an column node 451 * 452 * @param object $column The Creole column 453 * @return object The column node instance 454 */ 455 protected function createColumnNode($column) { 456 457 $node = $this->doc->createElement("column"); 458 459 $table = $column->getTable(); 460 $colName = $column->getName(); 461 $colType = $column->getType(); 462 $colSize = $column->getSize(); 463 $colScale = $column->getScale(); 464 465 if ($colType === CreoleTypes::OTHER) { 466 $this->log("Column [" . $table->getName() . "." . $colName . "] has a column type (".$column->getNativeType().") that Propel does not support.", PROJECT_MSG_WARN); 467 } 468 469 $node->setAttribute("name", $colName); 470 471 if ($this->isSamePhpName()) { 472 $node->setAttribute("phpName", $colName); 473 } 474 475 $node->setAttribute("type", PropelTypes::getPropelType($colType)); 476 477 if ($colSize > 0 && ( 478 $colType == CreoleTypes::CHAR 479 || $colType == CreoleTypes::VARCHAR 480 || $colType == CreoleTypes::LONGVARCHAR 481 || $colType == CreoleTypes::DECIMAL 482 || $colType == CreoleTypes::FLOAT 483 || $colType == CreoleTypes::NUMERIC)) { 484 $node->setAttribute("size", (string) $colSize); 485 } 486 487 if ($colScale > 0 && ( 488 $colType == CreoleTypes::DECIMAL 489 || $colType == CreoleTypes::FLOAT 490 || $colType == CreoleTypes::NUMERIC)) { 491 $node->setAttribute("scale", (string) $colScale); 492 } 493 494 if (!$column->isNullable()) { 495 $node->setAttribute("required", "true"); 496 } 497 498 if ($column->isAutoIncrement()) { 499 $node->setAttribute("autoIncrement", "true"); 500 } 501 502 if (in_array($colName, $this->getTablePkCols($table))) { 503 $node->setAttribute("primaryKey", "true"); 504 } 505 506 if (($defValue = $column->getDefaultValue()) !== null) { 507 $node->setAttribute("default", iconv($this->dbEncoding, 'utf-8', $defValue)); 508 } 509 510 if ($vendorNode = $this->createVendorInfoNode($column->getVendorSpecificInfo())) { 511 $node->appendChild($vendorNode); 512 } 513 514 return $node; 515 } 516 517 /** 518 * Returns the primary key columns for a table 519 * 520 * @param object $table The table 521 * @return array The primary keys 522 */ 523 protected function getTablePkCols($table) { 524 525 static $columns = array(); 526 527 $tableName = $table->getName(); 528 if (!isset($columns[$tableName])) { 529 $columns[$tableName] = array(); 530 $primaryKey = $table->getPrimaryKey(); 531 if ($primaryKey) { 532 foreach($primaryKey->getColumns() as $colObject) { 533 $columns[$tableName][] = $colObject->getName(); 534 } 535 } 536 } 537 return $columns[$tableName]; 538 } 539 540 /** 541 * Creates an foreign key node 542 * 543 * @param object $foreignKey The foreign key 544 * @return object The foreign key node instance 545 */ 546 protected function createForeignKeyNode($foreignKey) { 547 548 $node = $this->doc->createElement("foreign-key"); 549 if ($vendorNode = $this->createVendorInfoNode($foreignKey->getVendorSpecificInfo())) { 550 $node->appendChild($vendorNode); 551 } 552 553 $refs = $foreignKey->getReferences(); 554 // all references must be to same table, so we can grab table from the first, foreign column 555 $node->setAttribute("foreignTable", $refs[0][1]->getTable()->getName()); 556 $node->setAttribute("onDelete", $refs[0][2]); 557 $node->setAttribute("onUpdate", $refs[0][3]); 558 for($m = 0, $size = count($refs); $m < $size; $m++) { 559 $refNode = $this->doc->createElement("reference"); 560 $refData = $refs[$m]; 561 $refNode->setAttribute("local", $refData[0]->getName()); 562 $refNode->setAttribute("foreign", $refData[1]->getName()); 563 $node->appendChild($refNode); 564 } 565 566 return $node; 567 } 568 569 /** 570 * Creates an index node 571 * 572 * @param object $index The index 573 * @return object The index node instance 574 */ 575 protected function createIndexNode($index) { 576 577 $indexType = $index->isUnique() ? 'unique' : 'index'; 578 579 $node = $this->doc->createElement($indexType); 580 $node->setAttribute("name", $index->getName()); 581 582 $columns = $index->getColumns(); 583 foreach ($columns as $column) { 584 $tableName = $column->getTable()->getName(); 585 $colName = $column->getName(); 586 $columnNode = $this->doc->createElement("{$indexType}-column"); 587 $columnNode->setAttribute("name", $colName); 588 $node->appendChild($columnNode); 589 if ($indexType == 'unique' && $this->isValidatorRequired('unique')) { 590 $this->validatorInfos[$tableName][$colName][] = array('type' => 'unique'); 591 } 592 } 593 594 if ($vendorNode = $this->createVendorInfoNode($index->getVendorSpecificInfo())) { 595 $node->appendChild($vendorNode); 596 } 597 598 return $node; 599 } 600 601 /** 602 * Checks whether to add validators of specified type or not 603 * 604 * @param string $type The validator type 605 * @return boolean 606 */ 607 protected function isValidatorRequired($type) { 608 $type = strtolower($type); 609 return ($this->validatorBits & self::$validatorBitMap[$type] ? true : false); 610 } 611 612 /** 613 * Registers column type specific validators if necessary 614 * 615 * We'll first collect the validators/rule infos and add them later on to 616 * have them appended to the table tag as a block. 617 * 618 * CreoleTypes are: 619 * 620 * BOOLEAN 621 * BIGINT, SMALLINT, TINYINT, INTEGER 622 * FLOAT, DOUBLE, NUMERIC, DECIMAL, REAL 623 * BIGINT, SMALLINT, TINYINT, INTEGER 624 * TEXT 625 * BLOB, CLOB, BINARY, VARBINARY, LONGVARBINARY 626 * DATE, YEAR, TIME 627 * TIMESTAMP 628 * 629 * We will add the following type specific validators: 630 * 631 * for notNull columns: required validator 632 * for unique indexes: unique validator 633 * for varchar types: maxLength validators (CHAR, VARCHAR, LONGVARCHAR) 634 * for numeric types: maxValue validators (BIGINT, SMALLINT, TINYINT, INTEGER, FLOAT, DOUBLE, NUMERIC, DECIMAL, REAL) 635 * for integer and timestamp types: notMatch validator with [^\d]+ (BIGINT, SMALLINT, TINYINT, INTEGER, TIMESTAMP) 636 * for float types: notMatch validator with [^\d\.]+ (FLOAT, DOUBLE, NUMERIC, DECIMAL, REAL) 637 * 638 * @param object $column The Creole column 639 * @return void 640 * @todo find out how to evaluate the appropriate size and adjust maxValue rule values appropriate 641 * @todo find out if float type column values must always notMatch('[^\d\.]+'), i.e. digits and point for any db vendor, language etc. 642 */ 643 protected function registerValidatorsForColumn($column) { 644 645 $table = $column->getTable(); 646 $tableName = $table->getName(); 647 648 $colName = $column->getName(); 649 $colType = $column->getType(); 650 $colSize = $column->getSize(); 651 652 if ($this->isValidatorRequired('required')) { 653 $ruleInfo = array('type' => 'required'); 654 $this->validatorInfos[$tableName][$colName][] = $ruleInfo; 655 } 656 $isPrimarykeyCol = in_array($colName, $this->getTablePkCols($table)); 657 if ($this->isValidatorRequired('unique') && $isPrimarykeyCol) { 658 $ruleInfo = array('type' => 'unique'); 659 $this->validatorInfos[$tableName][$colName][] = $ruleInfo; 660 } 661 if ($this->isValidatorRequired('maxLength') && 662 $colSize > 0 && in_array($colType, array( 663 CreoleTypes::CHAR, 664 CreoleTypes::VARCHAR, 665 CreoleTypes::LONGVARCHAR))) { 666 $ruleInfo = array('type' => 'maxLength', 'value' => $colSize); 667 $this->validatorInfos[$tableName][$colName][] = $ruleInfo; 668 } 669 if ($this->isValidatorRequired('maxValue') && 670 $colSize > 0 && in_array($colType, array( 671 CreoleTypes::SMALLINT, 672 CreoleTypes::TINYINT, 673 CreoleTypes::INTEGER, 674 CreoleTypes::BIGINT, 675 CreoleTypes::FLOAT, 676 CreoleTypes::DOUBLE, 677 CreoleTypes::NUMERIC, 678 CreoleTypes::DECIMAL, 679 CreoleTypes::REAL))) { 680 681 // TODO: how to evaluate the appropriate size?? 682 $this->log("WARNING: maxValue validator added for column $colName. You will have to adjust the size value manually.", PROJECT_MSG_WARN); 683 $ruleInfo = array('type' => 'maxValue', 'value' => $colSize); 684 $this->validatorInfos[$tableName][$colName][] = $ruleInfo; 685 } 686 if ($this->isValidatorRequired('type') && 687 $colSize > 0 && in_array($colType, array( 688 CreoleTypes::SMALLINT, 689 CreoleTypes::TINYINT, 690 CreoleTypes::INTEGER, 691 CreoleTypes::TIMESTAMP))) { 692 $ruleInfo = array('type' => 'type', 'value' => '[^\d]+'); 693 $this->validatorInfos[$tableName][$colName][] = $ruleInfo; 694 } 695 if ($this->isValidatorRequired('type') && 696 $colSize > 0 && in_array($colType, array( 697 CreoleTypes::FLOAT, 698 CreoleTypes::DOUBLE, 699 CreoleTypes::NUMERIC, 700 CreoleTypes::DECIMAL, 701 CreoleTypes::REAL))) { 702 // TODO: is this always true?? 703 $ruleInfo = array('type' => 'type', 'value' => '[^\d\.]+'); 704 $this->validatorInfos[$tableName][$colName][] = $ruleInfo; 705 } 706 } 707 708 /** 709 * Creates a validator node 710 * 711 * @param object $column The Creole column 712 * @param integer $type The validator type 713 * @return object The validator node instance 714 */ 715 protected function createValidator($column, $type) { 716 717 $node = $this->doc->createElement('validator'); 718 $node->setAttribute('column', $column->getName()); 719 720 return $node; 721 } 722 723 /** 724 * Creates a rule node 725 * 726 * @param object $column The Creole column 727 * @param array $rule The rule info 728 * @return object The rule node instance 729 */ 730 protected function createRuleNode($column, $rule) { 731 732 extract($rule); 733 734 // create message 735 $colName = $column->getName(); 736 $tableName = $column->getTable()->getName(); 737 $msg = self::$validatorMessages[strtolower($type)]; 738 array_unshift($tmp = compact($msg['var']), $msg['msg']); 739 $msg = call_user_func_array('sprintf', $tmp); 740 741 // add node 742 $node = $this->doc->createElement('rule'); 743 $node->setAttribute('name', $type == 'type' ? 'notMatch' : $type); 744 $node->setAttribute('message', $msg); 745 746 return $node; 747 } 748 749 /** 750 * Creates a vendor info node 751 * 752 * returns false if no vendor info can or has to be added 753 * 754 * @param array $vendorInfo The validator info 755 * @return object|boolean The vendor info instance or false 756 */ 757 protected function createVendorInfoNode($vendorInfo) 758 { 759 if(!$vendorInfo OR !$this->addVendorInfo) { 760 return false; 761 } 762 763 $vendorNode = $this->doc->createElement("vendor"); 764 $vendorNode->setAttribute("type", $this->dsn["phptype"]); 765 766 foreach($vendorInfo as $key => $value) { 767 $parameterNode = $this->doc->createElement("parameter"); 768 $value = iconv($this->dbEncoding, "utf-8", $value); 769 $parameterNode->setAttribute("name", $key); 770 $parameterNode->setAttribute("value", $value); 771 $vendorNode->appendChild($parameterNode); 772 } 773 774 return $vendorNode; 775 } 776 777 } 778 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
| Généré le : Fri Mar 16 22:42:14 2007 | par Balluche grâce à PHPXref 0.7 |