Skip to content

Commit

Permalink
Documentation nip tuck, fixed ExtensionManager accessor for S2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdunn committed Jun 7, 2012
1 parent 2aadea8 commit 3b9c90a
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 88 deletions.
19 changes: 6 additions & 13 deletions README.markdown
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
#EXSL Function Manager
Version 0.5
# EXSL Function Manager

##Status
This is currently beta.

##Synopsis
## Synopsis
This extension provides a delegate that allows other extensions to register php functions with Symphony's XSLTProcessor object. It also provides a stream to an XSL document that declares these functions using EXSL:function.

##Background
## Background

Symphony 2.0.7 added the capability to register PHP functions for use within XSLT transformations, allowing developers to implement their own functions in a similar fashion as the built-in functions (such as substring(), etc). There are both benefits and pitfalls to this capabilty. One general concern is the increased coupling of XSLT that uses these functions to PHP's XSL implementation. Another related concern is the lack of version control; calling any registered php function uses the php: namespace.

Fortunately EXSL allows for the creation of functions in a custom-defined namespace. The benefit of defining extension function namespaces is that it abstractly attaches the function to its behavior, rather than to its implementation (as you would in the php: namespace). Assuming the behavior you require necessitates creating an extension function, doing it within its own namespace is the most agnostic way to do so.
Fortunately [EXSL](http://exslt.org/) allows for the creation of functions in a custom-defined namespace. The benefit of defining extension function namespaces is that it abstractly attaches the function to its behavior, rather than to its implementation (as you would in the php: namespace). Assuming the behavior you require necessitates creating an extension function, doing it within its own namespace is the most agnostic way to do so.


## Usage
Expand All @@ -35,7 +31,7 @@ If your extension needs to parse XML sent from the XSL transformation, EFM will
### In a Symphony Page
With EXSL Function Manager activated, include the registered functions using the efm stream just as you would an xsl document, in the top level of your XSL:

`<xsl:include href='efm://functions' />`
<xsl:include href='efm://functions' />

XSL authors will need to declare the namespace of every function managed by EFM that they want to call in their XSL document. The prefix they choose is up to them.

Expand All @@ -50,7 +46,4 @@ Simply put, there are probably a lot more ways to abuse this than anything else.
3. **Do** use this to generate views, or initiate behavior using those views, that would otherwise be awkward or impossible within Symphony.
4. **Do** use it for utility functions missing from XSLT 1, providing they are not native PHP functions. If they are native php functions, then use the php: namespace for the function.

The bottom line is that Symphony provides a pretty good MVC structure, and introducing php functions into the XSL transformation stands a good chance of mucking that up.

test

The bottom line is that Symphony provides a pretty good MVC structure, and introducing PHP functions into the XSL transformation stands a good chance of mucking that up.
42 changes: 42 additions & 0 deletions examples/hello_world/extension.driver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
Class extension_hello_world extends Extension{

public function getSubscribedDelegates(){
return array(
// 1. Subscribe to the EXSLT Function Manager's "ManageEXSLFunctions" delegate
array(
'page' => '/frontend/',
'delegate' => 'ManageEXSLFunctions',
'callback' => 'loadhelloworld'
)
);
}

// 2. The delegate callback method. Register your XSLT functions here
public function loadhelloworld($context){

$context['manager']->addFunction(
'extension_hello_world::helloworld', // callback class and static method name
'http://example.com', // namespace of your choosing
'hello' // the function name you'll use in XSLT
);

$context['manager']->addFunction(
'extension_hello_world::hellonode',
'http://example.com',
'hellonode'
);
}

// 3. The functions!
public static function helloworld($name) {
return 'Hello, ' . $name;
}

public static function hellonode( array $name) {
// By type hinting an array, this function is passed a DomDocument wrapped in array.
return $name[0];
}

}

8 changes: 8 additions & 0 deletions examples/hello_world/extension.meta.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<extension id="hello_world" status="experimental" xmlns="http://symphony-cms.com/schemas/extension/1.0">
<name>Hello World</name>
<description>An example use of the EXSLT Function Manager extension.</description>
<releases>
<release version="0.1" date="2012-06-06" min="2.3.0" />
</releases>
</extension>
Original file line number Diff line number Diff line change
@@ -1,28 +1,32 @@


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:function="http://example.com" >
<!-- Note the function declaration above. While the URI is from the function extension, I've made up the prefix 'function' just for use in this doc.-->
xmlns:my_function="http://example.com">
<!--
Note the function declaration above.
While the namespace URI is from the function's extension, I've made up the prefix 'my_function' just for use in this doc.
-->

<xsl:output method="xml"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
omit-xml-declaration="yes"
encoding="UTF-8"
indent="yes" />

<!-- include the stream, this does all sorts of awesome -->
<xsl:include href='efm://functions' />

<xsl:template match="/">

<xsl:variable name='name' select="'I am a boring string.'" />
<xsl:value-of select='function:hello($name)' /><br /><br />
<p><xsl:value-of select='my_function:hello($name)' /></p>


<xsl:variable name='testnode'>
<node>Hello, I'm a node. I've been to PHP and back. Wild stuff.</node>
</xsl:variable>
<xsl:copy-of select='function:hellonode($testnode)' />
<xsl:copy-of select='my_function:hellonode($testnode)' />

</xsl:template>
</xsl:stylesheet>
42 changes: 0 additions & 42 deletions examples/helloworld/extension.driver.php

This file was deleted.

32 changes: 11 additions & 21 deletions extension.driver.php
Original file line number Diff line number Diff line change
@@ -1,33 +1,23 @@
<?php

require_once('lib/class.functionmanager.php');
require_once('lib/class.functionstream.php');

Class extension_EXSL_Function_Manager extends Extension{
public function about(){
return array('name' => 'EXSL Function Manager',
'version' => '0.5',
'release-date' => '',
'author' => array('name' => 'Andrew Shooner',
'website' => 'http://andrewshooner.com',
'email' => 'ashooner@gmail.com')
);
}

public function getSubscribedDelegates(){
return array(
array(
'page' => '/frontend/',
'delegate' => 'FrontendOutputPreGenerate',
'callback' => 'initFunctionManager'
),

);
array(
'page' => '/frontend/',
'delegate' => 'FrontendOutputPreGenerate',
'callback' => 'initFunctionManager'
)
);
}

public function initFunctionManager($context) {

public function initFunctionManager($context){
$Manager = new FunctionManager(&$context);
$Manager->createDelegate();
$Manager->createStream();
}
$Manager->createDelegate();
$Manager->createStream();
}
}
7 changes: 2 additions & 5 deletions lib/class.exslfunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,5 @@ public function getFunction($prefix) {
$this->fn_xslfunction = $strFunction;
return $this->fn_xslfunction;
}


}



}
2 changes: 1 addition & 1 deletion lib/class.functionmanager.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function __construct($context) {
public function createDelegate() {
// Create Delegate

$this->page->ExtensionManager->notifyMembers(
Symphony::ExtensionManager()->notifyMembers(
'ManageEXSLFunctions', '/frontend/', array('manager' => &$this)
);
}
Expand Down

0 comments on commit 3b9c90a

Please sign in to comment.