for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* @package CleverStyle Framework
* @author Nazar Mokrynskyi <[email protected]>
* @copyright Copyright (c) 2013-2016, Nazar Mokrynskyi
* @license MIT License, see license.txt
*/
namespace cs\DB;
use
cs\DB;
* Accessor trait
*
* Provides db() and db_prime() methods for simplified for with DB
trait Accessor {
* Link to db object
* @var false|_Abstract
private $_db = false;
* Link to primary db object
private $_db_prime = false;
* Returns link to the object of db for reading (can be mirror of main DB)
* @return _Abstract
function db () {
if (is_object($this->_db)) {
return $this->_db;
}
if (is_object($this->_db_prime)) {
return $this->_db = $this->_db_prime;
* Save reference for faster access
/** @noinspection ExceptionsAnnotatingAndHandlingInspection */
$this->_db = DB::instance()->db($this->cdb());
* Returns link to the object of db for writing (always main DB)
function db_prime () {
return $this->_db_prime;
$this->_db_prime = DB::instance()->db_prime($this->cdb());
* Returns database index
* @return int
abstract protected function cdb ();