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 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
<?php
namespace GeniBase\DBase;
use Gedcomx\Agent\Agent;
use Pimple\Container;
class DBaseService extends Container
{
protected $agent;
public function __construct(Container $app)
{
$this['app'] = $app;
}
public function getDb()
{
return $this['app']['db'];
}
public function getTableName($table)
{
$prefix = isset($this['app']['dbs.options']['default']['prefix'])
? $this['app']['dbs.options']['default']['prefix'] : '';
return $prefix.$table;
}
public function getLidForId($table, $id)
{
if (false !== $result = $this['app']['db']->fetchColumn("SELECT _id FROM $table WHERE id = ?", [$id])) {
return (int) $result;
}
return $result;
}
public function getIdForLid($table, $lid)
{
return $this['app']['db']->fetchColumn("SELECT id FROM $table WHERE _id = ?", [(int) $lid]);
}
public function getIdFromReference($uri)
{
if (empty($uri)) {
return null;
}
if (preg_match('/\#([\w\-]+)/', $uri, $matches)) {
return $matches[1];
}
return false;
}
public function setAgent(Agent $agent)
{
$this->agent = $agent;
}
public function getAgent()
{
return $this->agent;
}
}