<commit_before><?php
/**
 * @package modules.webservices.lib.services
 */
class webservices_ModuleService extends ModuleBaseService
{
	/**
	 * @var webservices_ModuleService
	 */
	private static $instance = null;

	/**
	 * @return webservices_ModuleService
	 */
	public static function getInstance()
	{
		if (is_null(self::$instance))
		{
			self::$instance = self::getServiceClassInstance(get_class());
		}
		return self::$instance;
	}

	/**
	 * Return the content of WSDL
	 * @param string $className
	 * @return string
	 */
	function getWsdl($className)
	{
		return f_util_FileUtils::read($this->getWsdlPath($className));
	}

	/**
	 * Return the file path of cached WSDL
	 * @param string $className
	 * @return string
	 */
	function getWsdlPath($className)
	{
		$path = f_util_FileUtils::buildChangeBuildPath("wsdl", str_replace("_", DIRECTORY_SEPARATOR, $className) . ".wsdl");
		if (Framework::inDevelopmentMode())
		{
			$wsdl = $this->generateWsdl($className);
			f_util_FileUtils::writeAndCreateContainer($path, $wsdl, f_util_FileUtils::OVERRIDE);
		}
		return $path;
	}
	
	/**
	 * Compile all WSLD defined in the configuration
	 */
	function compileWsdls()
	{
		$wss = webservices_WsService::getInstance()->createQuery()->find();
		foreach ($wss as $ws) 
		{
			$this->compileWsdl($ws->getPhpclass());
		}
	}
	
	/**
	 * @param string $className
	 */
	function compileWsdl($className)
	{
		Framework::info(__METHOD__ . " " . $className);
		$path = f_util_FileUtils::buildChangeBuildPath("wsdl", str_replace("_", DIRECTORY_SEPARATOR, $className) . ".wsdl");
		$wsdl = $this->generateWsdl($className);
		f_util_FileUtils::writeAndCreateContainer($path, $wsdl, f_util_FileUtils::OVERRIDE);
	}

