Esempio n. 1
0
 /**
  * Create auth adapter
  *
  * @param string $rolefile File containing XML with users and roles
  */
 public function __construct($rolefile)
 {
     $this->_acl = new Acl();
     $xml = XmlSecurity::scanFile($rolefile);
     /*
     Roles file format:
      <roles>
        <role id=”admin”>
             <user name=”user1” password=”pwd”/>
         </role>
        <role id=”hr”>
             <user name=”user2” password=”pwd2”/>
         </role>
     </roles>
     */
     foreach ($xml->role as $role) {
         $this->_acl->addRole(new \fproject\amf\acl\Role((string) $role["id"]));
         foreach ($role->user as $user) {
             $this->_users[(string) $user["name"]] = array("password" => (string) $user["password"], "role" => (string) $role["id"]);
         }
     }
 }
Esempio n. 2
0
 /**
  * Convert XML to SimpleXml
  * If user wants DomDocument they can use dom_import_simplexml
  *
  * @return \SimpleXMLElement|\DOMDocument|bool
  */
 public function readXmlString()
 {
     $xmlReference = $this->readInteger();
     $length = $xmlReference >> 1;
     $string = $this->_stream->readBytes($length);
     return XmlSecurity::scan($string);
 }
Esempio n. 3
0
 /**
  * Convert XML to SimpleXml
  * If user wants DomDocument they can use dom_import_simplexml
  *
  * @return \SimpleXMLElement|\DOMDocument|boolean
  */
 public function readXmlString()
 {
     $string = $this->_stream->readLongUTF();
     return XmlSecurity::scan($string);
     //simplexml_load_string($string);
 }
Esempio n. 4
0
 /**
  * fromXml - Converts XML to JSON
  *
  * Converts a XML formatted string into a JSON formatted string.
  * The value returned will be a string in JSON format.
  *
  * The caller of this function needs to provide only the first parameter,
  * which is an XML formatted String. The second parameter is optional, which
  * lets the user to select if the XML attributes in the input XML string
  * should be included or ignored in xml2json conversion.
  *
  * This function converts the XML formatted string into a PHP array by
  * calling a recursive (protected static) function in this class. Then, it
  * converts that PHP array into JSON by calling the "encode" static funcion.
  *
  * Throws a Zend_Json_Exception if the input not a XML formatted string.
  * NOTE: Encoding native javascript expressions via Zend_Json_Expr is not possible.
  *
  * @static
  * @access public
  * @param string $xmlStringContents XML String to be converted
  * @param boolean $ignoreXmlAttributes Include or exclude XML attributes in
  * the xml2json conversion process.
  * @return mixed - JSON formatted string on success
  * @throws Zend_Json_Exception
  */
 public static function fromXml($xmlStringContents, $ignoreXmlAttributes = true)
 {
     // Load the XML formatted string into a Simple XML Element object.
     $simpleXmlElementObject = XmlSecurity::scan($xmlStringContents);
     // If it is not a valid XML content, throw an exception.
     if ($simpleXmlElementObject == null) {
         require_once 'Zend/Json/Exception.php';
         throw new Zend_Json_Exception('Function fromXml was called with an invalid XML formatted string.');
     }
     // End of if ($simpleXmlElementObject == null)
     $resultArray = null;
     // Call the recursive function to convert the XML into a PHP array.
     $resultArray = self::_processXml($simpleXmlElementObject, $ignoreXmlAttributes);
     // Convert the PHP array to JSON using Zend_Json encode method.
     // It is just that simple.
     $jsonStringOutput = self::encode($resultArray);
     return $jsonStringOutput;
 }