bind() public method

Binds the passed instance with the name to the naming directory.
public bind ( string $name, mixed $value, array $args = [] ) : void
$name string The name to bind the value with
$value mixed The object instance to bind
$args array The array with the arguments
return void
Example #1
0
 /**
  * Test the descending recursive search on a directory tree
  * with a three level structure.
  *
  * @return void
  */
 public function testThreeLevelDescendingRecursiveSearch()
 {
     // create the three level tree
     $level1 = $this->namingDirectory->createSubdirectory('level1');
     $level2 = $level1->createSubdirectory('level2');
     $level3 = $level2->createSubdirectory('level3');
     // bind a value and search recursive
     $this->namingDirectory->bind($name = 'php:level1/level2/level3/test', $value = 'testValue');
     $this->assertSame($this->namingDirectory->search($name), $value);
 }
Example #2
0
// create and initialize the naming directory
$namingDirectory = new NamingDirectory();
$namingDirectory->setScheme('php');
// create a directory for the services
$namingDirectory->createSubdirectory('php:env');
$namingDirectory->createSubdirectory('php:env/args');
$namingDirectory->createSubdirectory('php:global');
$namingDirectory->createSubdirectory('php:global/log');
$namingDirectory->createSubdirectory('php:services');
// create the default subdirectories
foreach (array_keys(ApplicationServer::$runlevels) as $runlevel) {
    $namingDirectory->createSubdirectory(sprintf('php:services/%s', $runlevel));
}
// bind the command line arguments to the naming directory
foreach ($arguments as $name => $value) {
    $namingDirectory->bind(sprintf('php:env/args/%s', $name), empty($value) ? true : $value);
}
// bind the current user to the naming directory
$namingDirectory->bind('php:env/currentUser', isset($_SERVER['SUDO_USER']) ? $_SERVER['SUDO_USER'] : get_current_user());
// bind the path to the default configuration and bootstrap filenames
$namingDirectory->bind('php:env/configurationFilename', DirectoryKeys::realpath($filename));
$namingDirectory->bind('php:env/bootstrapConfigurationFilename', DirectoryKeys::realpath($bootstrapFilename));
// add the storeage containers for the runlevels
$runlevels = new GenericStackable();
foreach (ApplicationServer::$runlevels as $runlevel) {
    $runlevels[$runlevel] = new GenericStackable();
}
// initialize and start the application server
$applicationServer = ApplicationServer::singleton($namingDirectory, $runlevels);
// we've to wait for shutdown
while ($applicationServer->keepRunning()) {