[ Index ]
 

Code source de Symfony 1.0.0

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

title

Body

[fermer]

/lib/vendor/propel-generator/classes/propel/engine/database/model/ -> AppData.php (source)

   1  <?php
   2  /*
   3   *  $Id: AppData.php 258 2005-11-07 16:12:09Z hans $
   4   *
   5   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
   6   * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
   7   * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
   8   * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
   9   * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  10   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  11   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  12   * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  13   * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  14   * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  15   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  16   *
  17   * This software consists of voluntary contributions made by many individuals
  18   * and is licensed under the LGPL. For more information please see
  19   * <http://propel.phpdb.org>.
  20   */
  21  
  22  include_once 'propel/engine/EngineException.php';
  23  include_once 'propel/engine/database/model/Database.php';
  24  
  25  /**
  26   * A class for holding application data structures.
  27   *
  28   * @author Hans Lellelid <hans@xmpl.org> (Propel)
  29   * @author Leon Messerschmidt <leon@opticode.co.za> (Torque)
  30   * @author John McNally <jmcnally@collab.net> (Torque)
  31   * @author Daniel Rall <dlr@finemaltcoding.com> (Torque)
  32   * @version $Revision: 258 $
  33   * @package propel.engine.database.model
  34   */
  35  class AppData {
  36  
  37      /**
  38       * The list of databases for this application.
  39       * @var array Database[]
  40       */
  41      private $dbList = array();
  42  
  43      /**
  44       * The platform class for our database(s).
  45       * @var string
  46       */
  47      private $platform;
  48  
  49      /**
  50       * Name of the database. Only one database definition
  51       * is allowed in one XML descriptor.
  52       */
  53      private $name;
  54  
  55      /**
  56       * Flag to ensure that initialization is performed only once.
  57       * @var boolean
  58       */
  59      private $isInitialized = false;
  60  
  61      /**
  62       * Creates a new instance for the specified database type.
  63       *
  64       * @param Platform $platform The platform class to use for any databases added to this application model.
  65       */
  66      public function __construct(Platform $platform)
  67      {
  68          $this->platform = $platform;
  69      }
  70  
  71      /**
  72       * Set the name of the database.
  73       *
  74       * @param name of the database.
  75       */
  76      public function setName($name)
  77      {
  78          $this->name = $name;
  79      }
  80  
  81      /**
  82       * Get the name of the database.
  83       *
  84       * @return String name
  85       */
  86      public function getName()
  87      {
  88          return $this->name;
  89      }
  90  
  91      /**
  92       * Get the short name of the database (without the '-schema' postfix).
  93       *
  94       * @return String name
  95       */
  96      public function getShortName()
  97      {
  98          return str_replace("-schema", "", $this->name);
  99      }
 100  
 101      /**
 102       * Return an array of all databases
 103       *
 104       * @return Array of Database objects
 105       */
 106      public function getDatabases($doFinalInit = true)
 107      {
 108          // this is temporary until we'll have a clean solution
 109          // for packaging datamodels/requiring schemas
 110          if ($doFinalInit) {
 111              $this->doFinalInitialization();
 112          }
 113          return $this->dbList;
 114      }
 115  
 116      /**
 117       * Returns whether this application has multiple databases.
 118       *
 119       * @return boolean True if the application has multiple databases
 120       */
 121      public function hasMultipleDatabases()
 122      {
 123          return (count($this->dbList) > 1);
 124      }
 125  
 126      /**
 127       * Return the database with the specified name.
 128       *
 129       * @param name database name
 130       * @return A Database object.  If it does not exist it returns null
 131       */
 132      public function getDatabase($name = null, $doFinalInit = true)
 133      {
 134          // this is temporary until we'll have a clean solution
 135          // for packaging datamodels/requiring schemas
 136          if ($doFinalInit) {
 137              $this->doFinalInitialization();
 138          }
 139  
 140          if ($name === null) {
 141              return $this->dbList[0];
 142          }
 143  
 144          for($i=0,$size=count($this->dbList); $i < $size; $i++) {
 145              $db = $this->dbList[$i];
 146              if ($db->getName() === $name) {
 147                  return $db;
 148              }
 149          }
 150          return null;
 151      }
 152  
 153      /**
 154       * Add a database to the list and sets the AppData property to this
 155       * AppData
 156       *
 157       * @param db the database to add
 158       */
 159      public function addDatabase($db)
 160      {
 161          if ($db instanceof Database) {
 162              $db->setAppData($this);
 163              if ($db->getPlatform() === null) {
 164                  $db->setPlatform($this->platform);
 165              }
 166              $this->dbList[] = $db;
 167              return $db;
 168          } else {
 169              // XML attributes array / hash
 170              $d = new Database();
 171              $d->loadFromXML($db);
 172              return $this->addDatabase($d); // calls self w/ different param type
 173          }
 174  
 175      }
 176  
 177      /**
 178       *
 179       * @return void
 180       */
 181      private function doFinalInitialization()
 182      {
 183          if (!$this->isInitialized) {
 184              for($i=0, $size=count($this->dbList); $i < $size; $i++) {
 185                  $this->dbList[$i]->doFinalInitialization();
 186              }
 187              $this->isInitialized = true;
 188          }
 189      }
 190  
 191      /**
 192       * Creats a string representation of this AppData.
 193       * The representation is given in xml format.
 194       *
 195       * @return string Representation in xml format
 196       */
 197      public function toString()
 198      {
 199          $result = "<app-data>\n";
 200          for ($i=0,$size=count($this->dbList); $i < $size; $i++) {
 201              $result .= $this->dbList[$i]->toString();
 202          }
 203          $result .= "</app-data>";
 204          return $result;
 205      }
 206  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7