first pab commit

This commit is contained in:
RainLoop Team 2013-11-27 22:57:38 +04:00
parent 790a867674
commit 6b5fb98a94
3 changed files with 142 additions and 0 deletions

View file

@ -0,0 +1,43 @@
<?php
namespace RainLoop\Providers;
class PersonalAddressBook extends \RainLoop\Providers\AbstractProvider
{
/**
* @var \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface
*/
private $oDriver;
/**
* @param \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface $oDriver
*
* @return void
*/
public function __construct($oDriver)
{
$this->oDriver = null;
if ($oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface)
{
$this->oDriver = $oDriver;
}
}
/**
* @return bool
*/
public function IsActive()
{
return $this->oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface &&
$this->oDriver->IsSupported();
}
/**
* @return bool
*/
public function IsSupported()
{
return $this->oDriver instanceof \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface &&
$this->oDriver->IsSupported();
}
}

View file

@ -0,0 +1,88 @@
<?php
namespace RainLoop\Providers\PersonalAddressBook;
class MySqlPersonalAddressBook implements \RainLoop\Providers\PersonalAddressBook\PersonalAddressBookInterface
{
/**
* @var \MailSo\Log\Logger
*/
private $oLogger;
/**
* @param \MailSo\Log\Logger $oLogger = null
*/
public function __construct($oLogger = null)
{
$this->oLogger = $oLogger instanceof \MailSo\Log\Logger ? $oLogger : null;
}
/**
* @return bool
*/
public function IsSupported()
{
$aDrivers = \class_exists('PDO') ? \PDO::getAvailableDrivers() : array();
return \is_array($aDrivers) ? \in_array('mysql', $aDrivers) : false;
}
/**
* @param \RainLoop\Account $oAccount
* @staticvar array $aPdoCache
* @return \PDO
*/
private function getPDO($oAccount)
{
static $aPdoCache = array();
$sEmail = $oAccount->ParentEmailHelper();
if (isset($aPdoCache[$sEmail]))
{
return $aPdoCache[$sEmail];
}
if (!\class_exists('PDO'))
{
throw new \Exception('class_exists=PDO');
}
$sVersionFile = '';
$sDsn = '';
$sDbLogin = '';
$sDbPassword = '';
$oPdo = false;
try
{
$oPdo = new \PDO($sDsn, $sDbLogin, $sDbPassword);
if ($oPdo)
{
$oPdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
if (!@\file_exists($sVersionFile) ||
(string) @file_get_contents($sVersionFile) !== (string) \RainLoop\Providers\Contacts\Classes\Db::Version())
{
$this->syncTables($oPdo, $sVersionFile);
}
$oPdo->sqliteCreateFunction('SIMPLESEARCH', function ($sEmailValue, $sNameValue, $sMask) {
return \preg_match('/'.\preg_quote($sMask, '/').'/ui',
$sEmailValue.' '.$sNameValue) ? 1 : 0;
});
}
}
catch (\Exception $oException)
{
throw $oException;
$oPdo = false;
}
if ($oPdo)
{
$aPdoCache[$oAccount->ParentEmailHelper()] = $oPdo;
}
return $oPdo;
}
}

View file

@ -0,0 +1,11 @@
<?php
namespace RainLoop\Providers\PersonalAddressBook;
interface PersonalAddressBookInterface
{
/**
* @return bool
*/
public function IsSupported();
}