-
Notifications
You must be signed in to change notification settings - Fork 0
/
DataSourceFactory.php
73 lines (55 loc) · 2.04 KB
/
DataSourceFactory.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
<?php
/******************************************************************************
Copyright (c) 2008 by Alexei V. Vasilyev. All Rights Reserved.
-----------------------------------------------------------------------------
Module : Data Source Factory
File : DataSourceFactory.php
Author : Alexei V. Vasilyev
-----------------------------------------------------------------------------
Description:
******************************************************************************/
require_once( dirname( __FILE__ ) ."/Clonable.php" );
/**
\brief Data source factory, controls your data sources
This class provides \b Factory for creating DataSource object.
and you can have creation object instance in \b uiPage constructor
bacause object does not have big internal state linked with database.
Factory provides common service for seting current used database engine.
via "one point change" approach.
\relates DataSource
*/
class DataSourceFactory
{
/** contains DSN to current used database
*/
var $_dsn="";
/**
* constains prototype for creating \b DS objects
* @var IDataSource|null
*/
var $_proto=null;
/** construct factory
@param string $dsn \b string describes Data Source Name as next string:
engine_name://username:password@server[:port]/database
@param mixed $proto \b class instance which have support next interfaces:
\li Clonable
\li DataSource
*/
function DataSourceFactory( $dsn, IDataSource $proto )
{
if ( !is_subclass_of( $proto, CLASS_Clonable ) ) {
throw new DatabaseException( "object " . get_class( $proto ) . " is not subclass of ". CLASS_Clonable );
}
$this->_dsn = $dsn;
$this->_proto = $proto;
}
/** get connection for current used DSN and Data source object
@return new created \b object wich was created from recevied in constructor prototype
*/
function getConnection()
{
$ds = $this->_proto->cloneObject();
$ds->connect( $this->_dsn );
return( $ds );
}
}