Commit 422fc0295acbbedff723a6f72bc239ca789003e1
1 parent
f3cec0f2
cleaning up branch
Showing
3 changed files
with
329 additions
and
329 deletions
webservice/classes/soap/WSHelper.class.php
| 1 | -<?php | |
| 2 | -/** | |
| 3 | - * Class that generates a WSDL file and creates documentation | |
| 4 | - * for the webservices. | |
| 5 | - * | |
| 6 | - *@author KnowledgeTree Team | |
| 7 | - *@package Webservice | |
| 8 | - *@version Version 0.9 | |
| 9 | - */ | |
| 10 | -class WSHelper { | |
| 11 | - private $uri; | |
| 12 | - private $class = null; //IPReflectionClass object | |
| 13 | - private $name; //class name | |
| 14 | - private $persistence = SOAP_PERSISTENCE_SESSION; | |
| 15 | - private $wsdlfile; //wsdl file name | |
| 16 | - private $server; //soap server object | |
| 17 | - | |
| 18 | - public $actor; | |
| 19 | - public $structureMap = array(); | |
| 20 | - public $classNameArr = array(); | |
| 21 | - public $wsdlFolder; //WSDL cache folder | |
| 22 | - public $useWSDLCache = true; | |
| 23 | - | |
| 24 | - public $type = SOAP_RPC; | |
| 25 | - public $use = SOAP_LITERAL; | |
| 26 | - | |
| 27 | - /** | |
| 28 | - * Constructor | |
| 29 | - * @param string The Uri name | |
| 30 | - * @return void | |
| 31 | - */ | |
| 32 | - public function __construct($uri, $class=null){ | |
| 33 | - $this->uri = $uri; | |
| 34 | - $this->setWSDLCacheFolder($_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF'])."/wsdl/"); | |
| 35 | - if($class) $this->setClass($class); | |
| 36 | - } | |
| 37 | - | |
| 38 | - /** | |
| 39 | - * Adds the given class name to the list of classes | |
| 40 | - * to be included in the documentation/WSDL/Request handlers | |
| 41 | - * @param string | |
| 42 | - * @return void | |
| 43 | - */ | |
| 44 | - public function setClass($name){ | |
| 45 | - $this->name = $name; | |
| 46 | - $this->wsdlfile = $this->wsdlFolder.$this->name.".wsdl"; | |
| 47 | - } | |
| 48 | - | |
| 49 | - public function setWSDLCacheFolder($folder) { | |
| 50 | - $this->wsdlFolder = $folder; | |
| 51 | - //reset wsdlfile | |
| 52 | - $this->wsdlfile = $this->wsdlFolder.$this->name.".wsdl"; | |
| 53 | - } | |
| 54 | - /** | |
| 55 | - * Sets the persistence level for the soap class | |
| 56 | - */ | |
| 57 | - public function setPersistence($persistence) { | |
| 58 | - $this->persistence = $persistence; | |
| 59 | - } | |
| 60 | - | |
| 61 | - /** | |
| 62 | - * Handles everything. Makes sure the webservice is handled, | |
| 63 | - * documentations is generated, or the wsdl is generated, | |
| 64 | - * according to the page request | |
| 65 | - * @return void | |
| 66 | - */ | |
| 67 | - public function handle(){ | |
| 68 | - if(substr($_SERVER['QUERY_STRING'], -4) == 'wsdl'){ | |
| 69 | - $this->showWSDL(); | |
| 70 | - }elseif(isset($GLOBALS['HTTP_RAW_POST_DATA']) && strlen($GLOBALS['HTTP_RAW_POST_DATA'])>0){ | |
| 71 | - $this->handleRequest(); | |
| 72 | - }else{ | |
| 73 | - $this->createDocumentation(); | |
| 74 | - } | |
| 75 | - } | |
| 76 | - /** | |
| 77 | - * Checks if the current WSDL is up-to-date, regenerates if necessary and outputs the WSDL | |
| 78 | - * @return void | |
| 79 | - */ | |
| 80 | - public function showWSDL(){ | |
| 81 | - //check if it's a legal webservice class | |
| 82 | - if(!in_array($this->name, $this->classNameArr)) | |
| 83 | - throw new Exception("No valid webservice class."); | |
| 84 | - | |
| 85 | - //@TODO: nog een mooie oplossing voor het cachen zoeken | |
| 86 | - header("Content-type: text/xml"); | |
| 87 | - if($this->useWSDLCache && file_exists($this->wsdlfile)){ | |
| 88 | - readfile($this->wsdlfile); | |
| 89 | - }else{ | |
| 90 | - //make sure to refresh PHP WSDL cache system | |
| 91 | - ini_set("soap.wsdl_cache_enabled",0); | |
| 92 | - echo $this->createWSDL(); | |
| 93 | - } | |
| 94 | - } | |
| 95 | - | |
| 96 | - private function createWSDL(){ | |
| 97 | - $this->class = new IPReflectionClass($this->name); | |
| 98 | - $wsdl = new WSDLStruct($this->uri, "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?class=".$this->name, $this->type, $this->use); | |
| 99 | - $wsdl->setService($this->class); | |
| 100 | - | |
| 101 | - try { | |
| 102 | - $gendoc = $wsdl->generateDocument(); | |
| 103 | - } catch (WSDLException $exception) { | |
| 104 | - $exception->Display(); | |
| 105 | - exit(); | |
| 106 | - } | |
| 107 | - | |
| 108 | - $fh = fopen($this->wsdlfile, "w+"); | |
| 109 | - fwrite($fh, $gendoc); | |
| 110 | - fclose($fh); | |
| 111 | - | |
| 112 | - return $gendoc; | |
| 113 | - } | |
| 114 | - | |
| 115 | - /** | |
| 116 | - * Lets the native PHP5 soap implementation handle the request | |
| 117 | - * after registrating the class | |
| 118 | - * @return void | |
| 119 | - */ | |
| 120 | - private function handleRequest(){ | |
| 121 | - //check if it's a legal webservice class | |
| 122 | - if(!in_array($this->name, $this->classNameArr)) | |
| 123 | - throw new Exception("No valid webservice class."); | |
| 124 | - | |
| 125 | - //check cache | |
| 126 | - //if(!file_exists($this->wsdlfile)) | |
| 127 | - $this->createWSDL(); | |
| 128 | - | |
| 129 | - $options = Array('actor' => $this->actor, 'classmap' => $this->structureMap); | |
| 130 | - | |
| 131 | - header("Content-type: text/xml"); | |
| 132 | - $this->server = new SoapServer($this->wsdlfile, $options); | |
| 133 | - $this->server->setClass($this->name); | |
| 134 | - $this->server->setPersistence($this->persistence); | |
| 135 | - | |
| 136 | - use_soap_error_handler(true); | |
| 137 | - $this->server->handle(); | |
| 138 | - } | |
| 139 | - | |
| 140 | - /** | |
| 141 | - * @param string code | |
| 142 | - * @param string string | |
| 143 | - * @param string actor | |
| 144 | - * @param mixed details | |
| 145 | - * @param string name | |
| 146 | - * @return void | |
| 147 | - */ | |
| 148 | - public function fault($code, $string, $actor, $details, $name='') { | |
| 149 | - return $this->server->fault($code, $string, $actor, $details, $name); | |
| 150 | - } | |
| 151 | - | |
| 152 | - /** | |
| 153 | - * Generates the documentations for the webservice usage. | |
| 154 | - * @TODO: "int", "boolean", "double", "float", "string", "void" | |
| 155 | - * @param string Template filename | |
| 156 | - * @return void | |
| 157 | - */ | |
| 158 | - public function createDocumentation($template="classes/soap/templates/docclass.xsl") { | |
| 159 | - if(!is_file($template)) | |
| 160 | - throw new WSException("Could not find the template file: '$template'"); | |
| 161 | - $this->class = new IPReflectionClass($this->name); | |
| 162 | - $xtpl = new IPXSLTemplate($template); | |
| 163 | - $documentation = Array(); | |
| 164 | - $documentation['menu'] = Array(); | |
| 165 | - //loop menu items | |
| 166 | - sort($this->classNameArr); | |
| 167 | - foreach($this->classNameArr as $className) { | |
| 168 | - $documentation['menu'][] = new IPReflectionClass($className); | |
| 169 | - } | |
| 170 | - | |
| 171 | - if($this->class){ | |
| 172 | - $this->class->properties = $this->class->getProperties(false, false); | |
| 173 | - $this->class->methods = $this->class->getMethods(false, false); | |
| 174 | - foreach((array)$this->class->methods as $method) { | |
| 175 | - $method->params = $method->getParameters(); | |
| 176 | - } | |
| 177 | - | |
| 178 | - $documentation['class'] = $this->class; | |
| 179 | - } | |
| 180 | - echo $xtpl->execute($documentation); | |
| 181 | - } | |
| 182 | -} | |
| 1 | +<?php | |
| 2 | +/** | |
| 3 | + * Class that generates a WSDL file and creates documentation | |
| 4 | + * for the webservices. | |
| 5 | + * | |
| 6 | + *@author KnowledgeTree Team | |
| 7 | + *@package Webservice | |
| 8 | + *@version Version 0.9 | |
| 9 | + */ | |
| 10 | +class WSHelper { | |
| 11 | + private $uri; | |
| 12 | + private $class = null; //IPReflectionClass object | |
| 13 | + private $name; //class name | |
| 14 | + private $persistence = SOAP_PERSISTENCE_SESSION; | |
| 15 | + private $wsdlfile; //wsdl file name | |
| 16 | + private $server; //soap server object | |
| 17 | + | |
| 18 | + public $actor; | |
| 19 | + public $structureMap = array(); | |
| 20 | + public $classNameArr = array(); | |
| 21 | + public $wsdlFolder; //WSDL cache folder | |
| 22 | + public $useWSDLCache = true; | |
| 23 | + | |
| 24 | + public $type = SOAP_RPC; | |
| 25 | + public $use = SOAP_LITERAL; | |
| 26 | + | |
| 27 | + /** | |
| 28 | + * Constructor | |
| 29 | + * @param string The Uri name | |
| 30 | + * @return void | |
| 31 | + */ | |
| 32 | + public function __construct($uri, $class=null){ | |
| 33 | + $this->uri = $uri; | |
| 34 | + $this->setWSDLCacheFolder($_SERVER['DOCUMENT_ROOT'].dirname($_SERVER['PHP_SELF'])."/wsdl/"); | |
| 35 | + if($class) $this->setClass($class); | |
| 36 | + } | |
| 37 | + | |
| 38 | + /** | |
| 39 | + * Adds the given class name to the list of classes | |
| 40 | + * to be included in the documentation/WSDL/Request handlers | |
| 41 | + * @param string | |
| 42 | + * @return void | |
| 43 | + */ | |
| 44 | + public function setClass($name){ | |
| 45 | + $this->name = $name; | |
| 46 | + $this->wsdlfile = $this->wsdlFolder.$this->name.".wsdl"; | |
| 47 | + } | |
| 48 | + | |
| 49 | + public function setWSDLCacheFolder($folder) { | |
| 50 | + $this->wsdlFolder = $folder; | |
| 51 | + //reset wsdlfile | |
| 52 | + $this->wsdlfile = $this->wsdlFolder.$this->name.".wsdl"; | |
| 53 | + } | |
| 54 | + /** | |
| 55 | + * Sets the persistence level for the soap class | |
| 56 | + */ | |
| 57 | + public function setPersistence($persistence) { | |
| 58 | + $this->persistence = $persistence; | |
| 59 | + } | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * Handles everything. Makes sure the webservice is handled, | |
| 63 | + * documentations is generated, or the wsdl is generated, | |
| 64 | + * according to the page request | |
| 65 | + * @return void | |
| 66 | + */ | |
| 67 | + public function handle(){ | |
| 68 | + if(substr($_SERVER['QUERY_STRING'], -4) == 'wsdl'){ | |
| 69 | + $this->showWSDL(); | |
| 70 | + }elseif(isset($GLOBALS['HTTP_RAW_POST_DATA']) && strlen($GLOBALS['HTTP_RAW_POST_DATA'])>0){ | |
| 71 | + $this->handleRequest(); | |
| 72 | + }else{ | |
| 73 | + $this->createDocumentation(); | |
| 74 | + } | |
| 75 | + } | |
| 76 | + /** | |
| 77 | + * Checks if the current WSDL is up-to-date, regenerates if necessary and outputs the WSDL | |
| 78 | + * @return void | |
| 79 | + */ | |
| 80 | + public function showWSDL(){ | |
| 81 | + //check if it's a legal webservice class | |
| 82 | + if(!in_array($this->name, $this->classNameArr)) | |
| 83 | + throw new Exception("No valid webservice class."); | |
| 84 | + | |
| 85 | + //@TODO: nog een mooie oplossing voor het cachen zoeken | |
| 86 | + header("Content-type: text/xml"); | |
| 87 | + if($this->useWSDLCache && file_exists($this->wsdlfile)){ | |
| 88 | + readfile($this->wsdlfile); | |
| 89 | + }else{ | |
| 90 | + //make sure to refresh PHP WSDL cache system | |
| 91 | + ini_set("soap.wsdl_cache_enabled",0); | |
| 92 | + echo $this->createWSDL(); | |
| 93 | + } | |
| 94 | + } | |
| 95 | + | |
| 96 | + private function createWSDL(){ | |
| 97 | + $this->class = new IPReflectionClass($this->name); | |
| 98 | + $wsdl = new WSDLStruct($this->uri, "http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME']."?class=".$this->name, $this->type, $this->use); | |
| 99 | + $wsdl->setService($this->class); | |
| 100 | + | |
| 101 | + try { | |
| 102 | + $gendoc = $wsdl->generateDocument(); | |
| 103 | + } catch (WSDLException $exception) { | |
| 104 | + $exception->Display(); | |
| 105 | + exit(); | |
| 106 | + } | |
| 107 | + | |
| 108 | + $fh = fopen($this->wsdlfile, "w+"); | |
| 109 | + fwrite($fh, $gendoc); | |
| 110 | + fclose($fh); | |
| 111 | + | |
| 112 | + return $gendoc; | |
| 113 | + } | |
| 114 | + | |
| 115 | + /** | |
| 116 | + * Lets the native PHP5 soap implementation handle the request | |
| 117 | + * after registrating the class | |
| 118 | + * @return void | |
| 119 | + */ | |
| 120 | + private function handleRequest(){ | |
| 121 | + //check if it's a legal webservice class | |
| 122 | + if(!in_array($this->name, $this->classNameArr)) | |
| 123 | + throw new Exception("No valid webservice class."); | |
| 124 | + | |
| 125 | + //check cache | |
| 126 | + //if(!file_exists($this->wsdlfile)) | |
| 127 | + $this->createWSDL(); | |
| 128 | + | |
| 129 | + $options = Array('actor' => $this->actor, 'classmap' => $this->structureMap); | |
| 130 | + | |
| 131 | + header("Content-type: text/xml"); | |
| 132 | + $this->server = new SoapServer($this->wsdlfile, $options); | |
| 133 | + $this->server->setClass($this->name); | |
| 134 | + $this->server->setPersistence($this->persistence); | |
| 135 | + | |
| 136 | + use_soap_error_handler(true); | |
| 137 | + $this->server->handle(); | |
| 138 | + } | |
| 139 | + | |
| 140 | + /** | |
| 141 | + * @param string code | |
| 142 | + * @param string string | |
| 143 | + * @param string actor | |
| 144 | + * @param mixed details | |
| 145 | + * @param string name | |
| 146 | + * @return void | |
| 147 | + */ | |
| 148 | + public function fault($code, $string, $actor, $details, $name='') { | |
| 149 | + return $this->server->fault($code, $string, $actor, $details, $name); | |
| 150 | + } | |
| 151 | + | |
| 152 | + /** | |
| 153 | + * Generates the documentations for the webservice usage. | |
| 154 | + * @TODO: "int", "boolean", "double", "float", "string", "void" | |
| 155 | + * @param string Template filename | |
| 156 | + * @return void | |
| 157 | + */ | |
| 158 | + public function createDocumentation($template="classes/soap/templates/docclass.xsl") { | |
| 159 | + if(!is_file($template)) | |
| 160 | + throw new WSException("Could not find the template file: '$template'"); | |
| 161 | + $this->class = new IPReflectionClass($this->name); | |
| 162 | + $xtpl = new IPXSLTemplate($template); | |
| 163 | + $documentation = Array(); | |
| 164 | + $documentation['menu'] = Array(); | |
| 165 | + //loop menu items | |
| 166 | + sort($this->classNameArr); | |
| 167 | + foreach($this->classNameArr as $className) { | |
| 168 | + $documentation['menu'][] = new IPReflectionClass($className); | |
| 169 | + } | |
| 170 | + | |
| 171 | + if($this->class){ | |
| 172 | + $this->class->properties = $this->class->getProperties(false, false); | |
| 173 | + $this->class->methods = $this->class->getMethods(false, false); | |
| 174 | + foreach((array)$this->class->methods as $method) { | |
| 175 | + $method->params = $method->getParameters(); | |
| 176 | + } | |
| 177 | + | |
| 178 | + $documentation['class'] = $this->class; | |
| 179 | + } | |
| 180 | + echo $xtpl->execute($documentation); | |
| 181 | + } | |
| 182 | +} | |
| 183 | 183 | ?> |
| 184 | 184 | \ No newline at end of file | ... | ... |
webservice/classes/soap/templates/str.replace.function.xsl
| 1 | -<?xml version="1.0"?> | |
| 2 | -<xsl:stylesheet version="1.0" | |
| 3 | - xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
| 4 | - xmlns:str="http://exslt.org/strings" | |
| 5 | - xmlns:func="http://exslt.org/functions" | |
| 6 | - xmlns:exsl="http://exslt.org/common" | |
| 7 | - extension-element-prefixes="str exsl func"> | |
| 8 | - | |
| 9 | -<func:function name="str:replace"> | |
| 10 | - <xsl:param name="string" select="''" /> | |
| 11 | - <xsl:param name="search" select="/.." /> | |
| 12 | - <xsl:param name="replace" select="/.." /> | |
| 13 | - <xsl:choose> | |
| 14 | - <xsl:when test="not($string)"> | |
| 15 | - <func:result select="/.." /> | |
| 16 | - </xsl:when> | |
| 17 | - <xsl:when test="function-available('exsl:node-set')"> | |
| 18 | - <!-- this converts the search and replace arguments to node sets | |
| 19 | - if they are one of the other XPath types --> | |
| 20 | - <xsl:variable name="search-nodes-rtf"> | |
| 21 | - <xsl:copy-of select="$search" /> | |
| 22 | - </xsl:variable> | |
| 23 | - <xsl:variable name="replace-nodes-rtf"> | |
| 24 | - <xsl:copy-of select="$replace" /> | |
| 25 | - </xsl:variable> | |
| 26 | - <xsl:variable name="replacements-rtf"> | |
| 27 | - <xsl:for-each select="exsl:node-set($search-nodes-rtf)/node()"> | |
| 28 | - <xsl:variable name="pos" select="position()" /> | |
| 29 | - <replace search="{.}"> | |
| 30 | - <xsl:copy-of select="exsl:node-set($replace-nodes-rtf)/node()[$pos]" /> | |
| 31 | - </replace> | |
| 32 | - </xsl:for-each> | |
| 33 | - </xsl:variable> | |
| 34 | - <xsl:variable name="sorted-replacements-rtf"> | |
| 35 | - <xsl:for-each select="exsl:node-set($replacements-rtf)/replace"> | |
| 36 | - <xsl:sort select="string-length(@search)" data-type="number" order="descending" /> | |
| 37 | - <xsl:copy-of select="." /> | |
| 38 | - </xsl:for-each> | |
| 39 | - </xsl:variable> | |
| 40 | - <xsl:variable name="result"> | |
| 41 | - <xsl:choose> | |
| 42 | - <xsl:when test="not($search)"> | |
| 43 | - <xsl:value-of select="$string" /> | |
| 44 | - </xsl:when> | |
| 45 | - <xsl:otherwise> | |
| 46 | - <xsl:call-template name="str:_replace"> | |
| 47 | - <xsl:with-param name="string" select="$string" /> | |
| 48 | - <xsl:with-param name="replacements" select="exsl:node-set($sorted-replacements-rtf)/replace" /> | |
| 49 | - </xsl:call-template> | |
| 50 | - </xsl:otherwise> | |
| 51 | - </xsl:choose> | |
| 52 | - </xsl:variable> | |
| 53 | - <func:result select="exsl:node-set($result)/node()" /> | |
| 54 | - </xsl:when> | |
| 55 | - <xsl:otherwise> | |
| 56 | - <xsl:message terminate="yes"> | |
| 57 | - ERROR: function implementation of str:replace() relies on exsl:node-set(). | |
| 58 | - </xsl:message> | |
| 59 | - </xsl:otherwise> | |
| 60 | - </xsl:choose> | |
| 61 | -</func:function> | |
| 62 | - | |
| 63 | -<xsl:template name="str:_replace"> | |
| 64 | - <xsl:param name="string" select="''" /> | |
| 65 | - <xsl:param name="replacements" select="/.." /> | |
| 66 | - <xsl:choose> | |
| 67 | - <xsl:when test="not($string)" /> | |
| 68 | - <xsl:when test="not($replacements)"> | |
| 69 | - <xsl:value-of select="$string" /> | |
| 70 | - </xsl:when> | |
| 71 | - <xsl:otherwise> | |
| 72 | - <xsl:variable name="replacement" select="$replacements[1]" /> | |
| 73 | - <xsl:variable name="search" select="$replacement/@search" /> | |
| 74 | - <xsl:choose> | |
| 75 | - <xsl:when test="not(string($search))"> | |
| 76 | - <xsl:value-of select="substring($string, 1, 1)" /> | |
| 77 | - <xsl:copy-of select="$replacement/node()" /> | |
| 78 | - <xsl:call-template name="str:_replace"> | |
| 79 | - <xsl:with-param name="string" select="substring($string, 2)" /> | |
| 80 | - <xsl:with-param name="replacements" select="$replacements" /> | |
| 81 | - </xsl:call-template> | |
| 82 | - </xsl:when> | |
| 83 | - <xsl:when test="contains($string, $search)"> | |
| 84 | - <xsl:call-template name="str:_replace"> | |
| 85 | - <xsl:with-param name="string" select="substring-before($string, $search)" /> | |
| 86 | - <xsl:with-param name="replacements" select="$replacements[position() > 1]" /> | |
| 87 | - </xsl:call-template> | |
| 88 | - <xsl:copy-of select="$replacement/node()" /> | |
| 89 | - <xsl:call-template name="str:_replace"> | |
| 90 | - <xsl:with-param name="string" select="substring-after($string, $search)" /> | |
| 91 | - <xsl:with-param name="replacements" select="$replacements" /> | |
| 92 | - </xsl:call-template> | |
| 93 | - </xsl:when> | |
| 94 | - <xsl:otherwise> | |
| 95 | - <xsl:call-template name="str:_replace"> | |
| 96 | - <xsl:with-param name="string" select="$string" /> | |
| 97 | - <xsl:with-param name="replacements" select="$replacements[position() > 1]" /> | |
| 98 | - </xsl:call-template> | |
| 99 | - </xsl:otherwise> | |
| 100 | - </xsl:choose> | |
| 101 | - </xsl:otherwise> | |
| 102 | - </xsl:choose> | |
| 103 | -</xsl:template> | |
| 104 | - | |
| 1 | +<?xml version="1.0"?> | |
| 2 | +<xsl:stylesheet version="1.0" | |
| 3 | + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
| 4 | + xmlns:str="http://exslt.org/strings" | |
| 5 | + xmlns:func="http://exslt.org/functions" | |
| 6 | + xmlns:exsl="http://exslt.org/common" | |
| 7 | + extension-element-prefixes="str exsl func"> | |
| 8 | + | |
| 9 | +<func:function name="str:replace"> | |
| 10 | + <xsl:param name="string" select="''" /> | |
| 11 | + <xsl:param name="search" select="/.." /> | |
| 12 | + <xsl:param name="replace" select="/.." /> | |
| 13 | + <xsl:choose> | |
| 14 | + <xsl:when test="not($string)"> | |
| 15 | + <func:result select="/.." /> | |
| 16 | + </xsl:when> | |
| 17 | + <xsl:when test="function-available('exsl:node-set')"> | |
| 18 | + <!-- this converts the search and replace arguments to node sets | |
| 19 | + if they are one of the other XPath types --> | |
| 20 | + <xsl:variable name="search-nodes-rtf"> | |
| 21 | + <xsl:copy-of select="$search" /> | |
| 22 | + </xsl:variable> | |
| 23 | + <xsl:variable name="replace-nodes-rtf"> | |
| 24 | + <xsl:copy-of select="$replace" /> | |
| 25 | + </xsl:variable> | |
| 26 | + <xsl:variable name="replacements-rtf"> | |
| 27 | + <xsl:for-each select="exsl:node-set($search-nodes-rtf)/node()"> | |
| 28 | + <xsl:variable name="pos" select="position()" /> | |
| 29 | + <replace search="{.}"> | |
| 30 | + <xsl:copy-of select="exsl:node-set($replace-nodes-rtf)/node()[$pos]" /> | |
| 31 | + </replace> | |
| 32 | + </xsl:for-each> | |
| 33 | + </xsl:variable> | |
| 34 | + <xsl:variable name="sorted-replacements-rtf"> | |
| 35 | + <xsl:for-each select="exsl:node-set($replacements-rtf)/replace"> | |
| 36 | + <xsl:sort select="string-length(@search)" data-type="number" order="descending" /> | |
| 37 | + <xsl:copy-of select="." /> | |
| 38 | + </xsl:for-each> | |
| 39 | + </xsl:variable> | |
| 40 | + <xsl:variable name="result"> | |
| 41 | + <xsl:choose> | |
| 42 | + <xsl:when test="not($search)"> | |
| 43 | + <xsl:value-of select="$string" /> | |
| 44 | + </xsl:when> | |
| 45 | + <xsl:otherwise> | |
| 46 | + <xsl:call-template name="str:_replace"> | |
| 47 | + <xsl:with-param name="string" select="$string" /> | |
| 48 | + <xsl:with-param name="replacements" select="exsl:node-set($sorted-replacements-rtf)/replace" /> | |
| 49 | + </xsl:call-template> | |
| 50 | + </xsl:otherwise> | |
| 51 | + </xsl:choose> | |
| 52 | + </xsl:variable> | |
| 53 | + <func:result select="exsl:node-set($result)/node()" /> | |
| 54 | + </xsl:when> | |
| 55 | + <xsl:otherwise> | |
| 56 | + <xsl:message terminate="yes"> | |
| 57 | + ERROR: function implementation of str:replace() relies on exsl:node-set(). | |
| 58 | + </xsl:message> | |
| 59 | + </xsl:otherwise> | |
| 60 | + </xsl:choose> | |
| 61 | +</func:function> | |
| 62 | + | |
| 63 | +<xsl:template name="str:_replace"> | |
| 64 | + <xsl:param name="string" select="''" /> | |
| 65 | + <xsl:param name="replacements" select="/.." /> | |
| 66 | + <xsl:choose> | |
| 67 | + <xsl:when test="not($string)" /> | |
| 68 | + <xsl:when test="not($replacements)"> | |
| 69 | + <xsl:value-of select="$string" /> | |
| 70 | + </xsl:when> | |
| 71 | + <xsl:otherwise> | |
| 72 | + <xsl:variable name="replacement" select="$replacements[1]" /> | |
| 73 | + <xsl:variable name="search" select="$replacement/@search" /> | |
| 74 | + <xsl:choose> | |
| 75 | + <xsl:when test="not(string($search))"> | |
| 76 | + <xsl:value-of select="substring($string, 1, 1)" /> | |
| 77 | + <xsl:copy-of select="$replacement/node()" /> | |
| 78 | + <xsl:call-template name="str:_replace"> | |
| 79 | + <xsl:with-param name="string" select="substring($string, 2)" /> | |
| 80 | + <xsl:with-param name="replacements" select="$replacements" /> | |
| 81 | + </xsl:call-template> | |
| 82 | + </xsl:when> | |
| 83 | + <xsl:when test="contains($string, $search)"> | |
| 84 | + <xsl:call-template name="str:_replace"> | |
| 85 | + <xsl:with-param name="string" select="substring-before($string, $search)" /> | |
| 86 | + <xsl:with-param name="replacements" select="$replacements[position() > 1]" /> | |
| 87 | + </xsl:call-template> | |
| 88 | + <xsl:copy-of select="$replacement/node()" /> | |
| 89 | + <xsl:call-template name="str:_replace"> | |
| 90 | + <xsl:with-param name="string" select="substring-after($string, $search)" /> | |
| 91 | + <xsl:with-param name="replacements" select="$replacements" /> | |
| 92 | + </xsl:call-template> | |
| 93 | + </xsl:when> | |
| 94 | + <xsl:otherwise> | |
| 95 | + <xsl:call-template name="str:_replace"> | |
| 96 | + <xsl:with-param name="string" select="$string" /> | |
| 97 | + <xsl:with-param name="replacements" select="$replacements[position() > 1]" /> | |
| 98 | + </xsl:call-template> | |
| 99 | + </xsl:otherwise> | |
| 100 | + </xsl:choose> | |
| 101 | + </xsl:otherwise> | |
| 102 | + </xsl:choose> | |
| 103 | +</xsl:template> | |
| 104 | + | |
| 105 | 105 | </xsl:stylesheet> |
| 106 | 106 | \ No newline at end of file | ... | ... |
webservice/tests/annotations.php
| 1 | -<? | |
| 2 | -chdir(".."); | |
| 3 | -include "common.php"; | |
| 4 | - | |
| 5 | -class DefaultController { | |
| 6 | - const TYPE_PLAIN = 1; | |
| 7 | - const TYPE_HTML = 2; | |
| 8 | - public $type; | |
| 9 | - public $length; | |
| 10 | -} | |
| 11 | -/** | |
| 12 | - * @ann1('me'=>'you'); | |
| 13 | - */ | |
| 14 | -class something{ | |
| 15 | - /** | |
| 16 | - * @var string | |
| 17 | - * @Controller(type => DefaultController::TYPE_PLAIN, length => 100) | |
| 18 | - */ | |
| 19 | - public $propertyA; | |
| 20 | - | |
| 21 | - /** | |
| 22 | - * @var string | |
| 23 | - * @Controller(type => DefaultController::TYPE_HTML, length => 100) | |
| 24 | - */ | |
| 25 | - public function methodB () { | |
| 26 | - return "aap"; | |
| 27 | - } | |
| 28 | -} | |
| 29 | - | |
| 30 | -/* Annotation example */ | |
| 31 | -$rel = new IPReflectionClass("something"); | |
| 32 | -$properties = $rel->getProperties(); | |
| 33 | -$methods = $rel->getMethods(); | |
| 34 | - | |
| 35 | -var_dump($rel->getAnnotation("ann1", "stdClass")); | |
| 36 | - | |
| 37 | -$property = $properties["propertyA"]; | |
| 38 | -$ann = $property->getAnnotation("Controller", "DefaultController"); | |
| 39 | -var_dump($ann); | |
| 40 | - | |
| 41 | -$method = $methods["methodB"]; | |
| 42 | -$ann = $method->getAnnotation("Controller", "DefaultController"); | |
| 43 | -var_dump($ann); | |
| 1 | +<? | |
| 2 | +chdir(".."); | |
| 3 | +include "common.php"; | |
| 4 | + | |
| 5 | +class DefaultController { | |
| 6 | + const TYPE_PLAIN = 1; | |
| 7 | + const TYPE_HTML = 2; | |
| 8 | + public $type; | |
| 9 | + public $length; | |
| 10 | +} | |
| 11 | +/** | |
| 12 | + * @ann1('me'=>'you'); | |
| 13 | + */ | |
| 14 | +class something{ | |
| 15 | + /** | |
| 16 | + * @var string | |
| 17 | + * @Controller(type => DefaultController::TYPE_PLAIN, length => 100) | |
| 18 | + */ | |
| 19 | + public $propertyA; | |
| 20 | + | |
| 21 | + /** | |
| 22 | + * @var string | |
| 23 | + * @Controller(type => DefaultController::TYPE_HTML, length => 100) | |
| 24 | + */ | |
| 25 | + public function methodB () { | |
| 26 | + return "aap"; | |
| 27 | + } | |
| 28 | +} | |
| 29 | + | |
| 30 | +/* Annotation example */ | |
| 31 | +$rel = new IPReflectionClass("something"); | |
| 32 | +$properties = $rel->getProperties(); | |
| 33 | +$methods = $rel->getMethods(); | |
| 34 | + | |
| 35 | +var_dump($rel->getAnnotation("ann1", "stdClass")); | |
| 36 | + | |
| 37 | +$property = $properties["propertyA"]; | |
| 38 | +$ann = $property->getAnnotation("Controller", "DefaultController"); | |
| 39 | +var_dump($ann); | |
| 40 | + | |
| 41 | +$method = $methods["methodB"]; | |
| 42 | +$ann = $method->getAnnotation("Controller", "DefaultController"); | |
| 43 | +var_dump($ann); | |
| 44 | 44 | ?> |
| 45 | 45 | \ No newline at end of file | ... | ... |