/**
  * Test un-registration of keyed shutdown handler.
  *
  * @depends testRegister
  * @depends testUnRegister
  * @depends testShutdown
  */
 public function testUnRegisterKey()
 {
     self::$testVariable = 0;
     $handler = new ShutdownHandler(array(get_class($this), 'shutdown'), array(), 'testkey');
     $handler->unRegister();
     ShutdownHandler::shutdown();
     $this->assertSame(0, self::$testVariable);
     self::$testVariable = 0;
     $handler1 = new ShutdownHandler(array(get_class($this), 'shutdown'), array(), 'testkey1');
     $handler2 = new ShutdownHandler(array(get_class($this), 'shutdown'), array(), 'testkey1');
     $handler1->unRegister();
     ShutdownHandler::shutdown();
     $this->assertSame(1, self::$testVariable);
     self::$testVariable = 0;
     $handler1 = new ShutdownHandler(array(get_class($this), 'shutdown'), array(), 'testkey1');
     $handler2 = new ShutdownHandler(array(get_class($this), 'shutdown'), array(), 'testkey2');
     $handler2->unRegister();
     ShutdownHandler::shutdown();
     $this->assertSame(1, self::$testVariable);
 }
Example #2
0
<?php

namespace Gielfeldt\ShutdownHandler\Example;

require 'vendor/autoload.php';
use Gielfeldt\ShutdownHandler\ShutdownHandler;
/**
 * Simple shutdown handler callback.
 *
 * @param string $message
 *   Message to display during shutdown.
 */
function myshutdownhandler($message = '')
{
    echo "Goodbye {$message}\n";
}
// Register shutdown handler to be run during PHP shutdown phase.
$handler = new ShutdownHandler('\\Gielfeldt\\ShutdownHandler\\Example\\myshutdownhandler', array('cruel world'));
echo "Hello world\n";
// Register shutdown handler.
$handler2 = new ShutdownHandler('\\Gielfeldt\\ShutdownHandler\\Example\\myshutdownhandler', array('for now'));
// Don't run the first shutdown handler anyways.
$handler->unRegister();