-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Zend\Db transaction api unification #5001
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
<?php | ||
/** | ||
* Zend Framework (http://framework.zend.com/) | ||
* | ||
* @link http://github.com/zendframework/zf2 for the canonical source repository | ||
* @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com) | ||
* @license http://framework.zend.com/license/new-bsd New BSD License | ||
*/ | ||
|
||
namespace Zend\Db\Adapter\Driver; | ||
|
||
use Zend\Db\Adapter\Profiler; | ||
|
||
abstract class AbstractConnection implements ConnectionInterface, Profiler\ProfilerAwareInterface | ||
{ | ||
/** | ||
* @var array | ||
*/ | ||
protected $connectionParameters = array(); | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $driverName = null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I didn't find any use of this attribute. What is his purpose? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Maks3w $connectionParameters => used in connect() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am with @Maks3w, if you never intend to use that property, or that property has no context in the current abstract, then it should not be in here. |
||
|
||
/** | ||
* @var boolean | ||
*/ | ||
protected $inTransaction = false; | ||
|
||
/** | ||
* @var Profiler\ProfilerInterface | ||
*/ | ||
protected $profiler = null; | ||
|
||
/** | ||
* @var resource | ||
*/ | ||
protected $resource = null; | ||
|
||
/** | ||
* Disconnect | ||
* | ||
* @return self | ||
*/ | ||
public function disconnect() | ||
{ | ||
if ($this->isConnected()) { | ||
$this->resource = null; | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* Get connection parameters | ||
* | ||
* @return array | ||
*/ | ||
public function getConnectionParameters() | ||
{ | ||
return $this->connectionParameters; | ||
} | ||
|
||
/** | ||
* Get driver name | ||
* | ||
* @return null|string | ||
*/ | ||
public function getDriverName() | ||
{ | ||
return $this->driverName; | ||
} | ||
|
||
/** | ||
* @return null|Profiler\ProfilerInterface | ||
*/ | ||
public function getProfiler() | ||
{ | ||
return $this->profiler; | ||
} | ||
|
||
/** | ||
* Get resource | ||
* | ||
* @return resource | ||
*/ | ||
public function getResource() | ||
{ | ||
if (!$this->isConnected()) { | ||
$this->connect(); | ||
} | ||
|
||
return $this->resource; | ||
} | ||
|
||
/** | ||
* Checks whether the connection is in transaction state. | ||
* | ||
* @return boolean | ||
*/ | ||
public function inTransaction() | ||
{ | ||
return $this->inTransaction; | ||
} | ||
|
||
/** | ||
* @param array $connectionParameters | ||
* @return self | ||
*/ | ||
public function setConnectionParameters(array $connectionParameters) | ||
{ | ||
$this->connectionParameters = $connectionParameters; | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @param Profiler\ProfilerInterface $profiler | ||
* @return self | ||
*/ | ||
public function setProfiler(Profiler\ProfilerInterface $profiler) | ||
{ | ||
$this->profiler = $profiler; | ||
|
||
return $this; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm sure there will be developers that will disagree with me and who's frame of reference is to always use inheritance even for trivial things, but this abstraction seems unnecessary to me. The guts of this class do nothing algorithmically interesting and since that is the case, I see little need to introduce a base type that all driver connection classes inherit from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I told before, this abstract was a basis for another PR, so, I'm going to push it either in order to show you my final goal