Skip to content
Snippets Groups Projects
Commit f347a1c6 authored by mtrojan-ub's avatar mtrojan-ub Committed by Demian Katz
Browse files

Improved inheritance for generic controller factory (using static namespace) (#1055)

parent 57695825
No related merge requests found
...@@ -40,45 +40,8 @@ use Zend\ServiceManager\ServiceManager; ...@@ -40,45 +40,8 @@ use Zend\ServiceManager\ServiceManager;
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class Factory class Factory extends GenericFactory
{ {
/**
* Construct a generic controller.
*
* @param string $name Name of table to construct (fully qualified
* class name, or else a class name within the current namespace)
* @param ServiceManager $sm Service manager
*
* @return object
*/
public static function getGenericController($name, ServiceManager $sm)
{
// Prepend the current namespace unless we receive a FQCN:
$class = (strpos($name, '\\') === false)
? __NAMESPACE__ . '\\' . $name : $name;
if (!class_exists($class)) {
throw new \Exception('Cannot construct ' . $class);
}
return new $class($sm->getServiceLocator());
}
/**
* Construct a generic controller.
*
* @param string $name Method name being called
* @param array $args Method arguments
*
* @return object
*/
public static function __callStatic($name, $args)
{
// Strip "get" from method name to get name of class; pass first argument
// on assumption that it should be the ServiceManager object.
return static::getGenericController(
substr($name, 3), isset($args[0]) ? $args[0] : null
);
}
/** /**
* Construct the BrowseController. * Construct the BrowseController.
* *
......
<?php
/**
* Generic factory for controllers (contains generic default behavior shared
* across VuFind's modules).
*
* PHP version 5
*
* Copyright (C) Villanova University 2017.
*
* 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 Controller
* @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 VuFind\Controller;
use Zend\ServiceManager\ServiceManager;
/**
* Generic factory for controllers (contains generic default behavior shared
* across VuFind's modules).
*
* @category VuFind
* @package Controller
* @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
*
* @codeCoverageIgnore
*/
class GenericFactory
{
/**
* Construct a generic controller.
*
* @param string $name Name of table to construct (fully qualified
* class name, or else a class name within the current namespace)
* @param ServiceManager $sm Service manager
*
* @return object
*/
public static function getGenericController($name, ServiceManager $sm)
{
// Prepend the current (inherited) namespace unless we receive a FQCN:
$class = (strpos($name, '\\') === false)
? substr(static::class, 0, strrpos(static::class, '\\') + 1) . $name
: $name;
if (!class_exists($class)) {
throw new \Exception('Cannot construct ' . $class);
}
return new $class($sm->getServiceLocator());
}
/**
* Construct a generic controller.
*
* @param string $name Method name being called
* @param array $args Method arguments
*
* @return object
*/
public static function __callStatic($name, $args)
{
// Strip "get" from method name to get name of class; pass first argument
// on assumption that it should be the ServiceManager object.
return static::getGenericController(
substr($name, 3), isset($args[0]) ? $args[0] : null
);
}
}
...@@ -40,42 +40,6 @@ use Zend\ServiceManager\ServiceManager; ...@@ -40,42 +40,6 @@ use Zend\ServiceManager\ServiceManager;
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class Factory class Factory extends \VuFind\Controller\GenericFactory
{ {
/**
* Construct a generic controller.
*
* @param string $name Name of table to construct (fully qualified
* class name, or else a class name within the current namespace)
* @param ServiceManager $sm Service manager
*
* @return object
*/
public static function getGenericController($name, ServiceManager $sm)
{
// Prepend the current namespace unless we receive a FQCN:
$class = (strpos($name, '\\') === false)
? __NAMESPACE__ . '\\' . $name : $name;
if (!class_exists($class)) {
throw new \Exception('Cannot construct ' . $class);
}
return new $class($sm->getServiceLocator());
}
/**
* Construct a generic controller.
*
* @param string $name Method name being called
* @param array $args Method arguments
*
* @return object
*/
public static function __callStatic($name, $args)
{
// Strip "get" from method name to get name of class; pass first argument
// on assumption that it should be the ServiceManager object.
return static::getGenericController(
substr($name, 3), isset($args[0]) ? $args[0] : null
);
}
} }
...@@ -40,42 +40,6 @@ use Zend\ServiceManager\ServiceManager; ...@@ -40,42 +40,6 @@ use Zend\ServiceManager\ServiceManager;
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class Factory class Factory extends \VuFind\Controller\GenericFactory
{ {
/**
* Construct a generic controller.
*
* @param string $name Name of table to construct (fully qualified
* class name, or else a class name within the current namespace)
* @param ServiceManager $sm Service manager
*
* @return object
*/
public static function getGenericController($name, ServiceManager $sm)
{
// Prepend the current namespace unless we receive a FQCN:
$class = (strpos($name, '\\') === false)
? __NAMESPACE__ . '\\' . $name : $name;
if (!class_exists($class)) {
throw new \Exception('Cannot construct ' . $class);
}
return new $class($sm->getServiceLocator());
}
/**
* Construct a generic controller.
*
* @param string $name Method name being called
* @param array $args Method arguments
*
* @return object
*/
public static function __callStatic($name, $args)
{
// Strip "get" from method name to get name of class; pass first argument
// on assumption that it should be the ServiceManager object.
return static::getGenericController(
substr($name, 3), isset($args[0]) ? $args[0] : null
);
}
} }
...@@ -40,42 +40,6 @@ use Zend\ServiceManager\ServiceManager; ...@@ -40,42 +40,6 @@ use Zend\ServiceManager\ServiceManager;
* *
* @codeCoverageIgnore * @codeCoverageIgnore
*/ */
class Factory class Factory extends \VuFind\Controller\GenericFactory
{ {
/**
* Construct a generic controller.
*
* @param string $name Name of table to construct (fully qualified
* class name, or else a class name within the current namespace)
* @param ServiceManager $sm Service manager
*
* @return object
*/
public static function getGenericController($name, ServiceManager $sm)
{
// Prepend the current namespace unless we receive a FQCN:
$class = (strpos($name, '\\') === false)
? __NAMESPACE__ . '\\' . $name : $name;
if (!class_exists($class)) {
throw new \Exception('Cannot construct ' . $class);
}
return new $class($sm->getServiceLocator());
}
/**
* Construct a generic controller.
*
* @param string $name Method name being called
* @param array $args Method arguments
*
* @return object
*/
public static function __callStatic($name, $args)
{
// Strip "get" from method name to get name of class; pass first argument
// on assumption that it should be the ServiceManager object.
return static::getGenericController(
substr($name, 3), isset($args[0]) ? $args[0] : null
);
}
} }
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