[ Index ]
 

Code source de eZ Publish 3.9.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/ezdbschema/classes/ -> ezdbschema.php (source)

   1  <?php
   2  //
   3  // Created on: <28-Jan-2004 15:46:30 dr>
   4  //
   5  // SOFTWARE NAME: eZ publish
   6  // SOFTWARE RELEASE: 3.9.0
   7  // BUILD VERSION: 17785
   8  // COPYRIGHT NOTICE: Copyright (C) 1999-2006 eZ systems AS
   9  // SOFTWARE LICENSE: GNU General Public License v2.0
  10  // NOTICE: >
  11  //   This program is free software; you can redistribute it and/or
  12  //   modify it under the terms of version 2.0  of the GNU General
  13  //   Public License as published by the Free Software Foundation.
  14  //
  15  //   This program is distributed in the hope that it will be useful,
  16  //   but WITHOUT ANY WARRANTY; without even the implied warranty of
  17  //   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18  //   GNU General Public License for more details.
  19  //
  20  //   You should have received a copy of version 2.0 of the GNU General
  21  //   Public License along with this program; if not, write to the Free
  22  //   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  23  //   MA 02110-1301, USA.
  24  //
  25  //
  26  
  27  /*!
  28    \class eZDBSchema ezdbschema.php
  29    \ingroup eZDBSchema
  30    \brief A factory for schema handlers
  31  
  32  */
  33  
  34  class eZDbSchema
  35  {
  36      /*!
  37       \static
  38       Create new instance of eZDBSchemaInterface. placed here for simplicity.
  39  
  40       \param eZDB instance (optional), if none provided, eZDB::instance() will be used.
  41       \return new Instance of eZDBSchema, false if failed
  42      */
  43      function instance( $params = false )
  44      {
  45          if ( is_object( $params ) )
  46          {
  47              $db =& $params;
  48              unset( $params );
  49              $params = array( 'instance' => &$db );
  50          }
  51  
  52          if ( !isset( $params['instance'] ) )
  53          {
  54              include_once ( 'lib/ezdb/classes/ezdb.php' );
  55              $db = eZDB::instance();
  56              $params['instance'] = &$db;
  57          }
  58  
  59          unset( $db );
  60          $db =& $params['instance'];
  61  
  62          if ( !isset( $params['type'] ) )
  63              $params['type'] = $db->databaseName();
  64          if ( !isset( $params['schema'] ) )
  65              $params['schema'] = false;
  66  
  67          $dbname = $params['type'];
  68  
  69          /* Load the database schema handler INI stuff */
  70          require_once ( 'lib/ezutils/classes/ezini.php' );
  71          $ini =& eZINI::instance( 'dbschema.ini' );
  72          $schemaPaths = $ini->variable( 'SchemaSettings', 'SchemaPaths' );
  73          $schemaHandlerClasses = $ini->variable( 'SchemaSettings', 'SchemaHandlerClasses' );
  74  
  75          /* Check if we have a handler */
  76          if ( !isset( $schemaPaths[$dbname] ) or !isset( $schemaHandlerClasses[$dbname] ) )
  77          {
  78              eZDebug::writeError( "No schema handler for database type: $dbname", 'eZDBSchema::instance()' );
  79              return false;
  80          }
  81  
  82          /* Include the schema file and instantiate it */
  83          require_once( $schemaPaths[$dbname] );
  84          return new $schemaHandlerClasses[$dbname]( $params );
  85      }
  86  
  87      /*!
  88       \static
  89      */
  90  	function read( $filename, $returnArray = false )
  91      {
  92          $fd = @fopen( $filename, 'rb' );
  93          if ( $fd )
  94          {
  95              $buf = fread( $fd, 100 );
  96              fclose( $fd );
  97              if ( preg_match( '#^<\?' . "php#", $buf ) )
  98              {
  99                  include( $filename );
 100                  if ( $returnArray )
 101                  {
 102                      $params = array();
 103                      if ( isset( $schema ) )
 104                          $params['schema'] = $schema;
 105                      if ( isset( $data ) )
 106                          $params['data'] = $data;
 107                      return $params;
 108                  }
 109                  else
 110                  {
 111                      return $schema;
 112                  }
 113              }
 114              else if ( preg_match( '#a:[0-9]+:{#', $buf ) )
 115              {
 116                  include_once ( 'lib/ezfile/classes/ezfile.php' );
 117                  return unserialize( eZFile::getContents( $filename ) );
 118              }
 119              else
 120              {
 121                  eZDebug::writeError( "Unknown format for file $filename" );
 122                  return false;
 123              }
 124          }
 125      }
 126  
 127      /*!
 128       \static
 129      */
 130  	function readArray( $filename )
 131      {
 132          $schema = false;
 133          include( $filename );
 134          return $schema;
 135      }
 136  
 137      /*!
 138       \static
 139      */
 140  	function generateUpgradeFile( $differences )
 141      {
 142          $diff = var_export( $differences, true );
 143          return ( "<?php \n\$diff = \n" . $diff . ";\nreturn \$diff;\n?>\n" );
 144      }
 145  
 146      /*!
 147       \static
 148      */
 149  	function writeUpgradeFile( $differences, $filename )
 150      {
 151          $fp = @fopen( $filename, 'w' );
 152          if ( $fp )
 153          {
 154              fputs( $fp, eZDbSchema::generateUpgradeFile( $differences ) );
 155              fclose( $fp );
 156              return true;
 157          }
 158          else
 159          {
 160              return false;
 161          }
 162      }
 163  }
 164  ?>


Généré le : Sat Feb 24 10:30:04 2007 par Balluche grâce à PHPXref 0.7