AppserverIo\Appserver\Naming\NamingDirectory::search PHP Метод

    public function search($name, array $args = array())
    {
        try {
            // strip off the schema
            $key = $this->stripSchema($name);
            // throw an exception if we can't find a value
            if ($this->hasAttribute($key) === false) {
                throw new \Exception(sprintf('Requested value %s has not been bound to naming directory %s', $name, $this->getIdentifier()));
            }
            // try to load the value, which may also be NULL
            if (($found = $this->getAttribute($key)) == null) {
                return;
            }
            // load the binded value/args
            list($value, $bindArgs) = $found;
            // check if we've a callback method
            if (is_callable($value)) {
                // if yes, merge the params and invoke the callback
                foreach ($args as $arg) {
                    $bindArgs[] = $arg;
                }
                // invoke the callback
                return call_user_func_array($value, $bindArgs);
            }
            // simply return the value
            return $value;
        } catch (\Exception $e) {
            throw new NamingException(sprintf('Cant\'t resolve %s in naming directory %s', $name, $this->getIdentifier()), null, $e);
        }
    }

Usage Example

Пример #1
0
 /**
  * Test if the search for a subdirectory works.
  *
  * @return void
  */
 public function testSearchForASubdirectory()
 {
     // create a three level directory
     $level1 = $this->namingDirectory->createSubdirectory('level1');
     $level2 = $level1->createSubdirectory('level2');
     $level3 = $level2->createSubdirectory('level3');
     // search for the last created subdirectory
     $this->assertInstanceOf('AppserverIo\\Psr\\Naming\\NamingDirectoryInterface', $this->namingDirectory->search('php:level1/level2/level3'));
 }
All Usage Examples Of AppserverIo\Appserver\Naming\NamingDirectory::search