123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243 |
- <?php
- require_once 'phing/Task.php';
- include_once 'phing/types/Reference.php';
- abstract class CreoleTask extends Task {
-
- private static $loaderMap = array();
- private $caching = true;
-
- private $autocommit = false;
-
-
- private $driver;
-
-
- private $url;
-
- private $userId;
-
- private $password;
-
- private $rdbms;
-
-
- function init() {
- include_once 'creole/Creole.php';
- if (!class_exists('Creole')) {
- throw new Exception("Creole task depends on Creole classes being on include_path. (i.e. include of 'creole/Creole.php' failed.)");
- }
- }
-
- public function setCaching($enable) {
- $this->caching = $enable;
- }
-
- public function setUrl($url) {
- $this->url = $url;
- }
-
- public function setDriver($driver)
- {
- $this->driver = $driver;
- }
-
-
- public function setPassword($password) {
- $this->password = $password;
- }
-
- public function setAutocommit($autocommit) {
- $this->autocommit = $autocommit;
- }
-
- public function setVersion($version) {
- $this->version = $version;
- }
-
- protected function getLoaderMap() {
- return self::$loaderMap;
- }
-
- protected function getConnection() {
-
- if ($this->url === null) {
- throw new BuildException("Url attribute must be set!", $this->location);
- }
-
- try {
- $this->log("Connecting to " . $this->getUrl(), Project::MSG_VERBOSE);
- $info = new Properties();
-
- $dsn = Creole::parseDSN($this->url);
-
- if (!isset($dsn["username"]) && $this->userId === null) {
- throw new BuildException("Username must be in URL or userid attribute must be set.", $this->location);
- }
-
- if ($this->userId) {
- $dsn["username"] = $this->getUserId();
- }
-
- if ($this->password) {
- $dsn["password"] = $this->getPassword();
- }
-
- if ($this->driver) {
- Creole::registerDriver($dsn['phptype'], $this->driver);
- }
-
- $conn = Creole::getConnection($dsn);
- $conn->setAutoCommit($this->autocommit);
- return $conn;
-
- } catch (SQLException $e) {
- throw new BuildException($e->getMessage(), $this->location);
- }
- }
- public function isCaching($value) {
- $this->caching = $value;
- }
-
- public function isAutocommit() {
- return $this->autocommit;
- }
-
- public function getUrl() {
- return $this->url;
- }
-
- public function getUserId() {
- return $this->userId;
- }
-
- public function setUserid($userId) {
- $this->userId = $userId;
- }
-
- public function getPassword() {
- return $this->password;
- }
- }
|