[ Index ]
 

Code source de Symfony 1.0.0

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

title

Body

[fermer]

/lib/vendor/phing/tasks/ext/ -> CreoleTask.php (source)

   1  <?php
   2  
   3  /*
   4   *  $Id: CreoleTask.php 3076 2006-12-18 08:52:12Z fabien $
   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://phing.info>.
  21   */
  22  
  23  require_once 'phing/Task.php';
  24  include_once 'phing/types/Reference.php';
  25  
  26  /**
  27   * Handles Creole configuration needed by SQL type tasks.
  28   *
  29   * @author    Hans Lellelid <hans@xmpl.org> (Phing)
  30   * @author    Nick Chalko <nick@chalko.com> (Ant)
  31   * @author    Jeff Martin <jeff@custommonkey.org> (Ant)
  32   * @author    Michael McCallum <gholam@xtra.co.nz> (Ant)
  33   * @author    Tim Stephenson <tim.stephenson@sybase.com> (Ant)
  34   * @version   $Revision: 1.13 $
  35   * @package   phing.tasks.system
  36   */
  37  abstract class CreoleTask extends Task {
  38  
  39      /**
  40       * Used for caching loaders / driver. This is to avoid
  41       * getting an OutOfMemoryError when calling this task
  42       * multiple times in a row.
  43       * 
  44       * NOT IMPLEMENTED YET
  45       */
  46      private static $loaderMap = array();
  47  
  48      private $caching = true;
  49  
  50      /**
  51       * Autocommit flag. Default value is false
  52       */
  53      private $autocommit = false;
  54      
  55      /**
  56       * [optional] Classpath to Creole driver to use.
  57       * @param string
  58       */
  59      private $driver;
  60      
  61      /**
  62       * DB url.
  63       */
  64      private $url;
  65  
  66      /**
  67       * User name.
  68       */
  69      private $userId;
  70  
  71      /**
  72       * Password
  73       */
  74      private $password;
  75  
  76      /**
  77       * RDBMS Product needed for this SQL.
  78       **/
  79      private $rdbms;
  80     
  81        /**
  82       * Initialize CreoleTask.
  83       * This method includes any necessary Creole libraries and triggers
  84       * appropriate error if they cannot be found.  This is not done in header
  85       * because we may want this class to be loaded w/o triggering an error.
  86       */
  87      function init() {
  88          include_once 'creole/Creole.php';
  89          if (!class_exists('Creole')) {
  90              throw new Exception("Creole task depends on Creole classes being on include_path. (i.e. include of 'creole/Creole.php' failed.)");
  91          }
  92      }
  93  
  94      /**
  95       * Caching loaders / driver. This is to avoid
  96       * getting an OutOfMemoryError when calling this task
  97       * multiple times in a row; default: true
  98       * @param $enable
  99       */
 100      public function setCaching($enable) {
 101          $this->caching = $enable;
 102      }
 103  
 104      /**
 105       * Sets the database connection URL; required.
 106       * @param url The url to set
 107       */
 108      public function setUrl($url) {
 109          $this->url = $url;
 110      }
 111  
 112      /**
 113       * Set the Creole driver to be used.
 114       *
 115       * @param string $driver driver class name
 116       */
 117      public function setDriver($driver)
 118      {
 119          $this->driver = $driver;
 120      }
 121          
 122      /**
 123       * Sets the password; required.
 124       * @param password The password to set
 125       */
 126      public function setPassword($password) {
 127          $this->password = $password;
 128      }
 129  
 130      /**
 131       * Auto commit flag for database connection;
 132       * optional, default false.
 133       * @param autocommit The autocommit to set
 134       */
 135      public function setAutocommit($autocommit) {
 136          $this->autocommit = $autocommit;
 137      }
 138  
 139      /**
 140       * Sets the version string, execute task only if 
 141       * rdbms version match; optional.
 142       * @param version The version to set
 143       */
 144      public function setVersion($version) {
 145          $this->version = $version;
 146      }
 147         
 148      protected function getLoaderMap() {
 149          return self::$loaderMap;
 150      }
 151  
 152  
 153      /**
 154       * Creates a new Connection as using the driver, url, userid and password specified.
 155       * The calling method is responsible for closing the connection.
 156       * @return Connection the newly created connection.
 157       * @throws BuildException if the UserId/Password/Url is not set or there is no suitable driver or the driver fails to load.
 158       */
 159      protected function getConnection() {
 160              
 161          if ($this->url === null) {
 162              throw new BuildException("Url attribute must be set!", $this->location);
 163          }
 164                  
 165          try {
 166  
 167              $this->log("Connecting to " . $this->getUrl(), PROJECT_MSG_VERBOSE);
 168              $info = new Properties();
 169              
 170              $dsn = Creole::parseDSN($this->url);
 171              
 172              if (!isset($dsn["username"]) && $this->userId === null) {
 173                  throw new BuildException("Username must be in URL or userid attribute must be set.", $this->location);                
 174              }                        
 175              
 176              if ($this->userId) {
 177                  $dsn["username"] = $this->getUserId();
 178              }
 179              
 180              if ($this->password) {
 181                  $dsn["password"] = $this->getPassword();
 182              }
 183              
 184              if ($this->driver) {
 185                  Creole::registerDriver($dsn['phptype'], $this->driver);
 186              }
 187              
 188              $conn = Creole::getConnection($dsn);
 189              $conn->setAutoCommit($this->autocommit);
 190              return $conn;
 191              
 192          } catch (SQLException $e) {
 193              throw new BuildException($e->getMessage(), $this->location);
 194          }
 195  
 196      }
 197  
 198      public function isCaching($value) {
 199          $this->caching = $value;
 200      }
 201  
 202      /**
 203       * Gets the autocommit.
 204       * @return Returns a boolean
 205       */
 206      public function isAutocommit() {
 207          return $this->autocommit;
 208      }
 209  
 210      /**
 211       * Gets the url.
 212       * @return Returns a String
 213       */
 214      public function getUrl() {
 215          return $this->url;
 216      }
 217  
 218      /**
 219       * Gets the userId.
 220       * @return Returns a String
 221       */
 222      public function getUserId() {
 223          return $this->userId;
 224      }
 225  
 226      /**
 227       * Set the user name for the connection; required.
 228       * @param userId The userId to set
 229       */
 230      public function setUserid($userId) {
 231          $this->userId = $userId;
 232      }
 233  
 234      /**
 235       * Gets the password.
 236       * @return Returns a String
 237       */
 238      public function getPassword() {
 239          return $this->password;
 240      }
 241  
 242  }


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