	/**
	 * Return the content on generated WSDL
	 * @param string $className
	 * @return string
	 */
	public function generateWsdl($className)
	{
		$class = new ReflectionClass($className);
		if (!$class->implementsInterface("webservices_WebService"))
		{
			throw new Exception("$className does not implement webservices_WebService interface");
		}
		$baseWsdlPath = f_util_FileUtils::buildWebeditPath("modules", "webservices", "wsdefs", "WebServiceBase.wsdl");
		$baseWsdl = f_util_FileUtils::read($baseWsdlPath);

		$classInfo = explode("_", $className);
		$moduleName = $classInfo[0];
		$serviceName = strtolower(f_util_ArrayUtils::lastElement($classInfo));
		if (f_util_StringUtils::endsWith($serviceName, "webservice"))
		{
			$serviceName = substr($serviceName, 0, -10);
		}

		$targetNameSpace = Framework::getBaseUrl()."/ws/".$moduleName."/".$serviceName;
		$baseWsdl = str_replace("TARGET_NAME_SPACE", $targetNameSpace, $baseWsdl);
		$baseWsdl = str_replace("MY_SERVICE", $serviceName, $baseWsdl);
		$baseWsdl = str_replace("MY_MODULE", $moduleName, $baseWsdl);
		$baseWsdl = str_replace("MY_FQDN", Framework::getBaseUrl(), $baseWsdl);

		$wsdl = f_util_DOMUtils::fromString($baseWsdl);
		$wsdl->registerNamespace("tns", $targetNameSpace);
		$wsdl->registerNamespace("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
		//$wsdl->registerNamespace("soapenc", "http://schemas.xmlsoap.org/soap/encoding/");
		$wsdl->registerNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/");
		$wsdl->registerNamespace("xsd", "http://www.w3.org/2001/XMLSchema");

		$bindingElem = $wsdl->findUnique("wsdl:binding");
		$portTypeElem = $wsdl->findUnique("wsdl:portType");
		
		foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method)
		{
			$methodName = $method->getName();<commit_msg>[FIX] bad soap address when class name contains uppercase characters<commit_after><?php
/**
 * @package modules.webservices.lib.services
 */
class webservices_ModuleService extends ModuleBaseService
{
	/**
	 * @var webservices_ModuleService
	 */
	private static $instance = null;

	/**
	 * @return webservices_ModuleService
	 */
	public static function getInstance()
	{
		if (is_null(self::$instance))
		{
			self::$instance = self::getServiceClassInstance(get_class());
		}
		return self::$instance;
	}

	/**
	 * Return the content of WSDL
	 * @param string $className
	 * @return string
	 */
	function getWsdl($className)
	{
		return f_util_FileUtils::read($this->getWsdlPath($className));
	}

	/**
	 * Return the file path of cached WSDL
	 * @param string $className
	 * @return string
	 */
	function getWsdlPath($className)
	{
		$path = f_util_FileUtils::buildChangeBuildPath("wsdl", str_replace("_", DIRECTORY_SEPARATOR, $className) . ".wsdl");
		if (Framework::inDevelopmentMode())
		{
			$wsdl = $this->generateWsdl($className);
			f_util_FileUtils::writeAndCreateContainer($path, $wsdl, f_util_FileUtils::OVERRIDE);
		}
		return $path;
	}
	
	/**
	 * Compile all WSLD defined in the configuration
	 */
	function compileWsdls()
	{
		$wss = webservices_WsService::getInstance()->createQuery()->find();
		foreach ($wss as $ws) 
		{
			$this->compileWsdl($ws->getPhpclass());
		}
	}
	
	/**
	 * @param string $className
	 */
	function compileWsdl($className)
	{
		Framework::info(__METHOD__ . " " . $className);
		$path = f_util_FileUtils::buildChangeBuildPath("wsdl", str_replace("_", DIRECTORY_SEPARATOR, $className) . ".wsdl");
		$wsdl = $this->generateWsdl($className);
		f_util_FileUtils::writeAndCreateContainer($path, $wsdl, f_util_FileUtils::OVERRIDE);
	}

	/**
	 * Return the content on generated WSDL
	 * @param string $className
	 * @return string
	 */
	public function generateWsdl($className)
	{
		$class = new ReflectionClass($className);
		if (!$class->implementsInterface("webservices_WebService"))
		{
			throw new Exception("$className does not implement webservices_WebService interface");
		}
		$baseWsdlPath = f_util_FileUtils::buildWebeditPath("modules", "webservices", "wsdefs", "WebServiceBase.wsdl");
		$baseWsdl = f_util_FileUtils::read($baseWsdlPath);

		$classInfo = explode("_", $className);
		$moduleName = $classInfo[0];
		$serviceName = f_util_ArrayUtils::lastElement($classInfo);
		if (f_util_StringUtils::endsWith($serviceName, "WebService"))
		{
			$serviceName = substr($serviceName, 0, -10);
		}

		$targetNameSpace = Framework::getBaseUrl()."/ws/".$moduleName."/".$serviceName;
		$baseWsdl = str_replace("TARGET_NAME_SPACE", $targetNameSpace, $baseWsdl);
		$baseWsdl = str_replace("MY_SERVICE", $serviceName, $baseWsdl);
		$baseWsdl = str_replace("MY_MODULE", $moduleName, $baseWsdl);
		$baseWsdl = str_replace("MY_FQDN", Framework::getBaseUrl(), $baseWsdl);

		$wsdl = f_util_DOMUtils::fromString($baseWsdl);
		$wsdl->registerNamespace("tns", $targetNameSpace);
		$wsdl->registerNamespace("soap", "http://schemas.xmlsoap.org/wsdl/soap/");
		//$wsdl->registerNamespace("soapenc", "http://schemas.xmlsoap.org/soap/encoding/");
		$wsdl->registerNamespace("wsdl", "http://schemas.xmlsoap.org/wsdl/");
		$wsdl->registerNamespace("xsd", "http://www.w3.org/2001/XMLSchema");

		$bindingElem = $wsdl->findUnique("wsdl:binding");
		$portTypeElem = $wsdl->findUnique("wsdl:portType");
		
		foreach ($class->getMethods(ReflectionMethod::IS_PUBLIC) as $method)
		{
			$methodName = $method->getName();
{'fraction_non_alphanumeric': 0.1638877012968505, 'fraction_numerical': 0.0025651988029072254, 'mean_word_length': 5.391621129326047, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2474956', 'n_tokens_mistral': 2619, 'n_tokens_neox': 2313, 'n_words': 388}