Пример #1
0
 /**
  * Get the full version of a namespace prefix
  *
  * Looks up a prefix (atom:, etc.) in the list of registered
  * namespaces and returns the full namespace URI if
  * available. Returns the prefix, unmodified, if it's not
  * registered.
  *
  * @param string $prefix The namespace prefix to lookup.
  * @param integer $majorVersion The major protocol version in effect.
  *        Defaults to '1'.
  * @param integer $minorVersion The minor protocol version in effect.
  *        Defaults to null (use latest).
  * @return string
  */
 public function lookupNamespace($prefix, $majorVersion = 1, $minorVersion = null)
 {
     // If no match, return the prefix by default
     $result = $prefix;
     // Find tuple of keys that correspond to the namespace we should use
     if (isset($this->_namespaces[$prefix])) {
         // Major version search
         $nsData = $this->_namespaces[$prefix];
         $foundMajorV = Zend_Gdata_App_Util::findGreatestBoundedValue($majorVersion, $nsData);
         // Minor version search
         $nsData = $nsData[$foundMajorV];
         $foundMinorV = Zend_Gdata_App_Util::findGreatestBoundedValue($minorVersion, $nsData);
         // Extract NS
         $result = $nsData[$foundMinorV];
     }
     return $result;
 }
Пример #2
0
 /**
  * Get the full version of a namespace prefix
  *
  * Looks up a prefix (atom:, etc.) in the list of registered
  * namespaces and returns the full namespace URI if
  * available. Returns the prefix, unmodified, if it's not
  * registered.
  *
  * @param string $prefix The namespace prefix to lookup.
  * @param integer $majorVersion The major protocol version in effect.
  *        Defaults to '1'.
  * @param integer $minorVersion The minor protocol version in effect.
  *        Defaults to null (use latest).
  * @return string
  */
 public function lookupNamespace($prefix, $majorVersion = 1, $minorVersion = null)
 {
     // Check for a memoized result
     $key = $prefix . ' ' . ($majorVersion === null ? 'NULL' : $majorVersion) . ' ' . ($minorVersion === null ? 'NULL' : $minorVersion);
     if (array_key_exists($key, self::$_namespaceLookupCache)) {
         return self::$_namespaceLookupCache[$key];
     }
     // If no match, return the prefix by default
     $result = $prefix;
     // Find tuple of keys that correspond to the namespace we should use
     if (isset($this->_namespaces[$prefix])) {
         // Major version search
         $nsData = $this->_namespaces[$prefix];
         $foundMajorV = Zend_Gdata_App_Util::findGreatestBoundedValue($majorVersion, $nsData);
         // Minor version search
         $nsData = $nsData[$foundMajorV];
         $foundMinorV = Zend_Gdata_App_Util::findGreatestBoundedValue($minorVersion, $nsData);
         // Extract NS
         $result = $nsData[$foundMinorV];
     }
     // Memoize result
     self::$_namespaceLookupCache[$key] = $result;
     return $result;
 }
Пример #3
0
 public function testFindGreatestBoundedValueFailsWhenNegativelyBounded()
 {
     $data = array(-1 => null, 0 => null, 1 => null, 2 => null, 3 => null, 5 => null, -2 => null);
     try {
         $result = Zend_Gdata_App_Util::findGreatestBoundedValue(-1, $data);
         $failed = true;
     } catch (Zend_Gdata_App_Exception $e) {
         $failed = false;
     }
     $this->assertFalse($failed, 'Exception not raised.');
 }