Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Eliminate controllers' dependency on ServiceLocatorAwareInterface.
  • Loading branch information
demiankatz committed Feb 27, 2017
1 parent d8d697f commit 07dbedb
Show file tree
Hide file tree
Showing 68 changed files with 691 additions and 317 deletions.
74 changes: 36 additions & 38 deletions module/VuFind/config/module.config.php
Expand Up @@ -105,51 +105,49 @@
],
'controllers' => [
'factories' => [
'ajax' => 'VuFind\Controller\Factory::getAjaxController',
'alphabrowse' => 'VuFind\Controller\Factory::getAlphabrowseController',
'author' => 'VuFind\Controller\Factory::getAuthorController',
'authority' => 'VuFind\Controller\Factory::getAuthorityController',
'browse' => 'VuFind\Controller\Factory::getBrowseController',
'cart' => 'VuFind\Controller\Factory::getCartController',
'collection' => 'VuFind\Controller\Factory::getCollectionController',
'collections' => 'VuFind\Controller\Factory::getCollectionsController',
'combined' => 'VuFind\Controller\Factory::getCombinedController',
'confirm' => 'VuFind\Controller\Factory::getConfirmController',
'content' => 'VuFind\Controller\Factory::getContentController',
'cover' => 'VuFind\Controller\Factory::getCoverController',
'eds' => 'VuFind\Controller\Factory::getEdsController',
'edsrecord' => 'VuFind\Controller\Factory::getEdsrecordController',
'eit' => 'VuFind\Controller\Factory::getEITController',
'eitrecord' => '\VuFind\Controller\Factory::getEITrecordController',
'error' => 'VuFind\Controller\Factory::getErrorController',
'externalauth' => 'VuFind\Controller\Factory::getExternalAuthController',
'feedback' => 'VuFind\Controller\Factory::getFeedbackController',
'help' => 'VuFind\Controller\Factory::getHelpController',
'hierarchy' => 'VuFind\Controller\Factory::getHierarchyController',
'index' => 'VuFind\Controller\Factory::getIndexController',
'install' => 'VuFind\Controller\Factory::getInstallController',
'libguides' => 'VuFind\Controller\Factory::getLibGuidesController',
'librarycards' => 'VuFind\Controller\Factory::getLibraryCardsController',
'missingrecord' => 'VuFind\Controller\Factory::getMissingrecordController',
'my-research' => 'VuFind\Controller\Factory::getMyResearchController',
'oai' => 'VuFind\Controller\Factory::getOaiController',
'pazpar2' => 'VuFind\Controller\Factory::getPazpar2Controller',
'primo' => 'VuFind\Controller\Factory::getPrimoController',
'primorecord' => 'VuFind\Controller\Factory::getPrimorecordController',
'qrcode' => 'VuFind\Controller\Factory::getQRCodeController',
'record' => 'VuFind\Controller\Factory::getRecordController',
'records' => 'VuFind\Controller\Factory::getRecordsController',
'search' => 'VuFind\Controller\Factory::getSearchController',
'shibbolethlogoutnotification' => 'VuFind\Controller\Factory::getShibbolethLogoutNotificationController',
'summon' => 'VuFind\Controller\Factory::getSummonController',
'summonrecord' => 'VuFind\Controller\Factory::getSummonrecordController',
'tag' => 'VuFind\Controller\Factory::getTagController',
'upgrade' => 'VuFind\Controller\Factory::getUpgradeController',
],
'invokables' => [
'ajax' => 'VuFind\Controller\AjaxController',
'alphabrowse' => 'VuFind\Controller\AlphabrowseController',
'author' => 'VuFind\Controller\AuthorController',
'authority' => 'VuFind\Controller\AuthorityController',
'combined' => 'VuFind\Controller\CombinedController',
'confirm' => 'VuFind\Controller\ConfirmController',
'content' => 'VuFind\Controller\ContentController',
'cover' => 'VuFind\Controller\CoverController',
'eds' => 'VuFind\Controller\EdsController',
'edsrecord' => 'VuFind\Controller\EdsrecordController',
'eit' => 'VuFind\Controller\EITController',
'eitrecord' => '\VuFind\Controller\EITrecordController',
'error' => 'VuFind\Controller\ErrorController',
'externalauth' => 'VuFind\Controller\ExternalAuthController',
'feedback' => 'VuFind\Controller\FeedbackController',
'help' => 'VuFind\Controller\HelpController',
'hierarchy' => 'VuFind\Controller\HierarchyController',
'install' => 'VuFind\Controller\InstallController',
'libguides' => 'VuFind\Controller\LibGuidesController',
'librarycards' => 'VuFind\Controller\LibraryCardsController',
'missingrecord' => 'VuFind\Controller\MissingrecordController',
'my-research' => 'VuFind\Controller\MyResearchController',
'oai' => 'VuFind\Controller\OaiController',
'pazpar2' => 'VuFind\Controller\Pazpar2Controller',
'primo' => 'VuFind\Controller\PrimoController',
'primorecord' => 'VuFind\Controller\PrimorecordController',
'qrcode' => 'VuFind\Controller\QRCodeController',
'records' => 'VuFind\Controller\RecordsController',
'search' => 'VuFind\Controller\SearchController',
'shibbolethlogoutnotification' => 'VuFind\Controller\ShibbolethLogoutNotificationController',
'summon' => 'VuFind\Controller\SummonController',
'summonrecord' => 'VuFind\Controller\SummonrecordController',
'tag' => 'VuFind\Controller\TagController',
'web' => 'VuFind\Controller\WebController',
'worldcat' => 'VuFind\Controller\WorldcatController',
'worldcatrecord' => 'VuFind\Controller\WorldcatrecordController',
'web' => 'VuFind\Controller\Factory::getWebController',
'worldcat' => 'VuFind\Controller\Factory::getWorldcatController',
'worldcatrecord' => 'VuFind\Controller\Factory::getWorldcatrecordController',
],
],
'controller_plugins' => [
Expand Down
54 changes: 28 additions & 26 deletions module/VuFind/src/VuFind/Controller/AbstractBase.php
Expand Up @@ -32,6 +32,7 @@
VuFind\Exception\ILS as ILSException,
Zend\Mvc\Controller\AbstractActionController,
Zend\Mvc\MvcEvent,
Zend\ServiceManager\ServiceLocatorInterface,
Zend\View\Model\ViewModel,
ZfcRbac\Service\AuthorizationServiceAwareInterface,
ZfcRbac\Service\AuthorizationServiceAwareTrait;
Expand Down Expand Up @@ -65,6 +66,16 @@ class AbstractBase extends AbstractActionController
*/
protected $accessDeniedBehavior = 'promptLogin';

/**
* Constructor
*
* @param ServiceLocatorInterface $sm Service locator
*/
public function __construct(ServiceLocatorInterface $sm)
{
$this->setServiceLocator($sm);
}

/**
* Use preDispatch event to block access when appropriate.
*
Expand Down Expand Up @@ -105,15 +116,6 @@ protected function attachDefaultListeners()
}
}

/**
* Constructor
*/
public function __construct()
{
// Placeholder so child classes can call parent::__construct() in case
// of future global behavior.
}

/**
* Create a new ViewModel.
*
Expand Down Expand Up @@ -145,7 +147,7 @@ protected function createEmailViewModel($params = null, $defaultSubject = null)
$view = $this->createViewModel($params);

// Load configuration and current user for convenience:
$config = $this->getServiceLocator()->get('VuFind\Config')->get('config');
$config = $this->serviceLocator->get('VuFind\Config')->get('config');
$view->disableFrom
= (isset($config->Mail->disable_from) && $config->Mail->disable_from);
$view->editableSubject = isset($config->Mail->user_editable_subjects)
Expand Down Expand Up @@ -209,7 +211,7 @@ protected function createEmailViewModel($params = null, $defaultSubject = null)
*/
protected function getAuthManager()
{
return $this->getServiceLocator()->get('VuFind\AuthManager');
return $this->serviceLocator->get('VuFind\AuthManager');
}

/**
Expand All @@ -221,7 +223,7 @@ protected function getAuthManager()
*/
protected function getAuthorizationService()
{
return $this->getServiceLocator()
return $this->serviceLocator
->get('ZfcRbac\Service\AuthorizationService');
}

Expand All @@ -232,7 +234,7 @@ protected function getAuthorizationService()
*/
protected function getILSAuthenticator()
{
return $this->getServiceLocator()->get('VuFind\ILSAuthenticator');
return $this->serviceLocator->get('VuFind\ILSAuthenticator');
}

/**
Expand All @@ -252,7 +254,7 @@ protected function getUser()
*/
protected function getViewRenderer()
{
return $this->getServiceLocator()->get('ViewRenderer');
return $this->serviceLocator->get('ViewRenderer');
}

/**
Expand Down Expand Up @@ -358,7 +360,7 @@ protected function catalogLogin()
*/
public function getConfig($id = 'config')
{
return $this->getServiceLocator()->get('VuFind\Config')->get($id);
return $this->serviceLocator->get('VuFind\Config')->get($id);
}

/**
Expand All @@ -368,7 +370,7 @@ public function getConfig($id = 'config')
*/
public function getILS()
{
return $this->getServiceLocator()->get('VuFind\ILSConnection');
return $this->serviceLocator->get('VuFind\ILSConnection');
}

/**
Expand All @@ -378,7 +380,7 @@ public function getILS()
*/
public function getRecordLoader()
{
return $this->getServiceLocator()->get('VuFind\RecordLoader');
return $this->serviceLocator->get('VuFind\RecordLoader');
}

/**
Expand All @@ -388,7 +390,7 @@ public function getRecordLoader()
*/
public function getRecordCache()
{
return $this->getServiceLocator()->get('VuFind\RecordCache');
return $this->serviceLocator->get('VuFind\RecordCache');
}

/**
Expand All @@ -398,7 +400,7 @@ public function getRecordCache()
*/
public function getRecordRouter()
{
return $this->getServiceLocator()->get('VuFind\RecordRouter');
return $this->serviceLocator->get('VuFind\RecordRouter');
}

/**
Expand All @@ -410,7 +412,7 @@ public function getRecordRouter()
*/
public function getTable($table)
{
return $this->getServiceLocator()->get('VuFind\DbTablePluginManager')
return $this->serviceLocator->get('VuFind\DbTablePluginManager')
->get($table);
}

Expand Down Expand Up @@ -521,7 +523,7 @@ public function confirm($title, $yesTarget, $noTarget, $messages = [],
*/
protected function disableSessionWrites()
{
$this->getServiceLocator()->get('VuFind\Session\Settings')->disableWrite();
$this->serviceLocator->get('VuFind\Session\Settings')->disableWrite();
}

/**
Expand All @@ -531,7 +533,7 @@ protected function disableSessionWrites()
*/
public function getSearchMemory()
{
return $this->getServiceLocator()->get('VuFind\Search\Memory');
return $this->serviceLocator->get('VuFind\Search\Memory');
}

/**
Expand All @@ -541,7 +543,7 @@ public function getSearchMemory()
*/
protected function commentsEnabled()
{
$check = $this->getServiceLocator()->get('VuFind\AccountCapabilities');
$check = $this->serviceLocator->get('VuFind\AccountCapabilities');
return $check->getCommentSetting() !== 'disabled';
}

Expand All @@ -552,7 +554,7 @@ protected function commentsEnabled()
*/
protected function listsEnabled()
{
$check = $this->getServiceLocator()->get('VuFind\AccountCapabilities');
$check = $this->serviceLocator->get('VuFind\AccountCapabilities');
return $check->getListSetting() !== 'disabled';
}

Expand All @@ -563,7 +565,7 @@ protected function listsEnabled()
*/
protected function tagsEnabled()
{
$check = $this->getServiceLocator()->get('VuFind\AccountCapabilities');
$check = $this->serviceLocator->get('VuFind\AccountCapabilities');
return $check->getTagSetting() !== 'disabled';
}

Expand Down Expand Up @@ -654,7 +656,7 @@ protected function clearFollowupUrl()
*/
protected function getRecordTabConfig()
{
$cfg = $this->getServiceLocator()->get('Config');
$cfg = $this->serviceLocator->get('Config');
return $cfg['vufind']['recorddriver_tabs'];
}
}
16 changes: 8 additions & 8 deletions module/VuFind/src/VuFind/Controller/AbstractRecord.php
Expand Up @@ -197,7 +197,7 @@ public function addtagAction()

// Save tags, if any:
if ($tags = $this->params()->fromPost('tag')) {
$tagParser = $this->getServiceLocator()->get('VuFind\Tags');
$tagParser = $this->serviceLocator->get('VuFind\Tags');
$driver->addTags($user, $tagParser->parse($tags));
$this->flashMessenger()
->addMessage(['msg' => 'add_tag_success'], 'success');
Expand Down Expand Up @@ -286,10 +286,10 @@ protected function processSave()
// Perform the save operation:
$driver = $this->loadRecord();
$post = $this->getRequest()->getPost()->toArray();
$tagParser = $this->getServiceLocator()->get('VuFind\Tags');
$tagParser = $this->serviceLocator->get('VuFind\Tags');
$post['mytags']
= $tagParser->parse(isset($post['mytags']) ? $post['mytags'] : '');
$favorites = $this->getServiceLocator()
$favorites = $this->serviceLocator
->get('VuFind\Favorites\FavoritesService');
$results = $favorites->save($post, $user, $driver);

Expand Down Expand Up @@ -408,7 +408,7 @@ public function emailAction()
$driver = $this->loadRecord();

// Create view
$mailer = $this->getServiceLocator()->get('VuFind\Mailer');
$mailer = $this->serviceLocator->get('VuFind\Mailer');
$view = $this->createEmailViewModel(
null, $mailer->getDefaultRecordSubject($driver)
);
Expand Down Expand Up @@ -445,7 +445,7 @@ public function emailAction()
*/
protected function smsEnabled()
{
$check = $this->getServiceLocator()->get('VuFind\AccountCapabilities');
$check = $this->serviceLocator->get('VuFind\AccountCapabilities');
return $check->getSmsSetting() !== 'disabled';
}

Expand All @@ -465,7 +465,7 @@ public function smsAction()
$driver = $this->loadRecord();

// Load the SMS carrier list:
$sms = $this->getServiceLocator()->get('VuFind\SMS');
$sms = $this->serviceLocator->get('VuFind\SMS');
$view = $this->createViewModel();
$view->carriers = $sms->getCarriers();
$view->validation = $sms->getValidationType();
Expand Down Expand Up @@ -520,7 +520,7 @@ public function exportAction()
$format = $this->params()->fromQuery('style');

// Display export menu if missing/invalid option
$export = $this->getServiceLocator()->get('VuFind\Export');
$export = $this->serviceLocator->get('VuFind\Export');
if (empty($format) || !$export->recordSupportsFormat($driver, $format)) {
if (!empty($format)) {
$this->flashMessenger()
Expand Down Expand Up @@ -630,7 +630,7 @@ protected function loadTabDetails()
{
$driver = $this->loadRecord();
$request = $this->getRequest();
$rtpm = $this->getServiceLocator()->get('VuFind\RecordTabPluginManager');
$rtpm = $this->serviceLocator->get('VuFind\RecordTabPluginManager');
$details = $rtpm->getTabDetailsForRecord(
$driver, $this->getRecordTabConfig(), $request,
$this->fallbackDefaultTab
Expand Down

0 comments on commit 07dbedb

Please sign in to comment.