Auth_OpenID_NamespaceMap::add PHP Метод

add() публичный Метод

public add ( $namespace_uri )
    function add($namespace_uri)
    {
        // Add this namespace URI to the mapping, without caring what
        // alias it ends up with
        // See if this namespace is already mapped to an alias
        $alias = $this->namespace_to_alias->get($namespace_uri);
        if ($alias !== null) {
            return $alias;
        }
        // Fall back to generating a numerical alias
        $i = 0;
        while (1) {
            $alias = 'ext' . strval($i);
            if ($this->addAlias($namespace_uri, $alias) === null) {
                $i += 1;
            } else {
                return $alias;
            }
        }
        // Should NEVER be reached!
        return null;
    }

Usage Example

Пример #1
0
 function test_iteration()
 {
     $nsm = new Auth_OpenID_NamespaceMap();
     $uripat = 'http://example.com/foo%d';
     $nsm->add(sprintf($uripat, 0));
     for ($n = 1; $n < 23; $n++) {
         $this->assertTrue($nsm->contains(sprintf($uripat, $n - 1)));
         $this->assertTrue($nsm->isDefined(sprintf($uripat, $n - 1)));
         $nsm->add(sprintf($uripat, $n));
     }
     foreach ($nsm->iteritems() as $pair) {
         list($uri, $alias) = $pair;
         $this->assertTrue('ext' . substr($uri, 22) == $alias);
     }
     $it = $nsm->iterAliases();
     $this->assertTrue(count($it) == 23);
     $it = $nsm->iterNamespaceURIs();
     $this->assertTrue(count($it) == 23);
 }
All Usage Examples Of Auth_OpenID_NamespaceMap::add