TXmlDocument represents a DOM representation of an XML file. Besides all properties and methods inherited from {@link TXmlElement}, you can load an XML file or string by {@link loadFromFile} or {@link loadFromString}. You can also get the version and encoding of the XML document by the Version and Encoding properties. To construct an XML string, you may do the following: $doc=new TXmlDocument('1.0','utf-8'); $doc->TagName='Root'; $proc=new TXmlElement('Proc'); $proc->setAttribute('Name','xxxx'); $doc->Elements[]=$proc; $query=new TXmlElement('Query'); $query->setAttribute('ID','xxxx'); $proc->Elements[]=$query; $attr=new TXmlElement('Attr'); $attr->setAttribute('Name','aaa'); $attr->Value='1'; $query->Elements[]=$attr; $attr=new TXmlElement('Attr'); $attr->setAttribute('Name','bbb'); $attr->Value='1'; $query->Elements[]=$attr; The above code represents the following XML string: 1 1
Since: 3.0
Author: Qiang Xue (qiang.xue@gmail.com)
Inheritance: extends TXmlElement
 /**
  * Parses the application configuration file.
  * @param string configuration file name
  * @throws TConfigurationException if there is any parsing error
  */
 public function loadFromFile($fname)
 {
     if (Prado::getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) {
         $fcontent = (include $fname);
         $this->loadFromPhp($fcontent, dirname($fname));
     } else {
         $dom = new TXmlDocument();
         $dom->loadFromFile($fname);
         $this->loadFromXml($dom, dirname($fname));
     }
 }
Exemple #2
0
 public function setUp()
 {
     if (self::$app === null) {
         self::$app = new TApplication(dirname(__FILE__) . '/app');
         prado::setPathofAlias('App', dirname(__FILE__));
     }
     if (self::$mgr === null) {
         $config = new TXmlDocument('1.0', 'utf8');
         $config->loadFromString('<users><user name="Joe" password="******"/><user name="John" password="******" /><role name="Administrator" users="John" /><role name="Writer" users="Joe,John" /></users>');
         self::$mgr = new TUserManager();
         self::$mgr->init($config);
     }
 }
Exemple #3
0
 public function setUp()
 {
     ini_set('session.use_cookies', 0);
     ini_set('session.cache_limiter', 'none');
     if (self::$app === null) {
         self::$app = new TApplication(dirname(__FILE__) . '/app');
     }
     // Make a fake user manager module
     if (self::$usrMgr === null) {
         self::$usrMgr = new TUserManager();
         $config = new TXmlDocument('1.0', 'utf8');
         $config->loadFromString('<users><user name="Joe" password="******"/><user name="John" password="******" /><role name="Administrator" users="John" /><role name="Writer" users="Joe,John" /></users>');
         self::$usrMgr->init($config);
         self::$app->setModule('users', self::$usrMgr);
     }
 }
Exemple #4
0
 public function testSaveToFile()
 {
     $file = dirname(__FILE__) . '/data/tmp.xml';
     if (!is_writable(dirname($file))) {
         self::markTestSkipped(dirname($file) . ' must be writable for this test');
     }
     $xmldoc = new TXmlDocument('1.0', 'utf-8');
     $xmldoc->setTagName('root');
     $node = new TXmlElement('node');
     $node->setAttribute('param', 'attribute1');
     $xmldoc->getElements()->add($node);
     $xmldoc->saveToFile($file);
     self::assertTrue(is_file($file));
     if (is_file($file)) {
         unlink($file);
     }
 }
Exemple #5
0
 /**
  * Initializes this module.
  * This method is required by the IModule interface.
  * @param mixed configuration for this module, can be null
  * @throws TConfigurationException if {@link getConfigFile ConfigFile} is invalid.
  */
 public function init($config)
 {
     if ($this->_configFile !== null) {
         if (is_file($this->_configFile)) {
             if ($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) {
                 $phpConfig = (include $this->_configFile);
                 $this->loadConfig($phpConfig);
             } else {
                 $dom = new TXmlDocument();
                 $dom->loadFromFile($this->_configFile);
                 $this->loadConfig($dom);
             }
         } else {
             throw new TConfigurationException('logrouter_configfile_invalid', $this->_configFile);
         }
     }
     $this->loadConfig($config);
     $this->getApplication()->attachEventHandler('OnEndRequest', array($this, 'collectLogs'));
 }
