diff --git a/README.md b/README.md index 8ea2d9d..25149d6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -#how to use? +#how to use Event? ```php // varialbe outside of the closure bellow $message = 'test Message'; @@ -18,3 +18,46 @@ if ($oEvent->hasEvent('test')) { $oEvent->emit('test', array('1', '2')); } ``` + +#how to use Application? +```php +use \Sandbox\Application as TestApplication; + +$app = new TestApplication(); +$app->on('create', function ($a) use ($message) { + echo $a . ' ' . $message . '
'; +}); + +$app->on('retrieve', function ($a) use ($message) { + echo $a . ' ' . $message . '
'; +}); + +$app->on('update', function ($a) use ($message) { + echo $a . ' ' . $message . '
'; +}); + +$app->on('delete', function ($a) use ($message) { + echo $a . ' ' . $message . '
'; +}); + +$app->on('debug', function ($message) { + error_reporting(E_ALL); + ini_set("display_errors", 1); + + echo var_export($message, true) . '
'; +}); + +$eventName = $app->getRequestEvent(); +$input = $app->getInputData(); + +if (isset($input['debug']) && $app->hasEvent('debug')) { + $app->emit('debug', $input); +} + +if ($app->hasEvent($eventName)) { + // 觸發事件 + $message = var_export($input, true); + $app->emit($eventName, $message); +} + +```