Skip to content
Snippets Groups Projects
Commit 1972e574 authored by Ere Maijala's avatar Ere Maijala Committed by Demian Katz
Browse files

Set up formatters as services.

parent f8fde6bf
No related merge requests found
...@@ -12,6 +12,13 @@ $config = [ ...@@ -12,6 +12,13 @@ $config = [
'SearchApi' => 'VuFindApi\Controller\SearchApiController', 'SearchApi' => 'VuFindApi\Controller\SearchApiController',
], ],
], ],
'service_manager' => [
'allow_override' => true,
'factories' => [
'VuFindApi\Formatter\FacetFormatter' => 'Zend\ServiceManager\Factory\InvokableFactory',
'VuFindApi\Formatter\RecordFormatter' => 'VuFindApi\Formatter\RecordFormatterFactory',
],
],
'router' => [ 'router' => [
'routes' => [ 'routes' => [
'apiHome' => [ 'apiHome' => [
......
...@@ -28,7 +28,6 @@ ...@@ -28,7 +28,6 @@
namespace VuFindApi\Controller; namespace VuFindApi\Controller;
use VuFindApi\Formatter\FacetFormatter; use VuFindApi\Formatter\FacetFormatter;
use VuFindApi\Formatter\RecordFormatter;
use Zend\ServiceManager\ServiceManager; use Zend\ServiceManager\ServiceManager;
/** /**
...@@ -67,11 +66,10 @@ class Factory ...@@ -67,11 +66,10 @@ class Factory
*/ */
public static function getSearchApiController(ServiceManager $sm) public static function getSearchApiController(ServiceManager $sm)
{ {
$recordFields = $sm->get('VuFind\Config\YamlReader') return new SearchApiController(
->get('SearchApiRecordFields.yaml'); $sm,
$helperManager = $sm->get('ViewHelperManager'); $sm->get('VuFindApi\Formatter\RecordFormatter'),
$rf = new RecordFormatter($recordFields, $helperManager); $sm->get('VuFindApi\Formatter\FacetFormatter')
$controller = new SearchApiController($sm, $rf, new FacetFormatter()); );
return $controller;
} }
} }
<?php
/**
* Record Formatter factory.
*
* PHP version 7
*
* Copyright (C) Villanova University 2018.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package API_Formatter
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
namespace VuFindApi\Formatter;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;
/**
* Record Formatter factory.
*
* @category VuFind
* @package API_Formatter
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development Wiki
*/
class RecordFormatterFactory implements FactoryInterface
{
/**
* Create an object
*
* @param ContainerInterface $container Service manager
* @param string $requestedName Service being created
* @param null|array $options Extra options (optional)
*
* @return object
*
* @throws ServiceNotFoundException if unable to resolve the service.
* @throws ServiceNotCreatedException if an exception is raised when
* creating a service.
* @throws ContainerException if any other error occurs
*/
public function __invoke(ContainerInterface $container, $requestedName,
array $options = null
) {
if (!empty($options)) {
throw new \Exception('Unexpected options sent to factory.');
}
$recordFields = $container->get('VuFind\Config\YamlReader')
->get('SearchApiRecordFields.yaml');
$helperManager = $container->get('ViewHelperManager');
return new $requestedName($recordFields, $helperManager);
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment