Apache Zeta Components Manual :: File Source for schema_diff.php

Source for file schema_diff.php

Documentation is available at schema_diff.php

  1. <?php
  2. /**
  3.  *
  4.  * Licensed to the Apache Software Foundation (ASF) under one
  5.  * or more contributor license agreements.  See the NOTICE file
  6.  * distributed with this work for additional information
  7.  * regarding copyright ownership.  The ASF licenses this file
  8.  * to you under the Apache License, Version 2.0 (the
  9.  * "License"); you may not use this file except in compliance
  10.  * with the License.  You may obtain a copy of the License at
  11.  * 
  12.  *   http://www.apache.org/licenses/LICENSE-2.0
  13.  * 
  14.  * Unless required by applicable law or agreed to in writing,
  15.  * software distributed under the License is distributed on an
  16.  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17.  * KIND, either express or implied.  See the License for the
  18.  * specific language governing permissions and limitations
  19.  * under the License.
  20.  *
  21.  * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
  22.  * @version //autogentag//
  23.  * @filesource
  24.  * @package DatabaseSchema
  25.  */
  26. /**
  27.  * ezcDbSchemaDiff is the main class for schema differences operations.
  28.  *
  29.  * @package DatabaseSchema
  30.  * @version //autogentag//
  31.  * @mainclass
  32.  */
  33. {
  34.     /**
  35.      * All added tables
  36.      *
  37.      * @var array(string=>ezcDbSchemaTable) 
  38.      */
  39.     public $newTables;
  40.  
  41.     /**
  42.      * All changed tables
  43.      *
  44.      * @var array(string=>ezcDbSchemaTableDiff) 
  45.      */
  46.     public $changedTables;
  47.  
  48.     /**
  49.      * All removed tables
  50.      *
  51.      * @var array(string=>bool) 
  52.      */
  53.     public $removedTables;
  54.  
  55.     /**
  56.      * Constructs an ezcDbSchemaDiff object.
  57.      *
  58.      * @param array(string=>ezcDbSchemaTable)      $newTables 
  59.      * @param array(string=>ezcDbSchemaTableDiff)  $changedTables 
  60.      * @param array(string=>bool)                  $removedTables 
  61.      */
  62.     public function __construct$newTables array()$changedTables array()$removedTables array() )
  63.     {
  64.         $this->newTables = $newTables;
  65.         $this->changedTables = $changedTables;
  66.         $this->removedTables = $removedTables;
  67.     }
  68.  
  69.     static public function __set_statearray $array )
  70.     {
  71.         return new ezcDbSchemaDiff(
  72.              $array['newTables']$array['changedTables']$array['removedTables']
  73.         );
  74.     }
  75.  
  76.     /**
  77.      * Checks whether the object in $obj implements the correct $type of reader handler.
  78.      *
  79.      * @throws ezcDbSchemaInvalidReaderClassException if the object in $obj is
  80.      *          not a schema reader of the correct type.
  81.      *
  82.      * @param ezcDbSchemaReader $obj 
  83.      * @param int               $type 
  84.      */
  85.     static private function checkSchemaDiffReader$obj$type )
  86.     {
  87.         if !( ( $obj->getDiffReaderType($type == $type ) )
  88.         {
  89.             throw new ezcDbSchemaInvalidReaderClassExceptionget_class$obj )$type );
  90.         }
  91.     }
  92.  
  93.     /**
  94.      * Factory method to create a ezcDbSchemaDiff object from the file $file with the format $format.
  95.      *
  96.      * @throws ezcDbSchemaInvalidReaderClassException if the handler associated
  97.      *          with the $format is not a file schema reader.
  98.      *
  99.      * @param string $format 
  100.      * @param string $file 
  101.      * @return ezcDbSchemaDiff 
  102.      */
  103.     static public function createFromFile$format$file )
  104.     {
  105.         $className ezcDbSchemaHandlerManager::getDiffReaderByFormat$format );
  106.         $reader new $className();
  107.         self::checkSchemaDiffReader$readerezcDbSchema::FILE );
  108.         return $reader->loadDiffFromFile$file );
  109.     }
  110.  
  111.     /**
  112.      * Checks whether the object in $obj implements the correct $type of writer handler.
  113.      *
  114.      * @throws ezcDbSchemaInvalidWriterClassException if the object in $obj is
  115.      *          not a schema writer of the correct type.
  116.      *
  117.      * @param ezcDbSchemaWriter $obj 
  118.      * @param int               $type 
  119.      */
  120.     static private function checkSchemaDiffWriter$obj$type )
  121.     {
  122.         if !( ( $obj->getDiffWriterType($type == $type ) )
  123.         {
  124.             throw new ezcDbSchemaInvalidWriterClassExceptionget_class$obj )$type );
  125.         }
  126.     }
  127.  
  128.     /**
  129.      * Writes the schema differences to the file $file in format $format.
  130.      *
  131.      * @throws ezcDbSchemaInvalidWriterClassException if the handler associated
  132.      *          with the $format is not a file schema writer.
  133.      *
  134.      * @param string $format 
  135.      * @param string $file 
  136.      */
  137.     public function writeToFile$format$file )
  138.     {
  139.         $className ezcDbSchemaHandlerManager::getDiffWriterByFormat$format );
  140.         $reader new $className();
  141.         self::checkSchemaDiffWriter$readerezcDbSchema::FILE );
  142.         $reader->saveDiffToFile$file$this );
  143.     }
  144.  
  145.     /**
  146.      * Upgrades the database $db with the differences.
  147.      *
  148.      * @throws ezcDbSchemaInvalidWriterClassException if the handler associated
  149.      *          with the $format is not a database schema writer.
  150.      *
  151.      * @param ezcDbHandler $db 
  152.      */
  153.     public function applyToDbezcDbHandler $db )
  154.     {
  155.         $className ezcDbSchemaHandlerManager::getDiffWriterByFormat$db->getName() );
  156.         $writer new $className();
  157.         self::checkSchemaDiffWriter$writerezcDbSchema::DATABASE );
  158.         $writer->applyDiffToDb$db$this );
  159.     }
  160.  
  161.     /**
  162.      * Returns the $db specific SQL queries that would update the database $db
  163.      *
  164.      * The database type can be given as both a database handler (instanceof
  165.      * ezcDbHandler) or the name of the database as string as retrieved through
  166.      * calling getName() on the database handler object.
  167.      *
  168.      * @see ezcDbHandler::getName()
  169.      *
  170.      * @throws ezcDbSchemaInvalidWriterClassException if the handler associated
  171.      *          with the $format is not a database schema writer.
  172.      *
  173.      * @param string|ezcDbHandler$db 
  174.      * @return array(string) 
  175.      */
  176.     public function convertToDDL$db )
  177.     {
  178.         if $db instanceof ezcDbHandler )
  179.         {
  180.             $db $db->getName();
  181.         }
  182.         $className ezcDbSchemaHandlerManager::getDiffWriterByFormat$db );
  183.         $writer new $className();
  184.         self::checkSchemaDiffWriter$writerezcDbSchema::DATABASE );
  185.         return $writer->convertDiffToDDL$this );
  186.     }
  187. }
  188. ?>
Documentation generated by phpDocumentor 1.4.3