diff --git a/extension.driver.php b/extension.driver.php
index e06777a..60209c8 100755
--- a/extension.driver.php
+++ b/extension.driver.php
@@ -16,8 +16,8 @@ public function getSubscribedDelegates(){
}
public function initFunctionManager($context){
- $Manager = new FunctionManager(&$context);
+ $Manager = new FunctionManager($context);
$Manager->createDelegate();
$Manager->createStream();
}
- }
\ No newline at end of file
+ }
diff --git a/lib/class.exslfunction.php b/lib/class.exslfunction.php
index 7754694..c1e6deb 100644
--- a/lib/class.exslfunction.php
+++ b/lib/class.exslfunction.php
@@ -1,52 +1,67 @@
-fn_name = $strName;
- $this->fn_namespace = $strURI;
- if (!$strHandle) { $this->fn_handle = $strName;} else {$this->fn_handle = $strHandle;}
- }
-
-
- public function getDeclarations($prefix) {
- $strDeclaration = "xmlns:" . $prefix . "='" . $this->fn_namespace ."'";
- $this->fn_declaration = $strDeclaration;
- return $this->fn_declaration;
- }
-
- public function getFunction($prefix) {
- $reflector = new ReflectionMethod($this->fn_name);
- //handle parameters
- $params = $reflector->getParameters();
- $strParams = '';
- $strPassParams = '';
- foreach( $params as $param) {
- $strParams .= '';
- if ($param->isArray()) {
- // function wants a DomDocument (which comes wrapped in an array)
- $strPassParams .= 'exsl:node-set($' . $param->getName() . ")";
- } else {
- $strPassParams .= '$' . $param->getName();
- }
- if ($param != end($params)) {$strPassParams .= ',';}
+ public function __construct($strName, $strURI, $strHandle = null){
+ $this->fn_name = $strName;
+ $this->fn_namespace = $strURI;
+ if( !$strHandle ){
+ $this->fn_handle = $strName;
}
-
- $strFunction = 'fn_handle . '" xmlns:func="http://exslt.org/functions" >'
- . $strParams .
- '
-
-
- ';
-
- $this->fn_xslfunction = $strFunction;
- return $this->fn_xslfunction;
+ else{
+ $this->fn_handle = $strHandle;
+ }
+ }
+
+
+ public function getDeclarations($prefix){
+ $strDeclaration = "xmlns:".$prefix."='".$this->fn_namespace."'";
+ $this->fn_declaration = $strDeclaration;
+ return $this->fn_declaration;
+ }
+
+ public function getFunction($prefix){
+ $reflector = new ReflectionMethod($this->fn_name);
+
+ //handle parameters
+ $params = $reflector->getParameters();
+ $strParams = '';
+ $strPassParams = '';
+
+ foreach($params as $param){
+ $strParams .= '';
+
+ if( $param->isArray() ){
+ // function wants a DomDocument (which comes wrapped in an array)
+ $strPassParams .= 'exsl:node-set($'.$param->getName().")";
+ }
+ else{
+ $strPassParams .= '$'.$param->getName();
+ }
+
+ if( $param != end( $params ) ){
+ $strPassParams .= ',';
+ }
+ }
+
+ $strFunction =
+ 'fn_handle.'" xmlns:func="http://exslt.org/functions">'
+ .$strParams.
+ '
+
+
+ ';
+
+ $this->fn_xslfunction = $strFunction;
+
+ return $this->fn_xslfunction;
+ }
+
}
-
-}
\ No newline at end of file
diff --git a/lib/class.functionmanager.php b/lib/class.functionmanager.php
index 6d6ade5..dadbd23 100644
--- a/lib/class.functionmanager.php
+++ b/lib/class.functionmanager.php
@@ -1,69 +1,74 @@
page = $context['page'];
+ class FunctionManager
+ {
+ private $functions = array();
+ private $page;
- }
-
- public function createDelegate() {
- // Create Delegate
- Symphony::ExtensionManager()->notifyMembers(
- 'ManageEXSLFunctions', '/frontend/', array('manager' => &$this)
+ function __construct($context){
+ $this->page = $context['page'];
+ }
+
+ public function createDelegate(){
+ Symphony::ExtensionManager()->notifyMembers( 'ManageEXSLFunctions', '/frontend/', array(
+ 'manager' => &$this
+ ) );
+ }
+
+
+ public function createStream(){
+ // Register Stream Wrapper
+ stream_wrapper_register( "efm", "XslTemplateLoaderStream" );
+ $exsl = $this->getFunctions();
+ $opts = array(
+ 'efm' => array(
+ 'namespaces' => $exsl['declarations'],
+ 'functions' => $exsl['functions']
+ //'functions' => print_r($exsl)
+ )
);
- }
-
-
- public function createStream() {
- // Register Stream Wrapper
- stream_wrapper_register("efm", "XslTemplateLoaderStream");
- $exsl = $this->getFunctions();
- $opts = array(
- 'efm' => array(
- 'namespaces' => $exsl['declarations'],
- 'functions' => $exsl['functions']
- //'functions' => print_r($exsl)
- )
- );
- $streamContext = stream_context_create($opts);
- libxml_set_streams_context($streamContext);
- }
-
-
- // For use in subscribed delegates
- public function addFunction($strName, $strURI, $strHandle = NULL){
- //Register function with PHP
- $this->page->registerPHPFunction($strName);
-
- //Create a new EXSL function object
- $function = new EXSLFunction($strName, $strURI, $strHandle);
-
- //Add to Manager's function array, which groups by namespace URI
- $this->functions[$strURI][] = $function;
- }
-
- private function getFunctions(){
- $strFunctions = "";
- $strDeclarations = "";
- $i = 0;
- foreach ($this->functions as $namespace){
- $prefix = 'fn' . $i;
- $strDeclarations .= $namespace[0]->getDeclarations($prefix); //Get the declaration from the first EXSL object in the array
- foreach ($namespace as $function){
- $strFunctions .= $function->getFunction($prefix);
+ $streamContext = stream_context_create( $opts );
+
+ libxml_set_streams_context( $streamContext );
+ }
+
+
+ // For use in subscribed delegates
+ public function addFunction($strName, $strURI, $strHandle = null){
+ //Register function with PHP
+ $this->page->registerPHPFunction( $strName );
+
+ //Create a new EXSL function object
+ $function = new EXSLFunction($strName, $strURI, $strHandle);
+
+ //Add to Manager's function array, which groups by namespace URI
+ $this->functions[$strURI][] = $function;
+ }
+
+
+ private function getFunctions(){
+ $strFunctions = "";
+ $strDeclarations = "";
+ $i = 0;
+
+ foreach($this->functions as $namespace){
+ $prefix = 'fn'.$i;
+
+ $strDeclarations .= $namespace[0]->getDeclarations( $prefix ); //Get the declaration from the first EXSL object in the array
+
+ foreach($namespace as $function){
+ $strFunctions .= $function->getFunction( $prefix );
+ }
+
+ $i++;
}
- $i++;
+
+ return array('declarations' => $strDeclarations, 'functions' => $strFunctions);
+
}
- return array ('declarations' => $strDeclarations, 'functions' => $strFunctions);
-
- }
-
-}
\ No newline at end of file
+
+ }
diff --git a/lib/class.functionstream.php b/lib/class.functionstream.php
index f88e143..a556a35 100755
--- a/lib/class.functionstream.php
+++ b/lib/class.functionstream.php
@@ -1,50 +1,50 @@
-context);
- //$output = implode($options);
- $url = parse_url($path);
- switch ($url['host']) {
-
- case "functions":
+context );
+ //$output = implode($options);
+ $url = parse_url( $path );
+ switch( $url['host'] ){
+
+ case "functions":
$this->template = '
'
- . $context_array['efm']['functions'] .'
+ xmlns:php="http://php.net/xsl"
+ '.$context_array['efm']['namespaces'].'
+ extension-element-prefixes="func php" >
+ '.$context_array['efm']['functions'].'
';
- break;
+ break;
+ }
+
+ return true;
}
-
- return true;
- }
- function stream_read($count)
- {
- $ret = substr($this->template, $this->position, $count);
- $this->position += $count;
- return $ret;
- }
- function stream_write($data)
- {
- return 0;
- }
- function url_stat(){
- return array();
-
- }
- function stream_eof()
- {
- return true;
- }
-
-}
+
+ function stream_read($count){
+ $ret = substr( $this->template, $this->position, $count );
+ $this->position += $count;
+ return $ret;
+ }
+
+ function stream_write($data){
+ return 0;
+ }
+
+ function url_stat(){
+ return array();
+ }
+
+ function stream_eof(){
+ return true;
+ }
+
+ }