Skip to content
Snippets Groups Projects
Commit bc52e742 authored by Demian Katz's avatar Demian Katz Committed by Robert Lange
Browse files

Eliminate static factories in VuFindTheme Module.php.

parent 3c1b8077
No related merge requests found
......@@ -27,7 +27,7 @@
*/
namespace VuFindTheme;
use Zend\ServiceManager\ServiceManager;
use Zend\ServiceManager\Factory\InvokableFactory;
/**
* ZF2 module definition for the VuFind theme system.
......@@ -65,17 +65,12 @@ class Module
{
return [
'factories' => [
'VuFindTheme\MixinGenerator' =>
'VuFindTheme\Module::getMixinGenerator',
'VuFindTheme\Mobile' =>
'Zend\ServiceManager\Factory\InvokableFactory',
'VuFindTheme\ResourceContainer' =>
'Zend\ServiceManager\Factory\InvokableFactory',
'VuFindTheme\ThemeCompiler' =>
'VuFindTheme\Module::getThemeCompiler',
'VuFindTheme\ThemeGenerator' =>
'VuFindTheme\Module::getThemeGenerator',
'VuFindTheme\ThemeInfo' => 'VuFindTheme\Module::getThemeInfo',
MixinGenerator::class => ThemeInfoInjectorFactory::class,
Mobile::class => InvokableFactory::class,
ResourceContainer::class => InvokableFactory::class,
ThemeCompiler::class => ThemeInfoInjectorFactory::class,
ThemeGenerator::class => ThemeInfoInjectorFactory::class,
ThemeInfo::class => ThemeInfoFactory::class,
],
];
}
......@@ -106,50 +101,4 @@ class Module
],
];
}
/**
* Factory function for MixinGenerator object.
*
* @param ServiceManager $sm Service manager
*
* @return MixinGenerator
*/
public static function getMixinGenerator(ServiceManager $sm)
{
return new MixinGenerator($sm->get('VuFindTheme\ThemeInfo'));
}
/**
* Factory function for ThemeCompiler object.
*
* @param ServiceManager $sm Service manager
*
* @return ThemeCompiler
*/
public static function getThemeCompiler(ServiceManager $sm)
{
return new ThemeCompiler($sm->get('VuFindTheme\ThemeInfo'));
}
/**
* Factory function for ThemeGenerator object.
*
* @param ServiceManager $sm Service manager
*
* @return ThemeGenerator
*/
public static function getThemeGenerator(ServiceManager $sm)
{
return new ThemeGenerator($sm->get('VuFindTheme\ThemeInfo'));
}
/**
* Factory function for ThemeInfo object.
*
* @return ThemeInfo
*/
public static function getThemeInfo()
{
return new ThemeInfo(realpath(APPLICATION_PATH . '/themes'), 'bootprint3');
}
}
<?php
/**
* ThemeInfo factory.
*
* PHP version 7
*
* Copyright (C) Villanova University 2010.
*
* 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 Theme
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Site
*/
namespace VuFindTheme;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;
/**
* ThemeInfo factory.
*
* @category VuFind
* @package Theme
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Site
*/
class ThemeInfoFactory 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.');
}
return new $requestedName(
realpath(APPLICATION_PATH . '/themes'), 'bootprint3'
);
}
}
<?php
/**
* Factory for objects that depend on the ThemeInfo object.
*
* PHP version 7
*
* Copyright (C) Villanova University 2010.
*
* 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 Theme
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Site
*/
namespace VuFindTheme;
use Interop\Container\ContainerInterface;
use Zend\ServiceManager\Factory\FactoryInterface;
/**
* Factory for objects that depend on the ThemeInfo object.
*
* @category VuFind
* @package Theme
* @author Demian Katz <demian.katz@villanova.edu>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org Main Site
*/
class ThemeInfoInjectorFactory 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.');
}
return new $requestedName($container->get(ThemeInfo::class));
}
}
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