/** * Get the database configuration adapter. * * @return ConfigAdapterInterface */ public static function getAdapter() { if (null === static::$adapter) { static::$adapter = new Ini(); } return static::$adapter; }
/** * Create and return instance of Select Statement for entity. If entity * has defined select, the return object will be this instance. * * @return Juborm\Select Statement of select */ public static function select($columns = null) { if (is_string($columns)) { // zostala podana tylko jedna kolumna wiec zamieniam na arraya $columns = array($columns); } // wczytuje klase select $select = is_null(static::$select) ? ORMSelect::class : static::$select; $cleanEntity = new static(); $select = $cleanEntity->adapter()->dml(MidataDML::SELECT); $select->from(static::$table)->entity(static::class)->model($cleanEntity->model())->source($cleanEntity->source()); if (is_null($columns)) { $columns = static::fields(); } // columns of primary key are added to each entity $pks = static::pkDefinition(); foreach ($pks as $pk) { if (!in_array($pk, $columns)) { $columns[] = $pk; } } foreach ($columns as $alias => $value) { if (is_int($alias)) { $select->column($value); } else { $select->column($value, $alias); } } // the last step is prepare the select to use $select->prepare(); // endtodo return $select; }
/** * @param \Phramework\Database\IAdapter $adapter * @throws \Exception */ public static function setAdapter(\Phramework\Database\IAdapter $adapter) { if (!$adapter instanceof \Phramework\Database\IAdapter) { throw new \Exception('Class is not implementing \\Phramework\\Database\\IAdapter'); } static::$adapter = $adapter; }
/** * Required * connects to the data base and stores the connection * @param $db_settings_name Array */ public static function establish_connection($db_settings_name) { $file = strtolower($db_settings_name['adapter']) . '_adapter'; $class = "\\ActivePhp\\" . \Inflector::classify($file); $klass = new $class($db_settings_name); static::$adapter = $klass; }
/** * Initialize router */ static function setupBeforeClass() { parent::setupBeforeClass(); if (testAdapter == 'HTTP') { // echo("Test using HTTP adapter\n"); static::$adapter = new GuzzleAdapter(new Client()); } else { if (null == self::$app) { // echo("Test using built-in Router\n"); self::$app = new Router(); } } }
/** * Initializes the cache. * * With the $options array it's possible to define: * - expiration of the key, (time in seconds) * - a namespace for the key * * this last one is useful in the case two applications use * a shared key/store (for instance a shared Memcached db) * * Ex: * $cfg_ar = ActiveRecord\Config::instance(); * $cfg_ar->set_cache('memcache://localhost:11211',array('namespace' => 'my_cool_app', * 'expire' => 120 * )); * * In the example above all the keys expire after 120 seconds, and the * all get a postfix 'my_cool_app'. * * (Note: expiring needs to be implemented in your cache store.) * * @param string $url URL to your cache server * @param array $options Specify additional options */ public static function initialize($url, $options = array()) { if ($url) { $url = parse_url($url); $file = ucwords(Inflector::instance()->camelize($url['scheme'])); $class = "ActiveRecord\\{$file}"; require_once __DIR__ . "/cache/{$file}.php"; static::$adapter = new $class($url); } else { static::$adapter = null; } static::$options = array_merge(array('expire' => 30, 'namespace' => ''), $options); }
/** * Initialization */ public function init() { parent::init(); if (empty($this->config['db'])) { $message = 'Incorrect param `db`!'; \Yii::error(PHP_EOL . $message, __METHOD__ . '(' . __LINE__ . ')'); throw new InvalidParamException($message); } $params = ['class' => __NAMESPACE__ . '\\db\\Connection', 'params' => $this->config['db']]; static::$adapter = \Yii::createObject($params); if (isset($this->config['max-count']) && (int) $this->config['max-count']) { $this->maxPostCount = (int) $this->config['max-count']; } }
public static function register(Di $di) { static::$di = $di; $di->remove('counter'); static::$adapter = null; $di->setShared('counter', function () { $default = Config::get('counter.default'); $config = Config::get('counter.drivers.' . $default); $class = $config['adapter']; $options = $config['options']; strpos($class, '\\') === false and $class = 'Phwoolcon\\Util\\Counter\\' . $class; return new $class($options); }); }
/** * Create Session Adapter instance using Factory pattern * * @param string $adapterName * @param string $name * @return SessionAdapterInterface * @throws Exception */ public static function create($adapterName, $name = '') { if (!in_array($adapterName, static::$allowedAdapters)) { throw new Exception(null, $adapterName . ' is not allowed as Session adapter'); } $adapterName = ucfirst($adapterName); switch ($adapterName) { case static::SESSION: static::$adapter = new Session($name); break; default: throw new Exception(null, $adapterName . ' is not implemented as Session adapter'); break; } return static::$adapter; }
public static function load_adapter($db_settings) { if ($db_settings["dbtype"] == "none") { return true; } $adapter = "Wax" . ucfirst($db_settings["dbtype"]) . "Adapter"; static::$adapter = $adapter; static::$db_settings = $db_settings; }
public static function setAdapter(adapter $adapter) { static::$adapter = $adapter; }
public static function setAdapter(atoum\test\adapter $adapter = null) { static::$adapter = $adapter ?: new atoum\php\mocker\adapter(); }
public static function changeCacheAdapter($adapter) { static::$adapter = $adapter; }
/** * Configures the facade, want to have a new Writer? A new Object Database or a new * Adapter and you want it on-the-fly? Use this method to hot-swap your facade with a new * toolbox. * * @param RedBean_ToolBox $tb toolbox * * @return RedBean_ToolBox $tb old, rusty, previously used toolbox */ public static function configureFacadeWithToolbox(RedBean_ToolBox $tb) { $oldTools = static::$toolbox; static::$toolbox = $tb; static::$writer = static::$toolbox->getWriter(); static::$adapter = static::$toolbox->getDatabaseAdapter(); static::$redbean = static::$toolbox->getRedBean(); static::$associationManager = new RedBean_AssociationManager(static::$toolbox); static::$redbean->setAssociationManager(static::$associationManager); static::$extAssocManager = new RedBean_ExtAssociationManager(static::$toolbox); $helper = new RedBean_ModelHelper(); static::$redbean->addEventListener('update', $helper); static::$redbean->addEventListener('open', $helper); static::$redbean->addEventListener('delete', $helper); static::$associationManager->addEventListener('delete', $helper); static::$redbean->addEventListener('after_delete', $helper); static::$redbean->addEventListener('after_update', $helper); static::$redbean->addEventListener('dispense', $helper); static::$tagManager = new RedBean_TagManager(static::$toolbox); static::$f = new RedBean_SQLHelper(static::$adapter); return $oldTools; }
/** * Required * connects to the database and stores the connection * @param array $db_settings */ public static function establish_connection(array $db_settings) { static::$database = $db_settings['database']; $file = strtolower($db_settings['adapter']) . '_adapter'; $filename = $file . '.php'; /** * lazy loading of the adapter */ $_adapters = self::get_available_adapters(); if (isset($_adapters[$filename])) { require_once __DIR__ . '/../adapters/' . $filename; } $class = Inflector::classify($file); $klass = new $class($db_settings); static::load_interfaces(); static::$adapter = $klass; }
public static function setAdapter(&$a) { static::$adapter = $a; }