Skip to content
Snippets Groups Projects
Commit 9a895c85 authored by Demian Katz's avatar Demian Katz
Browse files

Made XSLT importer custom class handling more flexible (and made the nasty...

Made XSLT importer custom class handling more flexible (and made the nasty class truncation logic optional, so we can start to move away from it).  Updated comments in configuration files to match.
parent fa545f50
No related merge requests found
...@@ -8,11 +8,17 @@ xslt = doaj.xsl ...@@ -8,11 +8,17 @@ xslt = doaj.xsl
; this line to register multiple PHP functions. ; this line to register multiple PHP functions.
;php_function[] = str_replace ;php_function[] = str_replace
; OPTIONAL: PHP class filled with public static functions for use by the XSLT file. ; OPTIONAL: PHP class filled with public static functions for use by the XSLT file.
; The class will be autoloaded using a prefix of VF_XSLT_Import_ (i.e. you need to ; The class must live within a PHP namespace. You may specify a fully-qualified
; define VF_XSLT_Import_VuFind in your library directory); the short name will be ; name; if you do not include a namespace, the class will automatically be assumed
; used from within the XSLT code. You may repeat this line to load multiple custom ; to live in the \VuFind\XSLT\Import namespace.
; classes.
custom_class[] = VuFind custom_class[] = VuFind
; OPTIONAL: If true, all custom_class settings above will be passed to the XSLT with
; their namespaces stripped off; for example, \VuFind\XSLT\Import\VuFind would be
; treated as \VuFind in XSLT files. This allows more compact syntax within XSLT
; files, but it can lead to name conflicts if used carelessly. If set to false, you
; must use fully-qualified names in your XSLT. The false setting is recommended, but
; the current default is "true" for compatibility with legacy configurations.
truncate_custom_class = true
; XSLT parameters -- any key/value pairs set here will be passed as parameters to ; XSLT parameters -- any key/value pairs set here will be passed as parameters to
; the XSLT file, allowing local values to be set without modifying XSLT code. ; the XSLT file, allowing local values to be set without modifying XSLT code.
......
...@@ -7,11 +7,17 @@ xslt = dspace.xsl ...@@ -7,11 +7,17 @@ xslt = dspace.xsl
; this line to register multiple PHP functions. ; this line to register multiple PHP functions.
;php_function[] = str_replace ;php_function[] = str_replace
; OPTIONAL: PHP class filled with public static functions for use by the XSLT file. ; OPTIONAL: PHP class filled with public static functions for use by the XSLT file.
; The class will be autoloaded using a prefix of VF_XSLT_Import_ (i.e. you need to ; The class must live within a PHP namespace. You may specify a fully-qualified
; define VF_XSLT_Import_VuFind in your library directory); the short name will be ; name; if you do not include a namespace, the class will automatically be assumed
; used from within the XSLT code. You may repeat this line to load multiple custom ; to live in the \VuFind\XSLT\Import namespace.
; classes.
custom_class[] = VuFind custom_class[] = VuFind
; OPTIONAL: If true, all custom_class settings above will be passed to the XSLT with
; their namespaces stripped off; for example, \VuFind\XSLT\Import\VuFind would be
; treated as \VuFind in XSLT files. This allows more compact syntax within XSLT
; files, but it can lead to name conflicts if used carelessly. If set to false, you
; must use fully-qualified names in your XSLT. The false setting is recommended, but
; the current default is "true" for compatibility with legacy configurations.
truncate_custom_class = true
; XSLT parameters -- any key/value pairs set here will be passed as parameters to ; XSLT parameters -- any key/value pairs set here will be passed as parameters to
; the XSLT file, allowing local values to be set without modifying XSLT code. ; the XSLT file, allowing local values to be set without modifying XSLT code.
......
...@@ -7,11 +7,17 @@ xslt = gsdl.xsl ...@@ -7,11 +7,17 @@ xslt = gsdl.xsl
; this line to register multiple PHP functions. ; this line to register multiple PHP functions.
;php_function[] = str_replace ;php_function[] = str_replace
; OPTIONAL: PHP class filled with public static functions for use by the XSLT file. ; OPTIONAL: PHP class filled with public static functions for use by the XSLT file.
; The class will be autoloaded using a prefix of VF_XSLT_Import_ (i.e. you need to ; The class must live within a PHP namespace. You may specify a fully-qualified
; define VF_XSLT_Import_VuFind in your library directory); the short name will be ; name; if you do not include a namespace, the class will automatically be assumed
; used from within the XSLT code. You may repeat this line to load multiple custom ; to live in the \VuFind\XSLT\Import namespace.
; classes.
custom_class[] = VuFind custom_class[] = VuFind
; OPTIONAL: If true, all custom_class settings above will be passed to the XSLT with
; their namespaces stripped off; for example, \VuFind\XSLT\Import\VuFind would be
; treated as \VuFind in XSLT files. This allows more compact syntax within XSLT
; files, but it can lead to name conflicts if used carelessly. If set to false, you
; must use fully-qualified names in your XSLT. The false setting is recommended, but
; the current default is "true" for compatibility with legacy configurations.
truncate_custom_class = true
; XSLT parameters -- any key/value pairs set here will be passed as parameters to ; XSLT parameters -- any key/value pairs set here will be passed as parameters to
; the XSLT file, allowing local values to be set without modifying XSLT code. ; the XSLT file, allowing local values to be set without modifying XSLT code.
......
...@@ -7,11 +7,17 @@ xslt = ndltd.xsl ...@@ -7,11 +7,17 @@ xslt = ndltd.xsl
; this line to register multiple PHP functions. ; this line to register multiple PHP functions.
;php_function[] = strtolower ;php_function[] = strtolower
; OPTIONAL: PHP class filled with public static functions for use by the XSLT file. ; OPTIONAL: PHP class filled with public static functions for use by the XSLT file.
; The class will be autoloaded using a prefix of VF_XSLT_Import_ (i.e. you need to ; The class must live within a PHP namespace. You may specify a fully-qualified
; define VF_XSLT_Import_VuFind in your library directory); the short name will be ; name; if you do not include a namespace, the class will automatically be assumed
; used from within the XSLT code. You may repeat this line to load multiple custom ; to live in the \VuFind\XSLT\Import namespace.
; classes.
custom_class[] = VuFind custom_class[] = VuFind
; OPTIONAL: If true, all custom_class settings above will be passed to the XSLT with
; their namespaces stripped off; for example, \VuFind\XSLT\Import\VuFind would be
; treated as \VuFind in XSLT files. This allows more compact syntax within XSLT
; files, but it can lead to name conflicts if used carelessly. If set to false, you
; must use fully-qualified names in your XSLT. The false setting is recommended, but
; the current default is "true" for compatibility with legacy configurations.
truncate_custom_class = true
; XSLT parameters -- any key/value pairs set here will be passed as parameters to ; XSLT parameters -- any key/value pairs set here will be passed as parameters to
; the XSLT file, allowing local values to be set without modifying XSLT code. ; the XSLT file, allowing local values to be set without modifying XSLT code.
......
...@@ -7,11 +7,17 @@ xslt = nlm_ojs.xsl ...@@ -7,11 +7,17 @@ xslt = nlm_ojs.xsl
; this line to register multiple PHP functions. ; this line to register multiple PHP functions.
php_function[] = strtolower php_function[] = strtolower
; OPTIONAL: PHP class filled with public static functions for use by the XSLT file. ; OPTIONAL: PHP class filled with public static functions for use by the XSLT file.
; The class will be autoloaded using a prefix of VF_XSLT_Import_ (i.e. you need to ; The class must live within a PHP namespace. You may specify a fully-qualified
; define VF_XSLT_Import_VuFind in your library directory); the short name will be ; name; if you do not include a namespace, the class will automatically be assumed
; used from within the XSLT code. You may repeat this line to load multiple custom ; to live in the \VuFind\XSLT\Import namespace.
; classes.
custom_class[] = VuFind custom_class[] = VuFind
; OPTIONAL: If true, all custom_class settings above will be passed to the XSLT with
; their namespaces stripped off; for example, \VuFind\XSLT\Import\VuFind would be
; treated as \VuFind in XSLT files. This allows more compact syntax within XSLT
; files, but it can lead to name conflicts if used carelessly. If set to false, you
; must use fully-qualified names in your XSLT. The false setting is recommended, but
; the current default is "true" for compatibility with legacy configurations.
truncate_custom_class = true
; XSLT parameters -- any key/value pairs set here will be passed as parameters to ; XSLT parameters -- any key/value pairs set here will be passed as parameters to
; the XSLT file, allowing local values to be set without modifying XSLT code. ; the XSLT file, allowing local values to be set without modifying XSLT code.
......
...@@ -7,11 +7,17 @@ xslt = ojs.xsl ...@@ -7,11 +7,17 @@ xslt = ojs.xsl
; this line to register multiple PHP functions. ; this line to register multiple PHP functions.
;php_function[] = str_replace ;php_function[] = str_replace
; OPTIONAL: PHP class filled with public static functions for use by the XSLT file. ; OPTIONAL: PHP class filled with public static functions for use by the XSLT file.
; The class will be autoloaded using a prefix of VF_XSLT_Import_ (i.e. you need to ; The class must live within a PHP namespace. You may specify a fully-qualified
; define VF_XSLT_Import_VuFind in your library directory); the short name will be ; name; if you do not include a namespace, the class will automatically be assumed
; used from within the XSLT code. You may repeat this line to load multiple custom ; to live in the \VuFind\XSLT\Import namespace.
; classes.
custom_class[] = VuFind custom_class[] = VuFind
; OPTIONAL: If true, all custom_class settings above will be passed to the XSLT with
; their namespaces stripped off; for example, \VuFind\XSLT\Import\VuFind would be
; treated as \VuFind in XSLT files. This allows more compact syntax within XSLT
; files, but it can lead to name conflicts if used carelessly. If set to false, you
; must use fully-qualified names in your XSLT. The false setting is recommended, but
; the current default is "true" for compatibility with legacy configurations.
truncate_custom_class = true
; XSLT parameters -- any key/value pairs set here will be passed as parameters to ; XSLT parameters -- any key/value pairs set here will be passed as parameters to
; the XSLT file, allowing local values to be set without modifying XSLT code. ; the XSLT file, allowing local values to be set without modifying XSLT code.
......
...@@ -7,11 +7,17 @@ xslt = vudl.xsl ...@@ -7,11 +7,17 @@ xslt = vudl.xsl
; this line to register multiple PHP functions. ; this line to register multiple PHP functions.
;php_function[] = str_replace ;php_function[] = str_replace
; OPTIONAL: PHP class filled with public static functions for use by the XSLT file. ; OPTIONAL: PHP class filled with public static functions for use by the XSLT file.
; The class will be autoloaded using a prefix of VF_XSLT_Import_ (i.e. you need to ; The class must live within a PHP namespace. You may specify a fully-qualified
; define VF_XSLT_Import_VuFind in your library directory); the short name will be ; name; if you do not include a namespace, the class will automatically be assumed
; used from within the XSLT code. You may repeat this line to load multiple custom ; to live in the \VuFind\XSLT\Import namespace.
; classes.
custom_class[] = VuFind custom_class[] = VuFind
; OPTIONAL: If true, all custom_class settings above will be passed to the XSLT with
; their namespaces stripped off; for example, \VuFind\XSLT\Import\VuFind would be
; treated as \VuFind in XSLT files. This allows more compact syntax within XSLT
; files, but it can lead to name conflicts if used carelessly. If set to false, you
; must use fully-qualified names in your XSLT. The false setting is recommended, but
; the current default is "true" for compatibility with legacy configurations.
truncate_custom_class = true
; XSLT parameters -- any key/value pairs set here will be passed as parameters to ; XSLT parameters -- any key/value pairs set here will be passed as parameters to
; the XSLT file, allowing local values to be set without modifying XSLT code. ; the XSLT file, allowing local values to be set without modifying XSLT code.
......
...@@ -157,10 +157,21 @@ class Importer implements ServiceLocatorAwareInterface ...@@ -157,10 +157,21 @@ class Importer implements ServiceLocatorAwareInterface
$classes = is_array($options['General']['custom_class']) $classes = is_array($options['General']['custom_class'])
? $options['General']['custom_class'] ? $options['General']['custom_class']
: array($options['General']['custom_class']); : array($options['General']['custom_class']);
$truncate = isset($options['General']['truncate_custom_class'])
? $options['General']['truncate_custom_class'] : true;
foreach ($classes as $class) { foreach ($classes as $class) {
// Dynamically generate the requested class: // Add a default namespace if none was provided:
$class = preg_replace('/[^A-Za-z0-9_]/', '', $class); if (false === strpos($class, '\\')) {
eval("class $class extends \\VuFind\\XSLT\\Import\\$class { }"); $class = 'VuFind\XSLT\Import\\' . $class;
}
// If necessary, dynamically generate the truncated version of the
// requested class:
if ($truncate) {
$parts = explode('\\', $class);
$class = preg_replace('/[^A-Za-z0-9_]/', '', array_pop($parts));
$ns = implode('\\', $parts);
eval("class $class extends \\$ns\\$class { }");
}
$methods = get_class_methods($class); $methods = get_class_methods($class);
if (method_exists($class, 'setServiceLocator')) { if (method_exists($class, 'setServiceLocator')) {
$class::setServiceLocator($this->getServiceLocator()); $class::setServiceLocator($this->getServiceLocator());
......
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