diff --git a/Alpha/Controller/ArticleController.php b/Alpha/Controller/ArticleController.php index e4e7e6a3..d36df63f 100644 --- a/Alpha/Controller/ArticleController.php +++ b/Alpha/Controller/ArticleController.php @@ -9,7 +9,7 @@ use Alpha\Util\Extension\TCPDFFacade; use Alpha\Util\Http\Request; use Alpha\Util\Http\Response; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Util\File\FileUtils; use Alpha\Model\Article; use Alpha\Model\ArticleComment; @@ -558,7 +558,7 @@ public function before_displayPageFoot_callback() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $html = ''; $params = $this->request->getParams(); @@ -635,7 +635,7 @@ private function renderComments() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $html = ''; @@ -707,7 +707,7 @@ private function renderVotes() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $URL = FrontController::generateSecureURL('act=Alpha\Controller\ActiveRecordController&ActiveRecordType=Alpha\Model\ArticleVote'); $html = '
'; diff --git a/Alpha/Controller/CacheController.php b/Alpha/Controller/CacheController.php index 32a68475..2830c034 100644 --- a/Alpha/Controller/CacheController.php +++ b/Alpha/Controller/CacheController.php @@ -7,7 +7,7 @@ use Alpha\Util\File\FileUtils; use Alpha\Util\Security\SecurityUtils; use Alpha\Util\Http\Response; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Exception\IllegalArguementException; use Alpha\Exception\SecurityException; use Alpha\Exception\AlphaException; @@ -213,7 +213,7 @@ public function doPOST($request) $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); self::$logger->info('Cache contents deleted successfully by user ['.$session->get('currentUser')->get('username').'].'); } catch (AlphaException $e) { diff --git a/Alpha/Controller/Controller.php b/Alpha/Controller/Controller.php index c956d995..14ab2b02 100644 --- a/Alpha/Controller/Controller.php +++ b/Alpha/Controller/Controller.php @@ -8,7 +8,7 @@ use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Security\SecurityUtils; use Alpha\Util\Helper\Validator; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Util\Http\Request; use Alpha\Util\Http\Response; use Alpha\Util\Logging\Logger; @@ -273,7 +273,7 @@ public function __construct($visibility = 'Public') } $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); if ($session->get('unitOfWork') !== false && is_array($session->get('unitOfWork'))) { $this->setUnitOfWork($session->get('unitOfWork')); @@ -490,7 +490,7 @@ public function setUnitOfWork($jobs) // clear out any previous unit of work from the session $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $session->delete('unitOfWork'); $this->firstJob = null; $this->previousJob = null; @@ -577,7 +577,7 @@ public function setUnitStartTime($year, $month, $day, $hour, $minute, $second) $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $this->unitStartTime->setTimestampValue($year, $month, $day, $hour, $minute, $second); $session->set('unitStartTime', $this->unitStartTime->getValue()); @@ -619,7 +619,7 @@ public function setUnitEndTime($year, $month, $day, $hour, $minute, $second) $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $this->unitEndTime->setTimestampValue($year, $month, $day, $hour, $minute, $second); $session->set('unitEndTime', $this->unitEndTime->getValue()); @@ -709,7 +709,7 @@ public function markDirty($object) $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $session->set('dirtyObjects', $this->dirtyObjects); @@ -754,7 +754,7 @@ public function markNew($object) $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $session->set('newObjects', $this->newObjects); @@ -893,7 +893,7 @@ public function clearUnitOfWorkAttributes() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $session->delete('unitOfWork'); $this->unitOfWork = null; @@ -1008,7 +1008,7 @@ public function accessError() $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); if ($session->get('currentUser') !== false) { self::$logger->warn('The user ['.$session->get('currentUser')->get('email').'] attempted to access the resource ['.$this->request->getURI().'] but was denied due to insufficient rights'); @@ -1044,7 +1044,7 @@ public function checkRights() $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); if (method_exists($this, 'before_checkRights_callback')) { $this->{'before_checkRights_callback'}(); @@ -1256,7 +1256,7 @@ public function setStatusMessage($message) { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $this->statusMessage = $message; $session->set('statusMessage', $message); @@ -1275,7 +1275,7 @@ public function getStatusMessage() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $session->delete('statusMessage'); @@ -1682,7 +1682,7 @@ public function after_displayPageHead_callback() $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); if ($session->get('currentUser') !== false) { $passwordResetRequired = SecurityUtils::checkAdminPasswordIsDefault($session->get('currentUser')->get('password')); diff --git a/Alpha/Controller/InstallController.php b/Alpha/Controller/InstallController.php index 63cc8853..19ae1f75 100644 --- a/Alpha/Controller/InstallController.php +++ b/Alpha/Controller/InstallController.php @@ -5,7 +5,7 @@ use Alpha\Util\Logging\Logger; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Http\Response; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Model\ActiveRecord; use Alpha\Model\Rights; use Alpha\Model\Person; @@ -105,7 +105,7 @@ public function doGET($request) $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); // if there is nobody logged in, we will send them off to the Login controller to do so before coming back here if ($session->get('currentUser') === false) { @@ -122,7 +122,7 @@ public function doGET($request) } $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $body = View::displayPageHead($this); @@ -462,7 +462,7 @@ public function checkRights() $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); if ($this->getVisibility() == 'Public') { self::$logger->debug('<set('ID', '00000000001'); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $session->set('currentUser', $admin); $response = new Response(301); @@ -308,7 +308,7 @@ protected function doLoginAndRedirect($password) if (!$this->personObject->isTransient() && $this->personObject->get('state') == 'Active') { if (password_verify($password, $this->personObject->get('password'))) { $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $session->set('currentUser', $this->personObject); self::$logger->debug('Logging in ['.$this->personObject->get('email').'] at ['.date('Y-m-d H:i:s').']'); diff --git a/Alpha/Controller/LogoutController.php b/Alpha/Controller/LogoutController.php index b0f79834..b48f8ea1 100644 --- a/Alpha/Controller/LogoutController.php +++ b/Alpha/Controller/LogoutController.php @@ -4,7 +4,7 @@ use Alpha\Util\Logging\Logger; use Alpha\Util\Config\ConfigProvider; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Util\Http\Response; use Alpha\Model\Person; use Alpha\View\View; @@ -77,7 +77,7 @@ public function __construct() $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); if ($session->get('currentUser') !== false) { $this->setRecord($session->get('currentUser')); @@ -114,7 +114,7 @@ public function doGET($request) } $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $session->destroy(); $body = View::displayPageHead($this); diff --git a/Alpha/Controller/SearchController.php b/Alpha/Controller/SearchController.php index 545c3e95..41059f04 100644 --- a/Alpha/Controller/SearchController.php +++ b/Alpha/Controller/SearchController.php @@ -8,7 +8,7 @@ use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Http\Request; use Alpha\Util\Http\Response; -use Alpha\Util\Search\SearchProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\View\View; use Alpha\View\Widget\Button; use Alpha\Controller\Front\FrontController; @@ -152,7 +152,7 @@ public function doGET($request) $KPI->logStep('log search query'); - $provider = SearchProviderFactory::getInstance('Alpha\Util\Search\SearchProviderTags'); + $provider = ServiceFactory::getInstance('Alpha\Util\Search\SearchProviderTags', 'Alpha\Util\Search\SearchProviderInterface'); // if a Record name is provided, only search tags on that class, otherwise search all records if (isset($params['ActiveRecordType'])) { diff --git a/Alpha/Model/ActiveRecord.php b/Alpha/Model/ActiveRecord.php index a09812c6..0ca5c35e 100644 --- a/Alpha/Model/ActiveRecord.php +++ b/Alpha/Model/ActiveRecord.php @@ -9,8 +9,7 @@ use Alpha\Model\Type\Relation; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Logging\Logger; -use Alpha\Util\Cache\CacheProviderFactory; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Exception\AlphaException; use Alpha\Exception\FailedSaveException; use Alpha\Exception\FailedDeleteException; @@ -194,7 +193,7 @@ public function __construct() $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); set_exception_handler('Alpha\Util\ErrorHandlers::catchException'); set_error_handler('Alpha\Util\ErrorHandlers::catchError', $config->get('php.error.log.level')); @@ -218,7 +217,7 @@ public static function disconnect() { $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name')); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); $provider->disconnect(); } @@ -239,7 +238,8 @@ public function query($sqlQuery) $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $result = $provider->query($sqlQuery); self::$logger->debug('<get('cache.provider.name') != '' && $this->loadFromCache()) { // Record was found in cache } else { - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $provider->load($ID, $version); if ($config->get('cache.provider.name') != '') { @@ -306,7 +307,8 @@ public function loadAllOldVersions($ID) $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $objects = $provider->loadAllOldVersions($ID); self::$logger->debug('<get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $provider->loadByAttribute($attribute, $value, $ignoreClassType, $loadAttributes); $this->setEnumOptions(); @@ -378,7 +381,8 @@ public function loadAll($start = 0, $limit = 0, $orderBy = 'ID', $order = 'ASC', $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $objects = $provider->loadAll($start, $limit, $orderBy, $order, $ignoreClassType); if (method_exists($this, 'after_loadAll_callback')) { @@ -419,7 +423,8 @@ public function loadAllByAttribute($attribute, $value, $start = 0, $limit = 0, $ $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $objects = $provider->loadAllByAttribute($attribute, $value, $start, $limit, $orderBy, $order, $ignoreClassType); if (method_exists($this, 'after_loadAllByAttribute_callback')) { @@ -465,7 +470,8 @@ public function loadAllByAttributes($attributes = array(), $values = array(), $s '] provided to loadAllByAttributes'); } - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $objects = $provider->loadAllByAttributes($attributes, $values, $start, $limit, $orderBy, $order, $ignoreClassType); if (method_exists($this, 'after_loadAllByAttributes_callback')) { @@ -503,7 +509,8 @@ public function loadAllByDayUpdated($date, $start = 0, $limit = 0, $orderBy = 'I $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $objects = $provider->loadAllByDayUpdated($date, $start, $limit, $orderBy, $order, $ignoreClassType); if (method_exists($this, 'after_loadAllByDayUpdated_callback')) { @@ -537,7 +544,8 @@ public function loadAllFieldValuesByAttribute($attribute, $value, $returnAttribu $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $values = $provider->loadAllFieldValuesByAttribute($attribute, $value, $returnAttribute, $order, $ignoreClassType); self::$logger->debug('<validate(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $provider->save(); if ($config->get('cache.provider.name') != '') { @@ -610,7 +619,8 @@ public function saveAttribute($attribute, $value) throw new FailedSaveException('Cannot perform saveAttribute method on transient record!'); } - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $provider->saveAttribute($attribute, $value); if ($config->get('cache.provider.name') != '') { @@ -642,7 +652,8 @@ public function saveHistory() $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $provider->saveHistory(); if (method_exists($this, 'after_saveHistory_callback')) { @@ -769,7 +780,8 @@ public function delete() } } - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $provider->delete(); if ($config->get('cache.provider.name') != '') { @@ -850,7 +862,8 @@ public function getVersion() $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $ver = $provider->getVersion(); if (method_exists($this, 'after_getVersion_callback')) { @@ -879,7 +892,8 @@ public function makeTable() $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $provider->makeTable(); if (method_exists($this, 'after_makeTable_callback')) { @@ -908,7 +922,8 @@ public function makeHistoryTable() $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $provider->makeHistoryTable(); if (method_exists($this, 'after_makeHistoryTable_callback')) { @@ -937,7 +952,8 @@ public function rebuildTable() $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $provider->rebuildTable(); if (method_exists($this, 'after_rebuildTable_callback')) { @@ -966,7 +982,8 @@ public function dropTable($tableName = null) $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $provider->dropTable($tableName); if (method_exists($this, 'after_dropTable_callback')) { @@ -996,7 +1013,8 @@ public function addProperty($propName) $this->{'before_addProperty_callback'}(); } - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $provider->addProperty($propName); if (method_exists($this, 'after_addProperty_callback')) { @@ -1069,7 +1087,8 @@ public function getMAX() $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $max = $provider->getMAX(); if (method_exists($this, 'after_getMAX_callback')) { @@ -1108,7 +1127,8 @@ public function getCount($attributes = array(), $values = array()) throw new IllegalArguementException('Illegal arrays attributes=['.var_export($attributes, true).'] and values=['.var_export($values, true).'] provided to loadAllByAttributes'); } - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $count = $provider->getCount($attributes, $values); if (method_exists($this, 'after_getCount_callback')) { @@ -1140,7 +1160,8 @@ public function getHistoryCount() $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $count = $provider->getHistoryCount(); if (method_exists($this, 'after_getHistoryCount_callback')) { @@ -1203,7 +1224,8 @@ protected function setEnumOptions() $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); try { $provider->setEnumOptions(); } catch (NotImplementedException $e) { @@ -1414,7 +1436,8 @@ public function checkTableExists($checkHistoryTable = false) $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $tableExists = $provider->checkTableExists($checkHistoryTable); if (method_exists($this, 'after_checkTableExists_callback')) { @@ -1428,9 +1451,9 @@ public function checkTableExists($checkHistoryTable = false) /** * Static method to check the database and see if the table for the indicated Record class name - * exists (assumes table name will be $RecordClassName less "Object"). + * exists (assumes table name will be $recordClassName less "Object"). * - * @param string $RecordClassName The name of the business object class we are checking. + * @param string $recordClassName The name of the business object class we are checking. * @param bool $checkHistoryTable Set to true if you want to check for the existance of the _history table for this DAO. * * @return bool @@ -1439,18 +1462,18 @@ public function checkTableExists($checkHistoryTable = false) * * @throws \Alpha\Exception\AlphaException */ - public static function checkRecordTableExists($RecordClassName, $checkHistoryTable = false) + public static function checkRecordTableExists($recordClassName, $checkHistoryTable = false) { if (self::$logger == null) { self::$logger = new Logger('ActiveRecord'); } - self::$logger->debug('>>checkRecordTableExists(RecordClassName=['.$RecordClassName.'])'); + self::$logger->debug('>>checkRecordTableExists(RecordClassName=['.$recordClassName.'])'); $config = ConfigProvider::getInstance(); $provider = $config->get('db.provider.name'); - $tableExists = $provider::checkRecordTableExists($RecordClassName, $checkHistoryTable); + $tableExists = $provider::checkRecordTableExists($recordClassName, $checkHistoryTable); self::$logger->debug('<get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $updateRequired = $provider->checkTableNeedsUpdate(); if (method_exists($this, 'after_checkTableNeedsUpdate_callback')) { @@ -1517,7 +1541,8 @@ public function findMissingFields() $this->{'before_findMissingFields_callback'}(); } - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $missingFields = $provider->findMissingFields(); if (method_exists($this, 'after_findMissingFields_callback')) { @@ -1703,7 +1728,8 @@ public function getIndexes() $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $indexNames = $provider->getIndexes(); self::$logger->debug('<get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $provider->createForeignIndex($attributeName, $relatedClass, $relatedClassAttribute, $indexName); if (method_exists($this, 'after_createForeignIndex_callback')) { @@ -1774,7 +1801,8 @@ public function createUniqueIndex($attribute1Name, $attribute2Name = '', $attrib $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $provider->createUniqueIndex($attribute1Name, $attribute2Name, $attribute3Name); if (method_exists($this, 'after_createUniqueIndex_callback')) { @@ -2112,7 +2140,8 @@ public function checkRecordExists($ID) $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $recordExists = $provider->checkRecordExists($ID); if (method_exists($this, 'after_checkRecordExists_callback')) { @@ -2141,7 +2170,8 @@ public function isTableOverloaded() $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $isOverloaded = $provider->isTableOverloaded(); self::$logger->debug('<get('db.provider.name'), $Record); + if (isset($record)) { + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($record); } else { - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), new Person()); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord(new Person()); } try { @@ -2185,13 +2217,13 @@ public static function begin($Record = null) /** * Commits the current database transaction. * - * @param ActiveRecord $Record The ActiveRecord instance to pass to the database provider. Leave empty to have a new Person passed. + * @param ActiveRecord $record The ActiveRecord instance to pass to the database provider. Leave empty to have a new Person passed. * * @since 1.0 * * @throws \Alpha\Exception\FailedSaveException */ - public static function commit($Record = null) + public static function commit($record = null) { if (self::$logger == null) { self::$logger = new Logger('ActiveRecord'); @@ -2200,10 +2232,12 @@ public static function commit($Record = null) $config = ConfigProvider::getInstance(); - if (isset($Record)) { - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $Record); + if (isset($record)) { + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($record); } else { - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), new Person()); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord(new Person()); } try { @@ -2218,13 +2252,13 @@ public static function commit($Record = null) /** * Aborts the current database transaction. * - * @param ActiveRecord $Record The ActiveRecord instance to pass to the database provider. Leave empty to have a new Person passed. + * @param ActiveRecord $record The ActiveRecord instance to pass to the database provider. Leave empty to have a new Person passed. * * @since 1.0 * * @throws \Alpha\Exception\AlphaException */ - public static function rollback($Record = null) + public static function rollback($record = null) { if (self::$logger == null) { self::$logger = new Logger('ActiveRecord'); @@ -2233,10 +2267,12 @@ public static function rollback($Record = null) $config = ConfigProvider::getInstance(); - if (isset($Record)) { - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $Record); + if (isset($record)) { + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($record); } else { - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), new Person()); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord(new Person()); } try { @@ -2337,9 +2373,9 @@ private function setVersion($versionNumber) */ public function cast($targetClassName, $originalRecord) { - $Record = new $targetClassName(); - $Record->setID($originalRecord->getID()); - $Record->setVersion($originalRecord->getVersion()); + $record = new $targetClassName(); + $record->setID($originalRecord->getID()); + $record->setVersion($originalRecord->getVersion()); // get the class attributes $originalRecordreflection = new ReflectionClass(get_class($originalRecord)); @@ -2354,7 +2390,7 @@ public function cast($targetClassName, $originalRecord) foreach ($originalRecordproperties as $propObj) { $propName = $propObj->name; if (!in_array($propName, $this->transientAttributes)) { - $Record->set($propName, $originalRecord->get($propName)); + $record->set($propName, $originalRecord->get($propName)); } } } else { @@ -2362,12 +2398,12 @@ public function cast($targetClassName, $originalRecord) foreach ($newRecordproperties as $propObj) { $propName = $propObj->name; if (!in_array($propName, $this->transientAttributes)) { - $Record->set($propName, $originalRecord->get($propName)); + $record->set($propName, $originalRecord->get($propName)); } } } - return $Record; + return $record; } /** @@ -2409,7 +2445,7 @@ public function addToCache() $config = ConfigProvider::getInstance(); try { - $cache = CacheProviderFactory::getInstance($config->get('cache.provider.name')); + $cache = ServiceFactory::getInstance($config->get('cache.provider.name'), 'Alpha\Util\Cache\CacheProviderInterface'); $cache->set(get_class($this).'-'.$this->getID(), $this, 3600); } catch (\Exception $e) { self::$logger->error('Error while attempting to store a business object to the ['.$config->get('cache.provider.name').'] @@ -2430,7 +2466,7 @@ public function removeFromCache() $config = ConfigProvider::getInstance(); try { - $cache = CacheProviderFactory::getInstance($config->get('cache.provider.name')); + $cache = ServiceFactory::getInstance($config->get('cache.provider.name'), 'Alpha\Util\Cache\CacheProviderInterface'); $cache->delete(get_class($this).'-'.$this->getID()); } catch (\Exception $e) { self::$logger->error('Error while attempting to remove a business object from ['.$config->get('cache.provider.name').'] @@ -2453,10 +2489,10 @@ public function loadFromCache() $config = ConfigProvider::getInstance(); try { - $cache = CacheProviderFactory::getInstance($config->get('cache.provider.name')); - $Record = $cache->get(get_class($this).'-'.$this->getID()); + $cache = ServiceFactory::getInstance($config->get('cache.provider.name'), 'Alpha\Util\Cache\CacheProviderInterface'); + $record = $cache->get(get_class($this).'-'.$this->getID()); - if (!$Record) { + if (!$record) { self::$logger->debug('Cache miss on key ['.get_class($this).'-'.$this->getID().']'); self::$logger->debug('<transientAttributes)) { - $this->set($propName, $Record->get($propName, true)); + $this->set($propName, $record->get($propName, true)); } elseif (!$propObj->isPrivate() && isset($this->$propName) && $this->$propName instanceof Relation) { $prop = $this->getPropObject($propName); @@ -2595,7 +2631,8 @@ public static function checkDatabaseExists() { $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), new Person()); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord(new Person()); return $provider->checkDatabaseExists(); } @@ -2611,7 +2648,8 @@ public static function createDatabase() { $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), new Person()); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord(new Person()); $provider->createDatabase(); } @@ -2626,7 +2664,8 @@ public static function dropDatabase() { $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), new Person()); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord(new Person()); $provider->dropDatabase(); } } diff --git a/Alpha/Model/ActiveRecordProviderFactory.php b/Alpha/Model/ActiveRecordProviderFactory.php deleted file mode 100644 index 0c2db3b4..00000000 --- a/Alpha/Model/ActiveRecordProviderFactory.php +++ /dev/null @@ -1,106 +0,0 @@ - - * - * @version $Id: ActiveRecordProviderFactory.php 1842 2014-11-12 22:27:01Z alphadevx $ - * - * @license http://www.opensource.org/licenses/bsd-license.php The BSD License - * @copyright Copyright (c) 2017, John Collins (founder of Alpha Framework). - * All rights reserved. - * - *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the
- * following conditions are met:
- *
- * * Redistributions of source code must retain the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer.
- * * Redistributions in binary form must reproduce the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer in the documentation and/or other
- *   materials provided with the distribution.
- * * Neither the name of the Alpha Framework nor the names
- *   of its contributors may be used to endorse or promote
- *   products derived from this software without specific
- *   prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
- */ -class ActiveRecordProviderFactory -{ - /** - * Trace logger. - * - * @var \Alpha\Util\Logging\Logger - * - * @since 1.1 - */ - private static $logger = null; - - /** - * A static method that attempts to return a ActiveRecordProviderInterface instance - * based on the name of the provider class supplied. - * - * @param string $providerName The fully-qualified class name of the provider class. - * @param ActiveRecord $Record The (optional) active record instance to pass to the persistance provider for mapping. - * - * @throws \Alpha\Exception\IllegalArguementException - * - * @return \Alpha\Model\ActiveRecordProviderInterface - * - * @since 1.1 - */ - public static function getInstance($providerName, $Record = null) - { - if (self::$logger == null) { - self::$logger = new Logger('ActiveRecordProviderFactory'); - } - - self::$logger->debug('>>getInstance(providerName=['.$providerName.'], Record=['.print_r($Record, true).'])'); - - if (class_exists($providerName)) { - $instance = new $providerName(); - - if (!$instance instanceof ActiveRecordProviderInterface) { - throw new IllegalArguementException('The class ['.$providerName.'] does not implement the expected ActiveRecordProviderInterface interface!'); - } - - if ($Record instanceof ActiveRecord) { - $instance->setRecord($Record); - } - - self::$logger->debug('<debug('<get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); // get the class attributes $reflection = new ReflectionClass(get_class($this->record)); @@ -1040,7 +1040,7 @@ public function saveAttribute($attribute, $value) $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); if ($this->record->getVersion() != $this->record->getVersionNumber()->getValue()) { throw new LockingException('Could not save the object as it has been updated by another user. Please try saving again.'); diff --git a/Alpha/Model/ActiveRecordProviderSQLite.php b/Alpha/Model/ActiveRecordProviderSQLite.php index beac587c..f8df802a 100644 --- a/Alpha/Model/ActiveRecordProviderSQLite.php +++ b/Alpha/Model/ActiveRecordProviderSQLite.php @@ -15,7 +15,7 @@ use Alpha\Model\Type\Boolean; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Logging\Logger; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Exception\AlphaException; use Alpha\Exception\FailedSaveException; use Alpha\Exception\FailedDeleteException; @@ -472,9 +472,9 @@ public function loadAll($start = 0, $limit = 0, $orderBy = 'ID', $order = 'ASC', if (!$ignoreClassType && $this->record->isTableOverloaded()) { if ($limit == 0) { - $sqlQuery = 'SELECT ID FROM '.$this->record->getTableName().' WHERE classname = \''.addslashes(get_class($this->record)).'\' ORDER BY '.$orderBy.' '.$order.';'; + $sqlQuery = 'SELECT ID FROM '.$this->record->getTableName().' WHERE classname = \''.get_class($this->record).'\' ORDER BY '.$orderBy.' '.$order.';'; } else { - $sqlQuery = 'SELECT ID FROM '.$this->record->getTableName().' WHERE classname = \''.addslashes(get_class($this->record)).'\' ORDER BY '.$orderBy.' '.$order.' LIMIT '. + $sqlQuery = 'SELECT ID FROM '.$this->record->getTableName().' WHERE classname = \''.get_class($this->record).'\' ORDER BY '.$orderBy.' '.$order.' LIMIT '. $limit.' OFFSET '.$start.';'; } } else { @@ -833,7 +833,7 @@ public function save() $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); // get the class attributes $reflection = new ReflectionClass(get_class($this->record)); @@ -1070,7 +1070,7 @@ public function saveAttribute($attribute, $value) $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); if ($this->record->getVersion() != $this->record->getVersionNumber()->getValue()) { throw new LockingException('Could not save the object as it has been updated by another user. Please try saving again.'); @@ -1606,7 +1606,7 @@ public function getCount($attributes = array(), $values = array()) self::$logger->debug('>>getCount(attributes=['.var_export($attributes, true).'], values=['.var_export($values, true).'])'); if ($this->record->isTableOverloaded()) { - $whereClause = ' WHERE classname = \''.addslashes(get_class($this->record)).'\' AND'; + $whereClause = ' WHERE classname = \''.get_class($this->record).'\' AND'; } else { $whereClause = ' WHERE'; } diff --git a/Alpha/Model/Article.php b/Alpha/Model/Article.php index 7bb998eb..2869ba52 100644 --- a/Alpha/Model/Article.php +++ b/Alpha/Model/Article.php @@ -9,7 +9,7 @@ use Alpha\Model\Type\Relation; use Alpha\Util\Config\Configprovider; use Alpha\Util\Logging\Logger; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Exception\ValidationException; use Alpha\Exception\FileNotFoundException; use Alpha\Exception\AlphaException; @@ -486,7 +486,7 @@ public function checkUserVoted() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); // just going to return true if nobody is logged in if ($session->get('currentUser') == null) { return true; diff --git a/Alpha/Model/Person.php b/Alpha/Model/Person.php index ce8f4c54..eeb698d4 100644 --- a/Alpha/Model/Person.php +++ b/Alpha/Model/Person.php @@ -8,7 +8,7 @@ use Alpha\Util\Helper\Validator; use Alpha\Util\Logging\Logger; use Alpha\Util\Config\ConfigProvider; -use Alpha\Util\Email\EmailProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Exception\RecordNotFoundException; /** @@ -408,7 +408,7 @@ public function sendMail($message, $subject) $body .= ''; - $mailer = EmailProviderFactory::getInstance('Alpha\Util\Email\EmailProviderPHP'); + $mailer = ServiceFactory::getInstance('Alpha\Util\Email\EmailProviderPHP', 'Alpha\Util\Email\EmailProviderInterface'); $mailer->send($this->get('email'), $config->get('email.reply.to'), $subject, $body, true); } diff --git a/Alpha/Model/Tag.php b/Alpha/Model/Tag.php index 886278d6..ba3fbb01 100644 --- a/Alpha/Model/Tag.php +++ b/Alpha/Model/Tag.php @@ -9,7 +9,7 @@ use Alpha\Exception\CustomQueryException; use Alpha\Exception\RecordNotFoundException; use Alpha\Util\Config\ConfigProvider; -use Alpha\Util\Cache\CacheProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Util\Helper\Validator; use Alpha\Util\Logging\Logger; use Exception; @@ -151,7 +151,8 @@ public function loadTags($taggedClass, $taggedID) throw new IllegalArguementException('The taggedClass or taggedID provided are empty'); } - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); try { $tags = $provider->loadAllByAttributes(array('taggedID', 'taggedClass'), array($taggedID, $taggedClass)); @@ -182,7 +183,8 @@ public static function getPopularTagsArray($limit) { $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), new self()); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord(new self()); $sqlQuery = 'SELECT content, count(*) as count FROM '.self::TABLE_NAME." GROUP BY content ORDER BY count DESC LIMIT $limit"; @@ -310,7 +312,7 @@ protected function after_save_callback() if ($config->get('cache.provider.name') != '') { try { - $cache = CacheProviderFactory::getInstance($config->get('cache.provider.name')); + $cache = ServiceFactory::getInstance($config->get('cache.provider.name'), 'Alpha\Util\Cache\CacheProviderInterface'); $cache->delete($this->get('content')); } catch (\Exception $e) { self::$logger->error('Error while attempting to remove search matches array from the ['.$config->get('cache.provider.name').'] diff --git a/Alpha/Model/Type/DEnum.php b/Alpha/Model/Type/DEnum.php index 5133ee56..2d9dd50c 100644 --- a/Alpha/Model/Type/DEnum.php +++ b/Alpha/Model/Type/DEnum.php @@ -3,7 +3,7 @@ namespace Alpha\Model\Type; use Alpha\Model\ActiveRecord; -use Alpha\Model\ActiveRecordProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Model\Type\SmallText; use Alpha\Exception\RecordNotFoundException; use Alpha\Exception\AlphaException; @@ -322,7 +322,8 @@ public function getItemCount() { $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $sqlQuery = 'SELECT COUNT(ID) AS item_count FROM DEnumItem WHERE DEnumID = \''.$this->getID().'\';'; diff --git a/Alpha/Model/Type/DEnumItem.php b/Alpha/Model/Type/DEnumItem.php index 2079fa9d..6f6eb465 100644 --- a/Alpha/Model/Type/DEnumItem.php +++ b/Alpha/Model/Type/DEnumItem.php @@ -3,7 +3,7 @@ namespace Alpha\Model\Type; use Alpha\Model\ActiveRecord; -use Alpha\Model\ActiveRecordProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Util\Helper\Validator; use Alpha\Util\Config\ConfigProvider; use Alpha\Exception\AlphaException; @@ -135,7 +135,8 @@ public function loadItems($EnumID) $sqlQuery = 'SELECT ID FROM '.self::TABLE_NAME.' WHERE DEnumID = \''.$EnumID.'\';'; - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); try { $result = $provider->query($sqlQuery); diff --git a/Alpha/Model/Type/RelationLookup.php b/Alpha/Model/Type/RelationLookup.php index a43cc24f..351796de 100644 --- a/Alpha/Model/Type/RelationLookup.php +++ b/Alpha/Model/Type/RelationLookup.php @@ -3,7 +3,7 @@ namespace Alpha\Model\Type; use Alpha\Model\ActiveRecord; -use Alpha\Model\ActiveRecordProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Exception\FailedLookupCreateException; use Alpha\Exception\IllegalArguementException; use Alpha\Exception\AlphaException; @@ -238,7 +238,8 @@ public function loadAllByAttribute($attribute, $value, $start = 0, $limit = 0, $ $config = ConfigProvider::getInstance(); - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $objects = $provider->loadAllByAttribute($attribute, $value, $start, $limit, $orderBy, $order, $ignoreClassType, array($this->leftClassName, $this->rightClassName)); if (method_exists($this, 'after_loadAllByAttribute_callback')) { @@ -274,7 +275,8 @@ public function loadAllByAttributes($attributes = array(), $values = array(), $s '] provided to loadAllByAttributes'); } - $provider = ActiveRecordProviderFactory::getInstance($config->get('db.provider.name'), $this); + $provider = ServiceFactory::getInstance($config->get('db.provider.name'), 'Alpha\Model\ActiveRecordProviderInterface'); + $provider->setRecord($this); $objects = $provider->loadAllByAttributes($attributes, $values, $start, $limit, $orderBy, $order, $ignoreClassType, array($this->leftClassName, $this->rightClassName)); if (method_exists($this, 'after_loadAllByAttributes_callback')) { diff --git a/Alpha/Util/Cache/CacheProviderFactory.php b/Alpha/Util/Cache/CacheProviderFactory.php deleted file mode 100644 index 726e7d5f..00000000 --- a/Alpha/Util/Cache/CacheProviderFactory.php +++ /dev/null @@ -1,97 +0,0 @@ - - * @license http://www.opensource.org/licenses/bsd-license.php The BSD License - * @copyright Copyright (c) 2017, John Collins (founder of Alpha Framework). - * All rights reserved. - * - *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the
- * following conditions are met:
- *
- * * Redistributions of source code must retain the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer.
- * * Redistributions in binary form must reproduce the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer in the documentation and/or other
- *   materials provided with the distribution.
- * * Neither the name of the Alpha Framework nor the names
- *   of its contributors may be used to endorse or promote
- *   products derived from this software without specific
- *   prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
- */ -class CacheProviderFactory -{ - /** - * Trace logger. - * - * @var \Alpha\Util\Logging\Logger - * - * @since 1.1 - */ - private static $logger = null; - - /** - * A static method that attempts to return a CacheProviderInterface instance - * based on the name of the provider class supplied. - * - * @param string $providerName The class name of the provider class (fully qualified). - * - * @throws \Alpha\Exception\IllegalArguementException - * - * @return \Alpha\Util\Cache\CacheProviderInterface - * - * @since 1.1 - */ - public static function getInstance($providerName) - { - if (self::$logger == null) { - self::$logger = new Logger('CacheProviderFactory'); - } - - self::$logger->debug('>>getInstance(providerName=['.$providerName.'])'); - - if (class_exists($providerName)) { - $instance = new $providerName(); - - if (!$instance instanceof CacheProviderInterface) { - throw new IllegalArguementException('The class ['.$providerName.'] does not implement the expected CacheProviderInterface intwerface!'); - } - - self::$logger->debug('<debug('< - * @license http://www.opensource.org/licenses/bsd-license.php The BSD License - * @copyright Copyright (c) 2017, John Collins (founder of Alpha Framework). - * All rights reserved. - * - *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the
- * following conditions are met:
- *
- * * Redistributions of source code must retain the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer.
- * * Redistributions in binary form must reproduce the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer in the documentation and/or other
- *   materials provided with the distribution.
- * * Neither the name of the Alpha Framework nor the names
- *   of its contributors may be used to endorse or promote
- *   products derived from this software without specific
- *   prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
- */ -class HighlightProviderFactory -{ - /** - * Trace logger. - * - * @var \Alpha\Util\Logging\Logger - * - * @since 1.2 - */ - private static $logger = null; - - /** - * A static method that attempts to return a HighlightProviderInterface instance - * based on the name of the provider class supplied. - * - * @param string $providerName The fully-qualified class name of the provider class, should implement Alpha\Util\Code\Highlight\HighlightProviderInterface - * - * @throws \Alpha\Exception\IllegalArguementException - * - * @return \Alpha\Util\Code\Highlight\HighlightProviderInterface - * - * @since 1.2 - */ - public static function getInstance($providerName) - { - if (self::$logger == null) { - self::$logger = new Logger('HighlightProviderFactory'); - } - - self::$logger->debug('>>getInstance(providerName=['.$providerName.'])'); - - if (class_exists($providerName)) { - $instance = new $providerName(); - - if (!$instance instanceof HighlightProviderInterface) { - throw new IllegalArguementException('The class ['.$providerName.'] does not implement the expected HighlightProviderInterface interface!'); - } - - self::$logger->debug('<debug('< - * @license http://www.opensource.org/licenses/bsd-license.php The BSD License - * @copyright Copyright (c) 2017, John Collins (founder of Alpha Framework). - * All rights reserved. - * - *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the
- * following conditions are met:
- *
- * * Redistributions of source code must retain the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer.
- * * Redistributions in binary form must reproduce the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer in the documentation and/or other
- *   materials provided with the distribution.
- * * Neither the name of the Alpha Framework nor the names
- *   of its contributors may be used to endorse or promote
- *   products derived from this software without specific
- *   prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
- */ -class EmailProviderFactory -{ - /** - * Trace logger. - * - * @var \Alpha\Util\Logging\Logger - * - * @since 2.0 - */ - private static $logger = null; - - /** - * A static method that attempts to return a EmailProviderInterface instance - * based on the name of the provider class supplied. - * - * @param string $providerName The class name of the provider class (fully qualified). - * - * @throws \Alpha\Exception\IllegalArguementException - * - * @return EmailProviderInterface|null - * - * @since 2.0 - */ - public static function getInstance($providerName) - { - if (self::$logger == null) { - self::$logger = new Logger('EmailProviderFactory'); - } - - self::$logger->debug('>>getInstance(providerName=['.$providerName.'])'); - - if (class_exists($providerName)) { - $instance = new $providerName(); - - if (!$instance instanceof EmailProviderInterface) { - throw new IllegalArguementException('The class ['.$providerName.'] does not implement the expected EmailProviderInterface intwerface!'); - } - - self::$logger->debug('<debug('<get('cms.highlight.provider.name') != '') { - $highlighter = HighlightProviderFactory::getInstance($config->get('cms.highlight.provider.name')); + $highlighter = ServiceFactory::getInstance($config->get('cms.highlight.provider.name'), 'Alpha\Util\Code\Highlight\HighlightProviderInterface'); $codeblock = $highlighter->highlight($codeblock, $language); } else { $codeblock = htmlspecialchars($codeblock, ENT_NOQUOTES); diff --git a/Alpha/Util/Http/Session/SessionProviderArray.php b/Alpha/Util/Http/Session/SessionProviderArray.php index 4cd84cd7..87287691 100644 --- a/Alpha/Util/Http/Session/SessionProviderArray.php +++ b/Alpha/Util/Http/Session/SessionProviderArray.php @@ -83,6 +83,7 @@ class SessionProviderArray implements SessionProviderInterface public function __construct() { self::$logger = new Logger('SessionProviderArray'); + $this->init(); } /** diff --git a/Alpha/Util/Http/Session/SessionProviderFactory.php b/Alpha/Util/Http/Session/SessionProviderFactory.php deleted file mode 100644 index 12409ca9..00000000 --- a/Alpha/Util/Http/Session/SessionProviderFactory.php +++ /dev/null @@ -1,98 +0,0 @@ - - * @license http://www.opensource.org/licenses/bsd-license.php The BSD License - * @copyright Copyright (c) 2017, John Collins (founder of Alpha Framework). - * All rights reserved. - * - *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the
- * following conditions are met:
- *
- * * Redistributions of source code must retain the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer.
- * * Redistributions in binary form must reproduce the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer in the documentation and/or other
- *   materials provided with the distribution.
- * * Neither the name of the Alpha Framework nor the names
- *   of its contributors may be used to endorse or promote
- *   products derived from this software without specific
- *   prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
- */ -class SessionProviderFactory -{ - /** - * Trace logger. - * - * @var \Alpha\Util\Logging\Logger - * - * @since 2.0 - */ - private static $logger = null; - - /** - * A static method that attempts to return a SessionProviderInterface instance - * based on the name of the provider class supplied. - * - * @param string $providerName The class name of the provider class (fully qualified). - * - * @throws \Alpha\Exception\IllegalArguementException - * - * @return \Alpha\Util\Http\Session\SessionProviderInterface - * - * @since 2.0 - */ - public static function getInstance($providerName) - { - if (self::$logger == null) { - self::$logger = new Logger('SessionProviderFactory'); - } - - self::$logger->debug('>>getInstance(providerName=['.$providerName.'])'); - - if (class_exists($providerName)) { - $instance = new $providerName(); - $instance->init(); - - if (!$instance instanceof SessionProviderInterface) { - throw new IllegalArguementException('The class ['.$providerName.'] does not implement the expected SessionProviderInterface intwerface!'); - } - - self::$logger->debug('<debug('<init(); } /** diff --git a/Alpha/Util/Logging/KPI.php b/Alpha/Util/Logging/KPI.php index 3e3d4386..9d54617d 100644 --- a/Alpha/Util/Logging/KPI.php +++ b/Alpha/Util/Logging/KPI.php @@ -6,7 +6,7 @@ use Alpha\Model\Type\SmallText; use Alpha\Util\Helper\Validator; use Alpha\Util\Config\ConfigProvider; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; /** * A Key Performance Indicator (KPI) logging class. @@ -130,7 +130,7 @@ public function __construct($name) $this->startTime = microtime(true); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); // a startTime value may have been passed from a previous request if ($session->get($name.'-startTime') !== false) { @@ -150,7 +150,7 @@ public function storeStartTimeInSession() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $session->set($this->name->getValue().'-startTime', $this->startTime); } diff --git a/Alpha/Util/Logging/LogProviderFactory.php b/Alpha/Util/Logging/LogProviderFactory.php deleted file mode 100644 index 208df259..00000000 --- a/Alpha/Util/Logging/LogProviderFactory.php +++ /dev/null @@ -1,83 +0,0 @@ - - * @license http://www.opensource.org/licenses/bsd-license.php The BSD License - * @copyright Copyright (c) 2017, John Collins (founder of Alpha Framework). - * All rights reserved. - * - *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the
- * following conditions are met:
- *
- * * Redistributions of source code must retain the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer.
- * * Redistributions in binary form must reproduce the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer in the documentation and/or other
- *   materials provided with the distribution.
- * * Neither the name of the Alpha Framework nor the names
- *   of its contributors may be used to endorse or promote
- *   products derived from this software without specific
- *   prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
- */ -class LogProviderFactory -{ - /** - * A static method that attempts to return a LogProviderInterface instance - * based on the name of the provider class supplied. - * - * @param $providerName The class name of the provider class (fully qualified). - * - * @throws \Alpha\Exception\IllegalArguementException - * - * @return \Alpha\Util\Logging\LogProviderInterface - * - * @since 2.0 - */ - public static function getInstance($providerName) - { - $config = ConfigProvider::getInstance(); - - if (class_exists($providerName)) { - $instance = new $providerName(); - - if (!$instance instanceof LogProviderInterface) { - throw new IllegalArguementException('The class ['.$providerName.'] does not implement the expected LogProviderInterface intwerface!'); - } - - $instance->setMaxSize($config->get('app.log.file.max.size')); - - return $instance; - } else { - throw new IllegalArguementException('The class ['.$providerName.'] is not defined anywhere!'); - } - } -} diff --git a/Alpha/Util/Logging/Logger.php b/Alpha/Util/Logging/Logger.php index d8549c95..08808250 100644 --- a/Alpha/Util/Logging/Logger.php +++ b/Alpha/Util/Logging/Logger.php @@ -3,8 +3,7 @@ namespace Alpha\Util\Logging; use Alpha\Util\Config\ConfigProvider; -use Alpha\Util\Email\EmailProviderFactory; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Util\Http\Request; use Alpha\Model\ActionLog; @@ -111,7 +110,7 @@ public function __construct($classname) $this->classname = $classname; $this->level = $config->get('app.log.trace.level'); $this->debugClasses = explode(',', $config->get('app.log.trace.debug.classes')); - $this->logProvider = LogProviderFactory::getInstance('Alpha\Util\Logging\LogProviderFile'); + $this->logProvider = ServiceFactory::getInstance('Alpha\Util\Logging\LogProviderFile', 'Alpha\Util\Logging\LogProviderInterface', true); $this->logProvider->setPath($config->get('app.file.store.dir').'logs/'.$config->get('app.log.file')); $this->request = new Request(array('method' => 'GET')); // hard-coding to GET here is fine as we don't log HTTP method (yet). @@ -230,7 +229,7 @@ public function action($message) { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); if ($session->get('currentUser') != null) { $action = new ActionLog(); @@ -264,7 +263,7 @@ public function notifyAdmin($message) $body .= "\n\nKind regards,\n\nAdministrator\n--\n".$config->get('app.url'); - $mailer = EmailProviderFactory::getInstance('Alpha\Util\Email\EmailProviderPHP'); + $mailer = ServiceFactory::getInstance('Alpha\Util\Email\EmailProviderPHP', 'Alpha\Util\Email\EmailProviderInterface'); $mailer->send($config->get('app.log.error.mail.address'), $config->get('email.reply.to'), 'Error in class '.$this->classname.' on site '.$config->get('app.title'), $body); } } diff --git a/Alpha/Util/Search/SearchProviderFactory.php b/Alpha/Util/Search/SearchProviderFactory.php deleted file mode 100644 index 342300f1..00000000 --- a/Alpha/Util/Search/SearchProviderFactory.php +++ /dev/null @@ -1,97 +0,0 @@ - - * @license http://www.opensource.org/licenses/bsd-license.php The BSD License - * @copyright Copyright (c) 2017, John Collins (founder of Alpha Framework). - * All rights reserved. - * - *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the
- * following conditions are met:
- *
- * * Redistributions of source code must retain the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer.
- * * Redistributions in binary form must reproduce the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer in the documentation and/or other
- *   materials provided with the distribution.
- * * Neither the name of the Alpha Framework nor the names
- *   of its contributors may be used to endorse or promote
- *   products derived from this software without specific
- *   prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
- */ -class SearchProviderFactory -{ - /** - * Trace logger. - * - * @var \Alpha\Util\Logging\Logger; - * - * @since 1.2.3 - */ - private static $logger = null; - - /** - * A static method that attempts to return a SearchProviderInterface instance - * based on the name of the provider class supplied. - * - * @param string $providerName The class name of the provider class, should be fully-qualified. - * - * @throws \Alpha\Exception\IllegalArguementException; - * - * @return \Alpha\Util\Search\SearchProviderInterface - * - * @since 1.2.3 - */ - public static function getInstance($providerName) - { - if (self::$logger == null) { - self::$logger = new Logger('SearchProviderFactory'); - } - - self::$logger->debug('>>getInstance(providerName=['.$providerName.'])'); - - if (class_exists($providerName)) { - $instance = new $providerName(); - - if (!$instance instanceof SearchProviderInterface) { - throw new IllegalArguementException('The class ['.$providerName.'] does not implement the expected SearchProviderInterface interface!'); - } - - self::$logger->debug('<debug('<get('cache.provider.name')); + $cache = ServiceFactory::getInstance($config->get('cache.provider.name'), 'Alpha\Util\Cache\CacheProviderInterface'); $matches = $cache->get($key); if (!$matches) { @@ -346,7 +346,7 @@ public function addToCache($key, $matches) $config = ConfigProvider::getInstance(); try { - $cache = CacheProviderFactory::getInstance($config->get('cache.provider.name')); + $cache = ServiceFactory::getInstance($config->get('cache.provider.name'), 'Alpha\Util\Cache\CacheProviderInterface'); $cache->set($key, $matches, 86400); // cache search matches for a day } catch (\Exception $e) { self::$logger->error('Error while attempting to store a search matches array to the ['.$config->get('cache.provider.name').'] diff --git a/Alpha/Util/Service/ServiceFactory.php b/Alpha/Util/Service/ServiceFactory.php new file mode 100644 index 00000000..d27b994e --- /dev/null +++ b/Alpha/Util/Service/ServiceFactory.php @@ -0,0 +1,124 @@ + + * @license http://www.opensource.org/licenses/bsd-license.php The BSD License + * @copyright Copyright (c) 2017, John Collins (founder of Alpha Framework). + * All rights reserved. + * + *
+ * Redistribution and use in source and binary forms, with or
+ * without modification, are permitted provided that the
+ * following conditions are met:
+ *
+ * * Redistributions of source code must retain the above
+ *   copyright notice, this list of conditions and the
+ *   following disclaimer.
+ * * Redistributions in binary form must reproduce the above
+ *   copyright notice, this list of conditions and the
+ *   following disclaimer in the documentation and/or other
+ *   materials provided with the distribution.
+ * * Neither the name of the Alpha Framework nor the names
+ *   of its contributors may be used to endorse or promote
+ *   products derived from this software without specific
+ *   prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
+ * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+ * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
+ * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ * 
+ */ +class ServiceFactory +{ + /** + * Trace logger. + * + * @var \Alpha\Util\Logging\Logger + * + * @since 3.0 + */ + private static $logger = null; + + /** + * A static array of service singletons in case any service needs to be accessed as a single instance. + * + * @var array + * + * @since 3.0 + */ + private static $singletons = array(); + + /** + * A static method that attempts to return a service provider instance + * based on the name of the provider class supplied. If the instance does not + * implement the desired interface, an exception is thrown. + * + * @param string $serviceName The class name of the service class (fully qualified). + * @param string $serviceInterface The interface name of the service class returned (fully qualified). + * @param bool $isSingleton Set to true if the service instance requested is a singleton, default is false (you get a new instance each time). + * + * @throws \Alpha\Exception\IllegalArguementException + * + * @return \stdClass + * + * @since 3.0 + */ + public static function getInstance($serviceName, $serviceInterface, $isSingleton = false) + { + // as the LogProviderInterface is itself a service, we don't call it's constructor again during instantiation + if (self::$logger === null && $serviceInterface != 'Alpha\Util\Logging\LogProviderInterface') { + self::$logger = new Logger('ServiceFactory'); + } + + if (self::$logger !== null) { + self::$logger->debug('>>getInstance(serviceName=['.$serviceName.'], serviceInterface=['.$serviceInterface.'], isSingleton=['.$isSingleton.'])'); + } + + if (class_exists($serviceName)) { + if ($isSingleton && in_array($serviceName, self::$singletons)) { + return self::$singletons[$serviceName]; + } + + $instance = new $serviceName(); + + if (!$instance instanceof $serviceInterface) { + throw new IllegalArguementException('The class ['.$serviceName.'] does not implement the expected ['.$serviceInterface.'] interface!'); + } + + if ($isSingleton && !in_array($serviceName, self::$singletons)) { + self::$singletons[$serviceName] = $instance; + } + + if (self::$logger !== null) { + self::$logger->debug('<debug('<get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $markdown = new MarkdownFacade($this->record); $author = new Person(); @@ -154,7 +154,7 @@ public function editView($fields = array()) { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $html = ''; $html .= ''; diff --git a/Alpha/View/DEnumView.php b/Alpha/View/DEnumView.php index bbd92439..bb99ecff 100644 --- a/Alpha/View/DEnumView.php +++ b/Alpha/View/DEnumView.php @@ -4,7 +4,7 @@ use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Security\SecurityUtils; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Controller\Front\FrontController; use Alpha\View\Widget\SmallTextBox; use Alpha\View\Widget\Button; @@ -66,7 +66,7 @@ public function listView($fields = array()) { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $reflection = new \ReflectionClass(get_class($this->record)); $properties = $reflection->getProperties(); diff --git a/Alpha/View/Renderer/Html/RendererProviderHTML.php b/Alpha/View/Renderer/Html/RendererProviderHTML.php index 8ee56135..6d6d3cb5 100644 --- a/Alpha/View/Renderer/Html/RendererProviderHTML.php +++ b/Alpha/View/Renderer/Html/RendererProviderHTML.php @@ -16,7 +16,7 @@ use Alpha\Util\Security\SecurityUtils; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\InputFilter; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Util\Http\Request; use Alpha\Model\Type\DEnum; use Alpha\Model\Type\SmallText; @@ -222,7 +222,7 @@ public function listView($fields = array()) $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); // work out how many columns will be in the table $reflection = new ReflectionClass(get_class($this->record)); @@ -369,7 +369,7 @@ public function detailedView($fields = array()) $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); // we may want to display the ID regardless of class $fields['IDLabel'] = $this->record->getDataLabel('ID'); @@ -594,7 +594,7 @@ public static function displayPageHead($controller) $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); if (!class_exists(get_class($controller))) { throw new IllegalArguementException('The controller provided ['.get_class($controller).'] is not defined anywhere!'); diff --git a/Alpha/View/Renderer/RendererProviderFactory.php b/Alpha/View/Renderer/RendererProviderFactory.php deleted file mode 100644 index 5da1f48b..00000000 --- a/Alpha/View/Renderer/RendererProviderFactory.php +++ /dev/null @@ -1,100 +0,0 @@ - - * @license http://www.opensource.org/licenses/bsd-license.php The BSD License - * @copyright Copyright (c) 2017, John Collins (founder of Alpha Framework). - * All rights reserved. - * - *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the
- * following conditions are met:
- *
- * * Redistributions of source code must retain the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer.
- * * Redistributions in binary form must reproduce the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer in the documentation and/or other
- *   materials provided with the distribution.
- * * Neither the name of the Alpha Framework nor the names
- *   of its contributors may be used to endorse or promote
- *   products derived from this software without specific
- *   prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
- */ -class RendererProviderFactory -{ - /** - * Trace logger. - * - * @var \Alpha\Util\Logging\Logger - * - * @since 1.2 - */ - private static $logger = null; - - /** - * A static method that attempts to return a RendererProviderInterface instance - * based on the name of the provider class supplied. - * - * @param $providerName The fully-qualified class name of the provider class, must implement Alpha\View\Renderer\RendererProviderInterface. - * @param $Record The Alpha\Model\ActiveRecord instance to pass to the renderer provider for passing data. - * - * @throws \Alpha\Exception\IllegalArguementException - * - * @return \Alpha\View\Renderer\RendererProviderInterface - * - * @since 1.2 - */ - public static function getInstance($providerName, $Record = null) - { - if (self::$logger == null) { - self::$logger = new Logger('RendererProviderFactory'); - } - - self::$logger->debug('>>getInstance(providerName=['.$providerName.'])'); - - if (!class_exists($providerName)) { - throw new IllegalArguementException('The class ['.$providerName.'] is not defined anywhere!'); - } - - $instance = new $providerName(); - if (isset($Record)) { - $instance->setRecord($Record); - } - - if (!$instance instanceof RendererProviderInterface) { - throw new IllegalArguementException('The class ['.$providerName.'] does not implement the expected AlphaRendererProviderInterface interface!'); - } - - self::$logger->debug('<get('app.renderer.provider.name')); + self::$provider = ServiceFactory::getInstance($config->get('app.renderer.provider.name'), 'Alpha\View\Renderer\RendererProviderInterface'); return self::$provider; } diff --git a/Alpha/View/ViewState.php b/Alpha/View/ViewState.php index 4dd1044c..3a40c8bf 100644 --- a/Alpha/View/ViewState.php +++ b/Alpha/View/ViewState.php @@ -4,7 +4,7 @@ use Alpha\Exception\IllegalArguementException; use Alpha\Util\Config\ConfigProvider; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use ReflectionProperty; /** @@ -117,7 +117,7 @@ public static function getInstance() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); // if we don't already have the object in memory... if (!isset(self::$instance)) { @@ -170,7 +170,7 @@ public function set($key, $value) { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $attribute = new ReflectionProperty(get_class($this), $key); if ($attribute != null) { diff --git a/Alpha/View/Widget/RecordSelector.php b/Alpha/View/Widget/RecordSelector.php index bc5a1bbf..8551dd94 100644 --- a/Alpha/View/Widget/RecordSelector.php +++ b/Alpha/View/Widget/RecordSelector.php @@ -5,7 +5,7 @@ use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Logging\Logger; use Alpha\Util\Security\SecurityUtils; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Util\Http\Request; use Alpha\Model\Type\Relation; use Alpha\Exception\IllegalArguementException; @@ -156,7 +156,7 @@ public function render($expanded = false, $buttons = true) $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $fieldname = ($config->get('security.encrypt.http.fieldnames') ? base64_encode(SecurityUtils::encrypt($this->name)) : $this->name); diff --git a/Alpha/View/Widget/TagCloud.php b/Alpha/View/Widget/TagCloud.php index 08d1c6d6..9f5110dc 100644 --- a/Alpha/View/Widget/TagCloud.php +++ b/Alpha/View/Widget/TagCloud.php @@ -4,7 +4,7 @@ use Alpha\Util\Logging\Logger; use Alpha\Util\Config\ConfigProvider; -use Alpha\Util\Cache\CacheProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Model\Tag; /** @@ -85,7 +85,7 @@ public function __construct($limit, $cacheKey = '') self::$logger = new Logger('TagCloud'); if ($cacheKey != '' && $config->get('cache.provider.name') != '') { - $cache = CacheProviderFactory::getInstance($config->get('cache.provider.name')); + $cache = ServiceFactory::getInstance($config->get('cache.provider.name'), 'Alpha\Util\Cache\CacheProviderInterface'); $this->popTags = $cache->get($cacheKey); // cache look-up failed, so add it for the next time diff --git a/README.md b/README.md index 2b04098c..5ec40cf8 100644 --- a/README.md +++ b/README.md @@ -491,35 +491,35 @@ Alpha includes many varied utilities in the _Alpha\Util_ package. The following A data cache is provided, that provides a factory and injectable providers that support Memcache, Redis, and APCu. The classes are provided in the _Alpha\Util\Cache_ package, while the providers implement the _Alpha\Util\Cache\CacheProviderInterface_. Here is an example using the Redis provider: - use Alpha\Util\Cache\CacheProviderFactory; + use Alpha\Util\Service\ServiceFactory; // ... - $cache = CacheProviderFactory::getInstance('Alpha\Util\Cache\CacheProviderRedis'); + $cache = ServiceFactory::getInstance('Alpha\Util\Cache\CacheProviderRedis','Alpha\Util\Cache\CacheProviderInterface'); $record = $cache->get($cacheKey); ### Code highlighting The _Alpha\Util\Code\Highlight\HighlightProviderFactory_ providers objects for converting plain source code into code-highlighted HTML source code. Providers for the Geshi and Luminous libraries are provided. Here is an example: - use Alpha\Util\Code\Highlight\HighlightProviderFactory; + use Alpha\Util\Service\ServiceFactory; // ... - $highlighter = HighlightProviderFactory::getInstance('Alpha\Util\Code\Highlight\HighlightProviderGeshi'); + $highlighter = ServiceFactory::getInstance('Alpha\Util\Code\Highlight\HighlightProviderGeshi','Alpha\Util\Code\Highlight\HighlightProviderInterface'); $html = $highlighter->highlight($code, 'php'); ### Email -Alpha provides an email package with a factory and an interface for injecting different email providers. Here is an example usage: +Alpha provides an email package with an interface for injecting different email providers. Here is an example usage: - use Alpha\Util\Email\EmailProviderFactory; + use Alpha\Util\Service\ServiceFactory; use Alpha\Exception\MailNotSentException; // ... - $mailer = EmailProviderFactory::getInstance('Alpha\Util\Email\EmailProviderPHP'); + $mailer = ServiceFactory::getInstance('Alpha\Util\Email\EmailProviderPHP','Alpha\Util\Email\EmailProviderInterface'); try { $mailer->send('to@mail.com', 'from@mail.com', 'Subject', 'Some HTML...', true); @@ -585,11 +585,11 @@ Registering a filter with the front controller is easy, and should be done on ap Alpha provides a session abstraction layer to allow the inject of different session providers, which is very useful for example if you want to store your session in an array for unit testing. It is also possible to write providers to store sessions in NoSQL or database backends. Here is an example of using the default PHP session mechanism: - use Alpha\Util\Http\Session\SessionProviderFactory; + use Alpha\Util\Service\ServiceFactory; // ... - $session = SessionProviderFactory::getInstance('Alpha\Util\Http\Session\SessionProviderPHP'); + $session = ServiceFactory::getInstance('Alpha\Util\Http\Session\SessionProviderPHP', 'Alpha\Util\Http\Session\SessionProviderInterface'); $session->set('somekey', 'somevalue'); // you can also pass complex types echo $session->get('somekey'); diff --git a/test/Alpha/Test/Controller/ActiveRecordControllerTest.php b/test/Alpha/Test/Controller/ActiveRecordControllerTest.php index 6cbc7920..eaa57c47 100644 --- a/test/Alpha/Test/Controller/ActiveRecordControllerTest.php +++ b/test/Alpha/Test/Controller/ActiveRecordControllerTest.php @@ -6,7 +6,7 @@ use Alpha\Controller\ActiveRecordController; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Http\Request; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Model\Person; use Alpha\Model\Rights; @@ -61,7 +61,7 @@ public function testDoGET() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); @@ -137,7 +137,7 @@ public function testDoPOST() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); $controller = new ActiveRecordController(); @@ -197,7 +197,7 @@ public function testDoPUT() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); $controller = new ActiveRecordController(); @@ -258,7 +258,7 @@ public function testDoDELETE() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); $controller = new ActiveRecordController(); diff --git a/test/Alpha/Test/Controller/ArticleControllerTest.php b/test/Alpha/Test/Controller/ArticleControllerTest.php index 163c6112..994247b8 100644 --- a/test/Alpha/Test/Controller/ArticleControllerTest.php +++ b/test/Alpha/Test/Controller/ArticleControllerTest.php @@ -15,7 +15,7 @@ use Alpha\Model\Rights; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Http\Request; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; /** * Test cases for the ArticleController class. @@ -162,7 +162,7 @@ public function testDoGET() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $person = $this->createPersonObject('test'); $person->save(); @@ -229,7 +229,7 @@ public function testDoPUT() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); $controller = new ArticleController(); diff --git a/test/Alpha/Test/Controller/AttachmentControllerTest.php b/test/Alpha/Test/Controller/AttachmentControllerTest.php index 9f6e2127..d1ed7724 100644 --- a/test/Alpha/Test/Controller/AttachmentControllerTest.php +++ b/test/Alpha/Test/Controller/AttachmentControllerTest.php @@ -15,7 +15,7 @@ use Alpha\Model\Rights; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Http\Request; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; /** * Test cases for the AttachmentController class. @@ -145,7 +145,7 @@ public function testDoGET() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); $controller = new ArticleController(); diff --git a/test/Alpha/Test/Controller/ControllerTest.php b/test/Alpha/Test/Controller/ControllerTest.php index 4925b3e9..b218f1ee 100644 --- a/test/Alpha/Test/Controller/ControllerTest.php +++ b/test/Alpha/Test/Controller/ControllerTest.php @@ -13,7 +13,7 @@ use Alpha\Model\Type\DEnumItem; use Alpha\Model\ActiveRecord; use Alpha\Util\Config\ConfigProvider; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Util\Http\Request; use Alpha\Exception\PHPException; use Alpha\Exception\FailedUnitCommitException; @@ -303,7 +303,7 @@ public function testRightsAccess() $lookup->save(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $session->set('currentUser', $this->person); try { @@ -532,7 +532,7 @@ public function testCheckRights() $_SERVER['REQUEST_METHOD'] = 'GET'; $controller = new ImageController('Admin'); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $session->delete('currentUser'); $this->assertFalse($controller->checkRights(), 'Testing that a user with no session cannot access an Admin controller'); diff --git a/test/Alpha/Test/Controller/ControllerTestCase.php b/test/Alpha/Test/Controller/ControllerTestCase.php index e847cd57..7698b1a5 100644 --- a/test/Alpha/Test/Controller/ControllerTestCase.php +++ b/test/Alpha/Test/Controller/ControllerTestCase.php @@ -3,7 +3,7 @@ namespace Alpha\Test\Controller; use Alpha\Util\Config\ConfigProvider; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Model\Person; use Alpha\Model\Rights; use Alpha\Model\ActionLog; @@ -95,7 +95,7 @@ protected function setUp() } $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $session->set('currentUser', $person); } @@ -108,7 +108,7 @@ protected function tearDown() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $session->set('currentUser', null); $person = new Person(); diff --git a/test/Alpha/Test/Controller/DEnumControllerTest.php b/test/Alpha/Test/Controller/DEnumControllerTest.php index 80efd167..47e3c3de 100644 --- a/test/Alpha/Test/Controller/DEnumControllerTest.php +++ b/test/Alpha/Test/Controller/DEnumControllerTest.php @@ -6,7 +6,7 @@ use Alpha\Controller\DEnumController; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Http\Request; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Model\Type\DEnum; use Alpha\Model\Type\DEnumItem; @@ -91,7 +91,7 @@ public function testDoGET() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); @@ -110,7 +110,7 @@ public function testDoPOST() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); $controller = new DEnumController(); diff --git a/test/Alpha/Test/Controller/ExcelControllerTest.php b/test/Alpha/Test/Controller/ExcelControllerTest.php index e71517da..313e405d 100644 --- a/test/Alpha/Test/Controller/ExcelControllerTest.php +++ b/test/Alpha/Test/Controller/ExcelControllerTest.php @@ -6,7 +6,7 @@ use Alpha\Controller\ExcelController; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Http\Request; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Model\Person; use Alpha\Model\Rights; @@ -102,7 +102,7 @@ public function testDoGET() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); diff --git a/test/Alpha/Test/Controller/FeedControllerTest.php b/test/Alpha/Test/Controller/FeedControllerTest.php index a54df9ba..966a89ed 100644 --- a/test/Alpha/Test/Controller/FeedControllerTest.php +++ b/test/Alpha/Test/Controller/FeedControllerTest.php @@ -6,7 +6,7 @@ use Alpha\Controller\FeedController; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Http\Request; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Model\Tag; use Alpha\Model\Type\DEnum; use Alpha\Model\Type\DEnumItem; @@ -151,7 +151,7 @@ public function testDoGET() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); diff --git a/test/Alpha/Test/Controller/GenSecureQueryStringControllerTest.php b/test/Alpha/Test/Controller/GenSecureQueryStringControllerTest.php index 41a05e2e..acd56437 100644 --- a/test/Alpha/Test/Controller/GenSecureQueryStringControllerTest.php +++ b/test/Alpha/Test/Controller/GenSecureQueryStringControllerTest.php @@ -6,7 +6,7 @@ use Alpha\Controller\GenSecureQueryStringController; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Http\Request; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; /** * Test cases for the GenSecureQueryStringController class. @@ -59,7 +59,7 @@ public function testDoGET() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); @@ -78,7 +78,7 @@ public function testDoPOST() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); $controller = new GenSecureQueryStringController(); diff --git a/test/Alpha/Test/Controller/ImageControllerTest.php b/test/Alpha/Test/Controller/ImageControllerTest.php index ac053c59..1a6467e1 100644 --- a/test/Alpha/Test/Controller/ImageControllerTest.php +++ b/test/Alpha/Test/Controller/ImageControllerTest.php @@ -7,7 +7,7 @@ use Alpha\Controller\Controller; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Http\Request; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; /** * Test cases for the ImageController class. @@ -72,7 +72,7 @@ public function testDoGET() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); diff --git a/test/Alpha/Test/Controller/InstallControllerTest.php b/test/Alpha/Test/Controller/InstallControllerTest.php index b9762860..e1a86d27 100644 --- a/test/Alpha/Test/Controller/InstallControllerTest.php +++ b/test/Alpha/Test/Controller/InstallControllerTest.php @@ -6,7 +6,7 @@ use Alpha\Controller\InstallController; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Http\Request; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Model\Person; /** @@ -82,7 +82,7 @@ protected function setup() $person->set('password', 'testpassword'); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $session->set('currentUser', $person); } @@ -101,7 +101,7 @@ public function testDoGET() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); diff --git a/test/Alpha/Test/Controller/ListActiveRecordsControllerTest.php b/test/Alpha/Test/Controller/ListActiveRecordsControllerTest.php index 0dc333e6..3318f3f6 100644 --- a/test/Alpha/Test/Controller/ListActiveRecordsControllerTest.php +++ b/test/Alpha/Test/Controller/ListActiveRecordsControllerTest.php @@ -6,7 +6,7 @@ use Alpha\Controller\ListActiveRecordsController; use Alpha\Util\Http\Request; use Alpha\Util\Config\ConfigProvider; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Model\Article; /** @@ -77,7 +77,7 @@ public function testDoPOSTCreateTable() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); $controller = new ListActiveRecordsController(); @@ -110,7 +110,7 @@ public function testDoPOSTCreateHistoryTable() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); $controller = new ListActiveRecordsController(); @@ -145,7 +145,7 @@ public function testDoPOSTRecreateTable() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); $controller = new ListActiveRecordsController(); @@ -178,7 +178,7 @@ public function testDoPOSTUpdateTable() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); $controller = new ListActiveRecordsController(); diff --git a/test/Alpha/Test/Controller/LogControllerTest.php b/test/Alpha/Test/Controller/LogControllerTest.php index f7cb8579..f19f4480 100644 --- a/test/Alpha/Test/Controller/LogControllerTest.php +++ b/test/Alpha/Test/Controller/LogControllerTest.php @@ -6,7 +6,7 @@ use Alpha\Controller\LogController; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Http\Request; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; /** * Test cases for the LogController class. @@ -59,7 +59,7 @@ public function testDoGET() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); diff --git a/test/Alpha/Test/Controller/LoginControllerTest.php b/test/Alpha/Test/Controller/LoginControllerTest.php index 1270ca01..d4ab9149 100644 --- a/test/Alpha/Test/Controller/LoginControllerTest.php +++ b/test/Alpha/Test/Controller/LoginControllerTest.php @@ -6,7 +6,7 @@ use Alpha\Controller\LoginController; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Http\Request; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Model\Person; use Alpha\Model\Rights; use Alpha\Model\ActionLog; @@ -102,7 +102,7 @@ public function testDoGET() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); @@ -120,7 +120,7 @@ public function testDoPOST() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $person = new Person(); $person->dropTable(); diff --git a/test/Alpha/Test/Controller/LogoutControllerTest.php b/test/Alpha/Test/Controller/LogoutControllerTest.php index 0f2707e5..a87f7de4 100644 --- a/test/Alpha/Test/Controller/LogoutControllerTest.php +++ b/test/Alpha/Test/Controller/LogoutControllerTest.php @@ -6,7 +6,7 @@ use Alpha\Controller\LogoutController; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Http\Request; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Model\Person; use Alpha\Model\Rights; @@ -98,7 +98,7 @@ public function testDoGET() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); $controller = new LogoutController(); diff --git a/test/Alpha/Test/Controller/MetricControllerTest.php b/test/Alpha/Test/Controller/MetricControllerTest.php index 60b158c8..2690481f 100644 --- a/test/Alpha/Test/Controller/MetricControllerTest.php +++ b/test/Alpha/Test/Controller/MetricControllerTest.php @@ -6,7 +6,7 @@ use Alpha\Controller\MetricController; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Http\Request; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; /** * Test cases for the MetricController class. @@ -59,7 +59,7 @@ public function testDoGET() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); diff --git a/test/Alpha/Test/Controller/RecordSelectorControllerTest.php b/test/Alpha/Test/Controller/RecordSelectorControllerTest.php index e276e53a..97939f82 100644 --- a/test/Alpha/Test/Controller/RecordSelectorControllerTest.php +++ b/test/Alpha/Test/Controller/RecordSelectorControllerTest.php @@ -6,7 +6,7 @@ use Alpha\Controller\RecordSelectorController; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Http\Request; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Model\Rights; use Alpha\Model\Person; use Alpha\Model\Article; @@ -100,7 +100,7 @@ public function testDoGET() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); $uri = '/recordselector/m2m/1/hiddenformfield/'.urlencode('Alpha\Model\Person').'/email/'.urlencode('Alpha\Model\Rights').'/name/'.urlencode('Alpha\Model\Person').'/1'; diff --git a/test/Alpha/Test/Controller/SequenceControllerTest.php b/test/Alpha/Test/Controller/SequenceControllerTest.php index 2d49bac1..63f91d04 100644 --- a/test/Alpha/Test/Controller/SequenceControllerTest.php +++ b/test/Alpha/Test/Controller/SequenceControllerTest.php @@ -6,7 +6,7 @@ use Alpha\Controller\SequenceController; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Http\Request; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; /** * Test cases for the SequenceController class. @@ -59,7 +59,7 @@ public function testDoGET() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); diff --git a/test/Alpha/Test/Controller/TagControllerTest.php b/test/Alpha/Test/Controller/TagControllerTest.php index a56364c1..0facd8e6 100644 --- a/test/Alpha/Test/Controller/TagControllerTest.php +++ b/test/Alpha/Test/Controller/TagControllerTest.php @@ -6,7 +6,7 @@ use Alpha\Controller\TagController; use Alpha\Util\Config\ConfigProvider; use Alpha\Util\Http\Request; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Model\Article; use Alpha\Model\Tag; use Alpha\Model\Type\DEnum; @@ -132,7 +132,7 @@ public function testDoPOST() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); $controller = new TagController(); @@ -181,7 +181,7 @@ public function testDoDELETE() { $config = ConfigProvider::getInstance(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $front = new FrontController(); $controller = new TagController(); diff --git a/test/Alpha/Test/Model/ActiveRecordProviderFactoryTest.php b/test/Alpha/Test/Model/ActiveRecordProviderFactoryTest.php deleted file mode 100644 index 15d725f9..00000000 --- a/test/Alpha/Test/Model/ActiveRecordProviderFactoryTest.php +++ /dev/null @@ -1,90 +0,0 @@ - - * - * @version $Id: ActiveRecordProviderFactoryTest.php 1842 2014-11-12 22:27:01Z alphadevx $ - * - * @license http://www.opensource.org/licenses/bsd-license.php The BSD License - * @copyright Copyright (c) 2017, John Collins (founder of Alpha Framework). - * All rights reserved. - * - *
- * Redistribution and use in source and binary forms, with or
- * without modification, are permitted provided that the
- * following conditions are met:
- *
- * * Redistributions of source code must retain the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer.
- * * Redistributions in binary form must reproduce the above
- *   copyright notice, this list of conditions and the
- *   following disclaimer in the documentation and/or other
- *   materials provided with the distribution.
- * * Neither the name of the Alpha Framework nor the names
- *   of its contributors may be used to endorse or promote
- *   products derived from this software without specific
- *   prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
- * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
- * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
- * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
- * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- * 
- */ -class ActiveRecordProviderFactoryTest extends \PHPUnit_Framework_TestCase -{ - /** - * Testing the getInstance() method with good parameters. - * - * @since 1.2.1 - */ - public function testGetInstanceGood() - { - $provider = ActiveRecordProviderFactory::getInstance('Alpha\Model\ActiveRecordProviderSQLite', new Person()); - - $this->assertTrue($provider instanceof \Alpha\Model\ActiveRecordProviderInterface, 'testing the getInstance() method with good parameters'); - $this->assertTrue($provider instanceof \Alpha\Model\ActiveRecordProviderSQLite, 'testing the getInstance() method with good parameters'); - } - - /** - * Testing the getInstance() method with bad parameters. - * - * @since 1.2.1 - */ - public function testGetInstanceBad() - { - try { - $provider = ActiveRecordProviderFactory::getInstance('Alpha\Model\ActiveRecordProviderDoesNotExist', new Person()); - $this->fail('testing the getInstance() method with bad parameters'); - } catch (IllegalArguementException $e) { - $this->assertEquals('The class [Alpha\Model\ActiveRecordProviderDoesNotExist] is not defined anywhere!', $e->getMessage(), 'testing the getInstance() method with bad parameters'); - } - - try { - $provider = ActiveRecordProviderFactory::getInstance('Alpha\Model\ActiveRecordProviderFactory', new Person()); - $this->fail('testing the getInstance() method with bad parameters'); - } catch (IllegalArguementException $e) { - $this->assertEquals('The class [Alpha\Model\ActiveRecordProviderFactory] does not implement the expected ActiveRecordProviderInterface interface!', $e->getMessage(), 'testing the getInstance() method with bad parameters'); - } - } -} diff --git a/test/Alpha/Test/Model/ActiveRecordTest.php b/test/Alpha/Test/Model/ActiveRecordTest.php index f4a86614..21da15fc 100644 --- a/test/Alpha/Test/Model/ActiveRecordTest.php +++ b/test/Alpha/Test/Model/ActiveRecordTest.php @@ -19,7 +19,7 @@ use Alpha\Exception\AlphaException; use Alpha\Exception\PHPException; use Alpha\Util\Config\ConfigProvider; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; /** * Test case for the ActiveRecord class. @@ -170,7 +170,7 @@ public function testDefaultHouseKeepingValues($provider) $this->person->save(); $sessionProvider = $config->get('session.provider.name'); - $session = SessionProviderFactory::getInstance($sessionProvider); + $session = ServiceFactory::getInstance($sessionProvider, 'Alpha\Util\Http\Session\SessionProviderInterface'); $session->set('currentUser', $this->person); $request = new BadRequest(); diff --git a/test/Alpha/Test/Util/Cache/CacheProviderTest.php b/test/Alpha/Test/Util/Cache/CacheProviderTest.php index 4c4f7888..0babbdcc 100644 --- a/test/Alpha/Test/Util/Cache/CacheProviderTest.php +++ b/test/Alpha/Test/Util/Cache/CacheProviderTest.php @@ -2,7 +2,7 @@ namespace Alpha\Test\Util\Cache; -use Alpha\Util\Cache\CacheProviderFactory; +use Alpha\Util\Service\ServiceFactory; /** * Test cases for the CacheProviderInterface implementations. @@ -73,7 +73,7 @@ public function getCacheProviders() */ public function testSetGetDelete($provider) { - $cache = CacheProviderFactory::getInstance($provider); + $cache = ServiceFactory::getInstance($provider, 'Alpha\Util\Cache\CacheProviderInterface'); $cached = array('value' => 5); diff --git a/test/Alpha/Test/Util/Code/Highlight/HighlightProviderTest.php b/test/Alpha/Test/Util/Code/Highlight/HighlightProviderTest.php index 38bf6140..f0d20d70 100644 --- a/test/Alpha/Test/Util/Code/Highlight/HighlightProviderTest.php +++ b/test/Alpha/Test/Util/Code/Highlight/HighlightProviderTest.php @@ -2,7 +2,7 @@ namespace Alpha\Test\Util\Code\Highlight; -use Alpha\Util\Code\Highlight\HighlightProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Util\Helper\Validator; /** @@ -72,7 +72,7 @@ public function getHighlightProviders() */ public function testHighlight($provider) { - $highlighter = HighlightProviderFactory::getInstance($provider); + $highlighter = ServiceFactory::getInstance($provider, 'Alpha\Util\Code\Highlight\HighlightProviderInterface'); $code = ''; diff --git a/test/Alpha/Test/Util/Http/Session/SessionProviderInterfaceTest.php b/test/Alpha/Test/Util/Http/Session/SessionProviderInterfaceTest.php index 2a25a7f8..8b9ae5e2 100644 --- a/test/Alpha/Test/Util/Http/Session/SessionProviderInterfaceTest.php +++ b/test/Alpha/Test/Util/Http/Session/SessionProviderInterfaceTest.php @@ -2,7 +2,7 @@ namespace Alpha\Test\Util\Http\Session; -use Alpha\Util\Http\Session\SessionProviderFactory; +use Alpha\Util\Service\ServiceFactory; /** * Test case for the session providers. @@ -98,15 +98,15 @@ public function testInit($provider) $this->assertEquals('stillhere', $provider->get('itisstillthere'), 'Testing values survive re-initialization of session'); - $provider = SessionProviderFactory::getInstance(get_class($provider)); + $provider = ServiceFactory::getInstance(get_class($provider), 'Alpha\Util\Http\Session\SessionProviderInterface'); $this->assertEquals('stillhere', $provider->get('itisstillthere'), 'Testing values survive re-initialization of session'); } public function getProviders() { - $arrayProvider = SessionProviderFactory::getInstance('Alpha\Util\Http\Session\SessionProviderArray'); - $PHPSessionProvider = SessionProviderFactory::getInstance('Alpha\Util\Http\Session\SessionProviderPHP'); + $arrayProvider = ServiceFactory::getInstance('Alpha\Util\Http\Session\SessionProviderArray', 'Alpha\Util\Http\Session\SessionProviderInterface'); + $PHPSessionProvider = ServiceFactory::getInstance('Alpha\Util\Http\Session\SessionProviderPHP', 'Alpha\Util\Http\Session\SessionProviderInterface'); return array( array($arrayProvider), diff --git a/test/Alpha/Test/Util/Search/SearchProviderTagsTest.php b/test/Alpha/Test/Util/Search/SearchProviderTagsTest.php index 12962104..8ba710d4 100644 --- a/test/Alpha/Test/Util/Search/SearchProviderTagsTest.php +++ b/test/Alpha/Test/Util/Search/SearchProviderTagsTest.php @@ -7,7 +7,7 @@ use Alpha\Model\Type\DEnum; use Alpha\Model\Type\DEnumItem; use Alpha\Model\ActiveRecord; -use Alpha\Util\Search\SearchProviderFactory; +use Alpha\Util\Service\ServiceFactory; use Alpha\Util\Config\ConfigProvider; /** @@ -150,7 +150,7 @@ public function testIndex() $tag->dropTable(); $tag->rebuildTable(); - $provider = SearchProviderFactory::getInstance('Alpha\Util\Search\SearchProviderTags'); + $provider = ServiceFactory::getInstance('Alpha\Util\Search\SearchProviderTags', 'Alpha\Util\Search\SearchProviderInterface'); $provider->index($this->article); $tags = $this->article->getPropObject('tags')->getRelatedObjects(); @@ -177,7 +177,7 @@ public function testDelete() $this->assertTrue(count($tags) > 0, 'Confirming that tags exist after saving the article (ArticleObject::after_save_callback())'); - $provider = SearchProviderFactory::getInstance('Alpha\Util\Search\SearchProviderTags'); + $provider = ServiceFactory::getInstance('Alpha\Util\Search\SearchProviderTags', 'Alpha\Util\Search\SearchProviderInterface'); $provider->delete($this->article); $tags = $this->article->getPropObject('tags')->getRelatedObjects(); @@ -194,7 +194,7 @@ public function testSearch() { $this->article->save(); - $provider = SearchProviderFactory::getInstance('Alpha\Util\Search\SearchProviderTags'); + $provider = ServiceFactory::getInstance('Alpha\Util\Search\SearchProviderTags', 'Alpha\Util\Search\SearchProviderInterface'); $results = $provider->search('unitTestArticle'); $this->assertTrue(count($results) == 1, 'Testing the search method for expected results'); @@ -214,7 +214,7 @@ public function testGetNumberFound() { $this->article->save(); - $provider = SearchProviderFactory::getInstance('Alpha\Util\Search\SearchProviderTags'); + $provider = ServiceFactory::getInstance('Alpha\Util\Search\SearchProviderTags', 'Alpha\Util\Search\SearchProviderInterface'); $results = $provider->search('unitTestArticle'); $this->assertTrue($provider->getNumberFound() == 1, 'Testing the method for getting the expected number of results'); @@ -245,7 +245,7 @@ public function testGetRelated() $article3 = $this->createArticle('unitTestArticle 3'); $article3->save(); - $provider = SearchProviderFactory::getInstance('Alpha\Util\Search\SearchProviderTags'); + $provider = ServiceFactory::getInstance('Alpha\Util\Search\SearchProviderTags', 'Alpha\Util\Search\SearchProviderInterface'); $results = $provider->getRelated($this->article); $this->assertTrue(count($results) == 2, 'Testing the method for getting related objects'); diff --git a/test/coverage.txt b/test/coverage.txt deleted file mode 100644 index ae61302a..00000000 --- a/test/coverage.txt +++ /dev/null @@ -1,190 +0,0 @@ - - -Code Coverage Report: - 2015-06-23 08:02:08 - - Summary: - Classes: 29.70% (30/101) - Methods: 52.73% (386/732) - Lines: 67.51% (5850/8666) - -\Alpha\Controller::ArticleController - Methods: 30.00% ( 3/10) Lines: 69.34% (285/411) -\Alpha\Controller::AttachmentController - Methods: 50.00% ( 1/ 2) Lines: 77.42% ( 24/ 31) -\Alpha\Controller::CacheController - Methods: 75.00% ( 3/ 4) Lines: 79.69% ( 51/ 64) -\Alpha\Controller::Controller - Methods: 50.91% (28/55) Lines: 71.46% (378/529) -\Alpha\Controller::CreateController - Methods: 50.00% ( 2/ 4) Lines: 74.65% ( 53/ 71) -\Alpha\Controller::DEnumController - Methods: 40.00% ( 2/ 5) Lines: 58.33% ( 70/120) -\Alpha\Controller::EditController - Methods: 25.00% ( 1/ 4) Lines: 66.35% ( 69/104) -\Alpha\Controller::ExcelController - Methods: 50.00% ( 1/ 2) Lines: 62.00% ( 31/ 50) -\Alpha\Controller::FeedController - Methods: 66.67% ( 2/ 3) Lines: 91.94% ( 57/ 62) -\Alpha\Controller::GenSecureQueryStringController - Methods: 100.00% ( 5/ 5) Lines: 100.00% ( 41/ 41) -\Alpha\Controller::ImageController - Methods: 50.00% ( 1/ 2) Lines: 76.92% ( 40/ 52) -\Alpha\Controller::ListActiveRecordsController - Methods: 60.00% ( 3/ 5) Lines: 27.00% ( 27/100) -\Alpha\Controller::ListController - Methods: 37.50% ( 3/ 8) Lines: 69.64% (117/168) -\Alpha\Controller::LogController - Methods: 66.67% ( 2/ 3) Lines: 85.29% ( 29/ 34) -\Alpha\Controller::LoginController - Methods: 60.00% ( 3/ 5) Lines: 88.89% ( 96/108) -\Alpha\Controller::LogoutController - Methods: 50.00% ( 1/ 2) Lines: 96.67% ( 29/ 30) -\Alpha\Controller::MetricController - Methods: 100.00% ( 3/ 3) Lines: 100.00% ( 18/ 18) -\Alpha\Controller::RecordSelectorController - Methods: 50.00% ( 1/ 2) Lines: 89.80% ( 44/ 49) -\Alpha\Controller::SearchController - Methods: 30.00% ( 3/10) Lines: 62.61% ( 72/115) -\Alpha\Controller::SequenceController - Methods: 66.67% ( 2/ 3) Lines: 93.33% ( 28/ 30) -\Alpha\Controller::TagController - Methods: 25.00% ( 1/ 4) Lines: 53.37% ( 95/178) -\Alpha\Controller::ViewController - Methods: 40.00% ( 2/ 5) Lines: 78.22% ( 79/101) -\Alpha\Controller\Front::FrontController - Methods: 62.50% (10/16) Lines: 80.34% (143/178) -\Alpha\Exception::AlphaException - Methods: 100.00% ( 2/ 2) Lines: 100.00% ( 4/ 4) -\Alpha\Model::ActionLog - Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 6/ 6) -\Alpha\Model::ActiveRecord - Methods: 63.10% (53/84) Lines: 82.15% (704/857) -\Alpha\Model::ActiveRecordProviderFactory - Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 12/ 12) -\Alpha\Model::ActiveRecordProviderSQLite - Methods: 19.51% ( 8/41) Lines: 68.45% (753/1100) -\Alpha\Model::Article - Methods: 35.29% ( 6/17) Lines: 67.57% (100/148) -\Alpha\Model::ArticleComment - Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 10/ 10) -\Alpha\Model::ArticleVote - Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 14/ 14) -\Alpha\Model::BadRequest - Methods: 50.00% ( 1/ 2) Lines: 40.00% ( 8/ 20) -\Alpha\Model::BlacklistedClient - Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 5/ 5) -\Alpha\Model::BlacklistedIP - Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 5/ 5) -\Alpha\Model::Person - Methods: 66.67% ( 8/12) Lines: 85.25% (104/122) -\Alpha\Model::Rights - Methods: 100.00% ( 6/ 6) Lines: 100.00% ( 22/ 22) -\Alpha\Model::Tag - Methods: 50.00% ( 4/ 8) Lines: 66.67% ( 52/ 78) -\Alpha\Model\Type::Boolean - Methods: 100.00% ( 5/ 5) Lines: 100.00% ( 23/ 23) -\Alpha\Model\Type::DEnum - Methods: 41.67% ( 5/12) Lines: 87.30% ( 55/ 63) -\Alpha\Model\Type::DEnumItem - Methods: 42.86% ( 3/ 7) Lines: 83.33% ( 25/ 30) -\Alpha\Model\Type::Date - Methods: 42.86% ( 6/14) Lines: 79.27% ( 65/ 82) -\Alpha\Model\Type::Double - Methods: 42.86% ( 3/ 7) Lines: 80.00% ( 20/ 25) -\Alpha\Model\Type::Enum - Methods: 80.00% ( 4/ 5) Lines: 93.75% ( 15/ 16) -\Alpha\Model\Type::Integer - Methods: 71.43% ( 5/ 7) Lines: 92.00% ( 23/ 25) -\Alpha\Model\Type::Relation - Methods: 45.45% (10/22) Lines: 74.27% (127/171) -\Alpha\Model\Type::RelationLookup - Methods: 36.36% ( 4/11) Lines: 69.12% ( 47/ 68) -\Alpha\Model\Type::Sequence - Methods: 33.33% ( 3/ 9) Lines: 81.08% ( 30/ 37) -\Alpha\Model\Type::String - Methods: 70.00% ( 7/10) Lines: 79.49% ( 31/ 39) -\Alpha\Model\Type::Text - Methods: 55.56% ( 5/ 9) Lines: 83.33% ( 25/ 30) -\Alpha\Model\Type::Timestamp - Methods: 56.52% (13/23) Lines: 62.03% (116/187) -\Alpha\Model\Type::Type - Methods: 100.00% ( 3/ 3) Lines: 100.00% ( 4/ 4) -\Alpha\Util::ErrorHandlers - Methods: 50.00% ( 1/ 2) Lines: 57.14% ( 4/ 7) -\Alpha\Util::InputFilter - Methods: 0.00% ( 0/ 2) Lines: 27.27% ( 3/ 11) -\Alpha\Util\Cache::CacheProviderArray - Methods: 100.00% ( 4/ 4) Lines: 100.00% ( 13/ 13) -\Alpha\Util\Cache::CacheProviderFactory - Methods: 0.00% ( 0/ 1) Lines: 90.00% ( 9/ 10) -\Alpha\Util\Code\Metric::Inspector - Methods: 100.00% ( 4/ 4) Lines: 100.00% ( 60/ 60) -\Alpha\Util\Config::ConfigProvider - Methods: 42.86% ( 3/ 7) Lines: 12.99% ( 10/ 77) -\Alpha\Util\Convertor::ActiveRecord2Excel - Methods: 50.00% ( 1/ 2) Lines: 97.14% ( 34/ 35) -\Alpha\Util\Extension::MarkdownFacade - Methods: 50.00% ( 3/ 6) Lines: 46.75% ( 36/ 77) -\Alpha\Util\Extension::TCPDFFacade - Methods: 22.22% ( 2/ 9) Lines: 13.68% ( 16/117) -\Alpha\Util\Feed::Atom - Methods: 100.00% ( 4/ 4) Lines: 100.00% ( 21/ 21) -\Alpha\Util\Feed::Feed - Methods: 55.56% ( 5/ 9) Lines: 94.05% ( 79/ 84) -\Alpha\Util\Feed::RSS - Methods: 100.00% ( 3/ 3) Lines: 100.00% ( 16/ 16) -\Alpha\Util\Feed::RSS2 - Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 3/ 3) -\Alpha\Util\File::FileUtils - Methods: 20.00% ( 1/ 5) Lines: 28.75% ( 23/ 80) -\Alpha\Util\Helper::Validator - Methods: 100.00% (10/10) Lines: 100.00% ( 35/ 35) -\Alpha\Util\Http::AgentUtils - Methods: 100.00% ( 1/ 1) Lines: 100.00% ( 7/ 7) -\Alpha\Util\Http::PHPServerUtils - Methods: 33.33% ( 1/ 3) Lines: 55.00% ( 22/ 40) -\Alpha\Util\Http::Request - Methods: 50.00% (12/24) Lines: 86.92% ( 93/107) -\Alpha\Util\Http::Response - Methods: 80.00% (12/15) Lines: 75.00% ( 33/ 44) -\Alpha\Util\Http\Filter::ClientBlacklistFilter - Methods: 50.00% ( 1/ 2) Lines: 15.38% ( 2/ 13) -\Alpha\Util\Http\Session::SessionProviderArray - Methods: 100.00% ( 7/ 7) Lines: 100.00% ( 18/ 18) -\Alpha\Util\Http\Session::SessionProviderFactory - Methods: 0.00% ( 0/ 1) Lines: 90.91% ( 10/ 11) -\Alpha\Util\Http\Session::SessionProviderPHP - Methods: 71.43% ( 5/ 7) Lines: 72.00% ( 18/ 25) -\Alpha\Util\Logging::KPI - Methods: 50.00% ( 2/ 4) Lines: 77.78% ( 28/ 36) -\Alpha\Util\Logging::LogFile - Methods: 57.14% ( 4/ 7) Lines: 68.67% ( 57/ 83) -\Alpha\Util\Logging::Logger - Methods: 30.00% ( 3/10) Lines: 46.48% ( 33/ 71) -\Alpha\Util\Search::SearchProviderFactory - Methods: 0.00% ( 0/ 1) Lines: 90.91% ( 10/ 11) -\Alpha\Util\Search::SearchProviderTags - Methods: 50.00% ( 4/ 8) Lines: 63.50% ( 87/137) -\Alpha\Util\Security::SecurityUtils - Methods: 100.00% ( 2/ 2) Lines: 100.00% ( 12/ 12) -\Alpha\View::ArticleView - Methods: 40.00% ( 2/ 5) Lines: 92.75% ( 64/ 69) -\Alpha\View::DEnumView - Methods: 50.00% ( 1/ 2) Lines: 94.44% ( 68/ 72) -\Alpha\View::PersonView - Methods: 33.33% ( 1/ 3) Lines: 30.43% ( 21/ 69) -\Alpha\View::View - Methods: 53.57% (15/28) Lines: 74.32% (191/257) -\Alpha\View\Renderer::RendererProviderFactory - Methods: 0.00% ( 0/ 1) Lines: 89.47% ( 17/ 19) -\Alpha\View\Renderer\Html::RendererProviderHTML - Methods: 41.67% (10/24) Lines: 46.21% (250/541) -\Alpha\View\Widget::Button - Methods: 50.00% ( 1/ 2) Lines: 75.86% ( 22/ 29) -\Alpha\View\Widget::Image - Methods: 55.56% ( 5/ 9) Lines: 34.78% ( 40/115) -\Alpha\View\Widget::RecordSelector - Methods: 33.33% ( 1/ 3) Lines: 40.58% ( 84/207) -\Alpha\View\Widget::StringBox - Methods: 25.00% ( 1/ 4) Lines: 75.00% ( 18/ 24)