From 903ae8a581fac1e6917fc3e31d2ad8fb91df80c3 Mon Sep 17 00:00:00 2001 From: ctrlaltca <> Date: Thu, 12 Jul 2012 11:21:01 +0000 Subject: standardize the use of unix eol; use svn properties to enforce native eol --- framework/Web/Services/TJsonService.php | 426 ++++++++++++++++---------------- 1 file changed, 213 insertions(+), 213 deletions(-) (limited to 'framework/Web/Services/TJsonService.php') diff --git a/framework/Web/Services/TJsonService.php b/framework/Web/Services/TJsonService.php index 13710101..b4e87e27 100644 --- a/framework/Web/Services/TJsonService.php +++ b/framework/Web/Services/TJsonService.php @@ -1,213 +1,213 @@ - - * @link http://www.pradosoft.com/ - * @copyright Copyright © 2005-2012 PradoSoft - * @license http://www.pradosoft.com/license/ - * @version $Id$ - * @package System.Web.Services - */ - -/** - * TJsonService class provides to end-users javascript content response in - * JSON format. - * - * TJsonService manages a set of {@link TJsonResponse}, each - * representing specific response with javascript content. - * The service parameter, referring to the ID of the service, specifies - * which javascript content to be provided to end-users. - * - * To use TJsonService, configure it in application configuration as follows, - * - * - * - * - * - * - * where each JSON response is specified via a <json> element. - * Initial property values can be configured in a <json> element. - * - * - * PHP configuration style: - * - * 'services' => array( - * 'get_article' => array( - * 'class' => 'Path.To.JsonResponseClass1', - * 'properties' => array( - * ... - * ) - * ) - * ) - * - * - * To retrieve the JSON content provided by "get_article", use the URL - * index.php?json=get_article - * - * @author Wei Zhuo - * @author Carl G. Mathisen - * @version $Id$ - * @package System.Web.Services - * @since 3.1 - */ -class TJsonService extends TService -{ - /** - * @var array registered services - */ - private $_services=array(); - - /** - * Initializes this module. - * This method is required by the IModule interface. - * @param mixed configuration for this module, can be null - */ - public function init($xml) - { - $this->loadJsonServices($xml); - } - - /** - * Load the service definitions. - * @param mixed configuration for this module, can be null - */ - protected function loadJsonServices($config) - { - if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) - { - if(is_array($config)) - { - foreach($config['json'] as $id => $json) - $this->_services[$id] = $json; - } - } - else - { - foreach($config->getElementsByTagName('json') as $json) - { - if(($id=$json->getAttribute('id'))!==null) - $this->_services[$id]=$json; - else - throw new TConfigurationException('jsonservice_id_required'); - } - } - } - - /** - * Runs the service. - * This method is invoked by application automatically. - */ - public function run() - { - $id=$this->getRequest()->getServiceParameter(); - if(isset($this->_services[$id])) - { - $serviceConfig=$this->_services[$id]; - if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) - { - if(isset($serviceConfig['class'])) - { - $service=Prado::createComponent($serviceConfig['class']); - if($service instanceof TJsonResponse) - { - $properties = isset($serviceConfig['properties'])?$serviceConfig['properties']:array(); - $this->createJsonResponse($service,$properties,$serviceConfig); - } - else - throw new TConfigurationException('jsonservice_response_type_invalid',$id); - } - else - throw new TConfigurationException('jsonservice_class_required',$id); - } - else - { - $properties=$serviceConfig->getAttributes(); - if(($class=$properties->remove('class'))!==null) - { - $service=Prado::createComponent($class); - if($service instanceof TJsonResponse) - $this->createJsonResponse($service,$properties,$serviceConfig); - else - throw new TConfigurationException('jsonservice_response_type_invalid',$id); - } - else - throw new TConfigurationException('jsonservice_class_required',$id); - } - } - else - throw new THttpException(404,'jsonservice_provider_unknown',$id); - } - - /** - * Renders content provided by TJsonResponse::getJsonContent() as - * javascript in JSON format. - */ - protected function createJsonResponse($service,$properties,$config) - { - // init service properties - foreach($properties as $name=>$value) - $service->setSubproperty($name,$value); - $service->init($config); - - //send content if not null - if(($content=$service->getJsonContent())!==null) - { - $response = $this->getResponse(); - $response->setContentType('text/javascript'); - $response->setCharset('UTF-8'); - //send content - $response->write(TJavaScript::jsonEncode($content)); - } - } -} - -/** - * TJsonResponse Class - * - * TJsonResponse is the base class for all JSON response provider classes. - * - * Derived classes must implement {@link getJsonContent()} to return - * an object or literals to be converted to JSON format. The response - * will be empty if the returned content is null. - * - * @author Wei Zhuo - * @version $Id$ - * @package System.Web.Services - * @since 3.1 - */ -abstract class TJsonResponse extends TApplicationComponent -{ - private $_id=''; - - /** - * Initializes the feed. - * @param TXmlElement configurations specified in {@link TJsonService}. - */ - public function init($config) - { - } - - /** - * @return string ID of this response - */ - public function getID() - { - return $this->_id; - } - - /** - * @param string ID of this response - */ - public function setID($value) - { - $this->_id=$value; - } - - /** - * @return object json response content, null to suppress output. - */ - abstract public function getJsonContent(); -} - -?> + + * @link http://www.pradosoft.com/ + * @copyright Copyright © 2005-2012 PradoSoft + * @license http://www.pradosoft.com/license/ + * @version $Id$ + * @package System.Web.Services + */ + +/** + * TJsonService class provides to end-users javascript content response in + * JSON format. + * + * TJsonService manages a set of {@link TJsonResponse}, each + * representing specific response with javascript content. + * The service parameter, referring to the ID of the service, specifies + * which javascript content to be provided to end-users. + * + * To use TJsonService, configure it in application configuration as follows, + * + * + * + * + * + * + * where each JSON response is specified via a <json> element. + * Initial property values can be configured in a <json> element. + * + * + * PHP configuration style: + * + * 'services' => array( + * 'get_article' => array( + * 'class' => 'Path.To.JsonResponseClass1', + * 'properties' => array( + * ... + * ) + * ) + * ) + * + * + * To retrieve the JSON content provided by "get_article", use the URL + * index.php?json=get_article + * + * @author Wei Zhuo + * @author Carl G. Mathisen + * @version $Id$ + * @package System.Web.Services + * @since 3.1 + */ +class TJsonService extends TService +{ + /** + * @var array registered services + */ + private $_services=array(); + + /** + * Initializes this module. + * This method is required by the IModule interface. + * @param mixed configuration for this module, can be null + */ + public function init($xml) + { + $this->loadJsonServices($xml); + } + + /** + * Load the service definitions. + * @param mixed configuration for this module, can be null + */ + protected function loadJsonServices($config) + { + if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) + { + if(is_array($config)) + { + foreach($config['json'] as $id => $json) + $this->_services[$id] = $json; + } + } + else + { + foreach($config->getElementsByTagName('json') as $json) + { + if(($id=$json->getAttribute('id'))!==null) + $this->_services[$id]=$json; + else + throw new TConfigurationException('jsonservice_id_required'); + } + } + } + + /** + * Runs the service. + * This method is invoked by application automatically. + */ + public function run() + { + $id=$this->getRequest()->getServiceParameter(); + if(isset($this->_services[$id])) + { + $serviceConfig=$this->_services[$id]; + if($this->getApplication()->getConfigurationType()==TApplication::CONFIG_TYPE_PHP) + { + if(isset($serviceConfig['class'])) + { + $service=Prado::createComponent($serviceConfig['class']); + if($service instanceof TJsonResponse) + { + $properties = isset($serviceConfig['properties'])?$serviceConfig['properties']:array(); + $this->createJsonResponse($service,$properties,$serviceConfig); + } + else + throw new TConfigurationException('jsonservice_response_type_invalid',$id); + } + else + throw new TConfigurationException('jsonservice_class_required',$id); + } + else + { + $properties=$serviceConfig->getAttributes(); + if(($class=$properties->remove('class'))!==null) + { + $service=Prado::createComponent($class); + if($service instanceof TJsonResponse) + $this->createJsonResponse($service,$properties,$serviceConfig); + else + throw new TConfigurationException('jsonservice_response_type_invalid',$id); + } + else + throw new TConfigurationException('jsonservice_class_required',$id); + } + } + else + throw new THttpException(404,'jsonservice_provider_unknown',$id); + } + + /** + * Renders content provided by TJsonResponse::getJsonContent() as + * javascript in JSON format. + */ + protected function createJsonResponse($service,$properties,$config) + { + // init service properties + foreach($properties as $name=>$value) + $service->setSubproperty($name,$value); + $service->init($config); + + //send content if not null + if(($content=$service->getJsonContent())!==null) + { + $response = $this->getResponse(); + $response->setContentType('text/javascript'); + $response->setCharset('UTF-8'); + //send content + $response->write(TJavaScript::jsonEncode($content)); + } + } +} + +/** + * TJsonResponse Class + * + * TJsonResponse is the base class for all JSON response provider classes. + * + * Derived classes must implement {@link getJsonContent()} to return + * an object or literals to be converted to JSON format. The response + * will be empty if the returned content is null. + * + * @author Wei Zhuo + * @version $Id$ + * @package System.Web.Services + * @since 3.1 + */ +abstract class TJsonResponse extends TApplicationComponent +{ + private $_id=''; + + /** + * Initializes the feed. + * @param TXmlElement configurations specified in {@link TJsonService}. + */ + public function init($config) + { + } + + /** + * @return string ID of this response + */ + public function getID() + { + return $this->_id; + } + + /** + * @param string ID of this response + */ + public function setID($value) + { + $this->_id=$value; + } + + /** + * @return object json response content, null to suppress output. + */ + abstract public function getJsonContent(); +} + +?> -- cgit v1.2.3