Exemple #6
0
 /**
  * Initializes the module by loading parameters.
  * @param mixed content enclosed within the module tag
  */
 public function init($config)
 {
     $this->loadParameters($config);
     if ($this->_paramFile !== null) {
         $configFile = null;
         if ($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_XML && ($cache = $this->getApplication()->getCache()) !== null) {
             $cacheKey = 'TParameterModule:' . $this->_paramFile;
             if (($configFile = $cache->get($cacheKey)) === false) {
                 $configFile = new TXmlDocument();
                 $configFile->loadFromFile($this->_paramFile);
                 $cache->set($cacheKey, $configFile, 0, new TFileCacheDependency($this->_paramFile));
             }
         } else {
             if ($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) {
                 $configFile = (include $this->_paramFile);
             } else {
                 $configFile = new TXmlDocument();
                 $configFile->loadFromFile($this->_paramFile);
             }
         }
         $this->loadParameters($configFile);
     }
     $this->_initialized = true;
 }
Exemple #7
0
 /**
  * Initializes this module.
  * This method is required by the IModule interface.
  * @param TXmlElement configuration for this module, can be null
  * @throws TConfigurationException if {@link getConfigFile ConfigFile} is invalid.
  */
 public function init($config)
 {
     if ($this->_configFile !== null) {
         if (is_file($this->_configFile)) {
             $dom = new TXmlDocument();
             $dom->loadFromFile($this->_configFile);
             $this->loadConfig($dom);
         } else {
             throw new TConfigurationException('soapservice_configfile_invalid', $this->_configFile);
         }
     }
     $this->loadConfig($config);
     $this->resolveRequest();
 }
 /**
  * Loads a specific config file.
  * @param string config file name
  * @param string the page path that the config file is associated with. The page path doesn't include the page name.
  */
 public function loadFromFile($fname, $configPagePath)
 {
     Prado::trace("Loading page configuration file {$fname}", 'System.Web.Services.TPageService');
     if (empty($fname) || !is_file($fname)) {
         return;
     }
     if (Prado::getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) {
         $fcontent = (include $fname);
         $this->loadFromPhp($fcontent, dirname($fname), $configPagePath);
     } else {
         $dom = new TXmlDocument();
         if ($dom->loadFromFile($fname)) {
             $this->loadFromXml($dom, dirname($fname), $configPagePath);
         } else {
             throw new TConfigurationException('pageserviceconf_file_invalid', $fname);
         }
     }
 }
Exemple #9
0
 /**
  * Initialize the module from configuration file.
  * @throws TConfigurationException if {@link getConfigFile ConfigFile} is invalid.
  */
 protected function loadConfigFile()
 {
     if (is_file($this->_configFile)) {
         if ($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) {
             $config = (include $this->_configFile);
             $this->loadUrlMappings($dom);
         } else {
             $dom = new TXmlDocument();
             $dom->loadFromFile($this->_configFile);
             $this->loadUrlMappings($dom);
         }
     } else {
         throw new TConfigurationException('urlmapping_configfile_inexistent', $this->_configFile);
     }
 }
Exemple #10
0
 /**
  * Initializes the module.
  * This method is required by IModule and is invoked by application.
  * It loads user/role information from the module configuration.
  * @param mixed module configuration
  */
 public function init($config)
 {
     $this->loadUserData($config);
     if ($this->_userFile !== null) {
         if ($this->getApplication()->getConfigurationType() == TApplication::CONFIG_TYPE_PHP) {
             $userFile = (include $this->_userFile);
             $this->loadUserDataFromPhp($userFile);
         } else {
             $dom = new TXmlDocument();
             $dom->loadFromFile($this->_userFile);
             $this->loadUserDataFromXml($dom);
         }
     }
     $this->_initialized = true;
 }
Exemple #11
0
 public function testRequestWithUrlMapping()
 {
     Prado::Using('System.Web.TUrlMapping');
     $confstr = '<config><url ServiceId="testService" ServiceParameter="testServiceParam" pattern="test/{param}/?" parameters.param="\\w+"/></config>';
     $config = new TXmlDocument('1.0', 'utf8');
     $config->loadFromString($confstr);
     $module = new TUrlMapping();
     self::$app->setModule('friendly-url', $module);
     if (isset($_GET['page'])) {
         unset($_GET['page']);
     }
     // Remove service from a previous test !
     $_SERVER['REQUEST_URI'] = '/index.php/test/value2';
     $_SERVER['SCRIPT_NAME'] = '/index.php';
     $_SERVER['PHP_SELF'] = '/index.php/test/value2';
     $_SERVER['QUERY_STRING'] = '';
     $_SERVER['PATH_INFO'] = '/test/value2';
     $request = new THttpRequest();
     $request->setUrlManager('friendly-url');
     $request->setUrlFormat(THttpRequestUrlFormat::Path);
     $request->init(null);
     $module->init($config);
     self::assertEquals('testService', $request->resolveRequest(array('page', 'testService')));
 }