code
stringlengths
31
707k
docstring
stringlengths
23
14.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
function CakeCLIReporter($charset = 'utf-8', $params = array()) { $this->CakeBaseReporter($charset, $params); }
Constructor @param string $separator @param array $params @return void
CakeCLIReporter
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_cli_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_cli_reporter.php
MIT
function paintFail($message) { parent::paintFail($message); $message .= $this->_getBreadcrumb(); fwrite(STDERR, 'FAIL' . $this->separator . $message); }
Paint fail faildetail to STDERR. @param string $message Message of the fail. @return void @access public
paintFail
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_cli_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_cli_reporter.php
MIT
function paintError($message) { parent::paintError($message); $message .= $this->_getBreadcrumb(); fwrite(STDERR, 'ERROR' . $this->separator . $message); }
Paint PHP errors to STDERR. @param string $message Message of the Error @return void @access public
paintError
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_cli_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_cli_reporter.php
MIT
function paintException($exception) { parent::paintException($exception); $message = sprintf('Unexpected exception of type [%s] with message [%s] in [%s] line [%s]', get_class($exception), $exception->getMessage(), $exception->getFile(), $exception->getLine() ); $message .= $this->_getBreadcrumb(); fwrite(STDERR, 'EXCEPTION' . $this->separator . $message); }
Paint exception faildetail to STDERR. @param object $exception Exception instance @return void @access public
paintException
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_cli_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_cli_reporter.php
MIT
function _getBreadcrumb() { $breadcrumb = $this->getTestList(); array_shift($breadcrumb); $out = "\n\tin " . implode("\n\tin ", array_reverse($breadcrumb)); $out .= "\n\n"; return $out; }
Get the breadcrumb trail for the current test method/case @return string The string for the breadcrumb
_getBreadcrumb
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_cli_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_cli_reporter.php
MIT
function paintSkip($message) { parent::paintSkip($message); fwrite(STDOUT, 'SKIP' . $this->separator . $message . "\n\n"); }
Paint a test skip message @param string $message The message of the skip @return void
paintSkip
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_cli_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_cli_reporter.php
MIT
function paintFooter($test_name) { $buffer = $this->getTestCaseProgress() . '/' . $this->getTestCaseCount() . ' test cases complete: '; if (0 < ($this->getFailCount() + $this->getExceptionCount())) { $buffer .= $this->getPassCount() . " passes"; if (0 < $this->getFailCount()) { $buffer .= ", " . $this->getFailCount() . " fails"; } if (0 < $this->getExceptionCount()) { $buffer .= ", " . $this->getExceptionCount() . " exceptions"; } $buffer .= ".\n"; $buffer .= $this->_timeStats(); fwrite(STDOUT, $buffer); } else { fwrite(STDOUT, $buffer . $this->getPassCount() . " passes.\n" . $this->_timeStats()); } if ( isset($this->params['codeCoverage']) && $this->params['codeCoverage'] && class_exists('CodeCoverageManager') ) { CodeCoverageManager::report(); } }
Paint a footer with test case name, timestamp, counts of fails and exceptions.
paintFooter
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_cli_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_cli_reporter.php
MIT
function _timeStats() { $out = 'Time taken by tests (in seconds): ' . $this->_timeDuration . "\n"; if (function_exists('memory_get_peak_usage')) { $out .= 'Peak memory use: (in bytes): ' . number_format(memory_get_peak_usage()) . "\n"; } return $out; }
Get the time and memory stats for this test case/group @return string String content to display @access protected
_timeStats
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_cli_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_cli_reporter.php
MIT
function CakeHtmlReporter($charset = 'utf-8', $params = array()) { $params = array_map(array($this, '_htmlEntities'), $params); $this->CakeBaseReporter($charset, $params); }
Constructor @param string $charset @param string $params @return void
CakeHtmlReporter
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_html_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_html_reporter.php
MIT
function paintHeader($testName) { $this->sendNoCacheHeaders(); $this->paintDocumentStart(); $this->paintTestMenu(); printf("<h2>%s</h2>\n", $this->_htmlEntities($testName)); echo "<ul class='tests'>\n"; }
Paints the top of the web page setting the title to the name of the starting test. @param string $test_name Name class of test. @return void @access public
paintHeader
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_html_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_html_reporter.php
MIT
function paintDocumentStart() { ob_start(); $baseDir = $this->params['baseDir']; include CAKE_TESTS_LIB . 'templates' . DS . 'header.php'; }
Paints the document start content contained in header.php @return void
paintDocumentStart
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_html_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_html_reporter.php
MIT
function paintTestMenu() { $groups = $this->baseUrl() . '?show=groups'; $cases = $this->baseUrl() . '?show=cases'; $plugins = App::objects('plugin', null, false); sort($plugins); include CAKE_TESTS_LIB . 'templates' . DS . 'menu.php'; }
Paints the menu on the left side of the test suite interface. Contains all of the various plugin, core, and app buttons. @return void
paintTestMenu
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_html_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_html_reporter.php
MIT
function testCaseList() { $testCases = parent::testCaseList(); $app = $this->params['app']; $plugin = $this->params['plugin']; $buffer = "<h3>Core Test Cases:</h3>\n<ul>"; $urlExtra = null; if ($app) { $buffer = "<h3>App Test Cases:</h3>\n<ul>"; $urlExtra = '&app=true'; } elseif ($plugin) { $buffer = "<h3>" . Inflector::humanize($plugin) . " Test Cases:</h3>\n<ul>"; $urlExtra = '&plugin=' . $plugin; } if (1 > count($testCases)) { $buffer .= "<strong>EMPTY</strong>"; } foreach ($testCases as $testCaseFile => $testCase) { $title = explode(strpos($testCase, '\\') ? '\\' : '/', str_replace('.test.php', '', $testCase)); $title[count($title) - 1] = Inflector::camelize($title[count($title) - 1]); $title = implode(' / ', $title); $buffer .= "<li><a href='" . $this->baseUrl() . "?case=" . urlencode($testCase) . $urlExtra ."'>" . $title . "</a></li>\n"; } $buffer .= "</ul>\n"; echo $buffer; }
Retrieves and paints the list of tests cases in an HTML format. @return void
testCaseList
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_html_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_html_reporter.php
MIT
function groupTestList() { $groupTests = parent::groupTestList(); $app = $this->params['app']; $plugin = $this->params['plugin']; $buffer = "<h3>Core Test Groups:</h3>\n<ul>"; $urlExtra = null; if ($app) { $buffer = "<h3>App Test Groups:</h3>\n<ul>"; $urlExtra = '&app=true'; } else if ($plugin) { $buffer = "<h3>" . Inflector::humanize($plugin) . " Test Groups:</h3>\n<ul>"; $urlExtra = '&plugin=' . $plugin; } $buffer .= "<li><a href='" . $this->baseURL() . "?group=all$urlExtra'>All tests</a></li>\n"; foreach ($groupTests as $groupTest) { $buffer .= "<li><a href='" . $this->baseURL() . "?group={$groupTest}" . "{$urlExtra}'>" . $groupTest . "</a></li>\n"; } $buffer .= "</ul>\n"; echo $buffer; }
Retrieves and paints the list of group tests in an HTML format. @return void
groupTestList
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_html_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_html_reporter.php
MIT
function sendNoCacheHeaders() { if (!headers_sent()) { header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); header("Cache-Control: no-store, no-cache, must-revalidate"); header("Cache-Control: post-check=0, pre-check=0", false); header("Pragma: no-cache"); } }
Send the headers necessary to ensure the page is reloaded on every request. Otherwise you could be scratching your head over out of date test data. @return void @access public
sendNoCacheHeaders
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_html_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_html_reporter.php
MIT
function paintFooter($test_name) { $colour = ($this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green"); echo "</ul>\n"; echo "<div style=\""; echo "padding: 8px; margin: 1em 0; background-color: $colour; color: white;"; echo "\">"; echo $this->getTestCaseProgress() . "/" . $this->getTestCaseCount(); echo " test cases complete:\n"; echo "<strong>" . $this->getPassCount() . "</strong> passes, "; echo "<strong>" . $this->getFailCount() . "</strong> fails and "; echo "<strong>" . $this->getExceptionCount() . "</strong> exceptions."; echo "</div>\n"; echo '<div style="padding:0 0 5px;">'; echo '<p><strong>Time taken by tests (in seconds):</strong> ' . $this->_timeDuration . '</p>'; if (function_exists('memory_get_peak_usage')) { echo '<p><strong>Peak memory use: (in bytes):</strong> ' . number_format(memory_get_peak_usage()) . '</p>'; } echo $this->_paintLinks(); echo '</div>'; if ( isset($this->params['codeCoverage']) && $this->params['codeCoverage'] && class_exists('CodeCoverageManager') ) { CodeCoverageManager::report(); } $this->paintDocumentEnd(); }
Paints the end of the test with a summary of the passes and failures. @param string $test_name Name class of test. @return void @access public
paintFooter
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_html_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_html_reporter.php
MIT
function _paintLinks() { $show = $query = array(); if (!empty($this->params['group'])) { $show['show'] = 'groups'; } elseif (!empty($this->params['case'])) { $show['show'] = 'cases'; } if (!empty($this->params['app'])) { $show['app'] = $query['app'] = 'true'; } if (!empty($this->params['plugin'])) { $show['plugin'] = $query['plugin'] = $this->params['plugin']; } if (!empty($this->params['case'])) { $query['case'] = $this->params['case']; } elseif (!empty($this->params['group'])) { $query['group'] = $this->params['group']; } $show = $this->_queryString($show); $query = $this->_queryString($query); echo "<p><a href='" . $this->baseUrl() . $show . "'>Run more tests</a> | <a href='" . $this->baseUrl() . $query . "&show_passes=1'>Show Passes</a> | \n"; echo " <a href='" . $this->baseUrl() . $query . "&amp;code_coverage=true'>Analyze Code Coverage</a></p>\n"; }
Renders the links that for accessing things in the test suite. @return void
_paintLinks
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_html_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_html_reporter.php
MIT
function _queryString($url) { $out = '?'; $params = array(); foreach ($url as $key => $value) { $params[] = "$key=$value"; } $out .= implode('&amp;', $params); return $out; }
Convert an array of parameters into a query string url @param array $url Url hash to be converted @return string Converted url query string
_queryString
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_html_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_html_reporter.php
MIT
function paintDocumentEnd() { $baseDir = $this->params['baseDir']; include CAKE_TESTS_LIB . 'templates' . DS . 'footer.php'; ob_end_flush(); }
Paints the end of the document html. @return void
paintDocumentEnd
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_html_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_html_reporter.php
MIT
function paintFail($message) { parent::paintFail($message); echo "<li class='fail'>\n"; echo "<span>Failed</span>"; echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n"; $breadcrumb = $this->getTestList(); array_shift($breadcrumb); echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n"; echo "</li>\n"; }
Paints the test failure with a breadcrumbs trail of the nesting test suites below the top level test. @param string $message Failure message displayed in the context of the other tests. @return void @access public
paintFail
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_html_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_html_reporter.php
MIT
function paintPass($message) { parent::paintPass($message); if (isset($this->params['show_passes']) && $this->params['show_passes']) { echo "<li class='pass'>\n"; echo "<span>Passed</span> "; $breadcrumb = $this->getTestList(); array_shift($breadcrumb); echo implode(" -&gt; ", $breadcrumb); echo "<br />" . $this->_htmlEntities($message) . "\n"; echo "</li>\n"; } }
Paints the test pass with a breadcrumbs trail of the nesting test suites below the top level test. @param string $message Pass message displayed in the context of the other tests. @return void @access public
paintPass
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_html_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_html_reporter.php
MIT
function paintError($message) { parent::paintError($message); echo "<li class='error'>\n"; echo "<span>Error</span>"; echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n"; $breadcrumb = $this->getTestList(); array_shift($breadcrumb); echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n"; echo "</li>\n"; }
Paints a PHP error. @param string $message Message is ignored. @return void @access public
paintError
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_html_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_html_reporter.php
MIT
function paintException($exception) { parent::paintException($exception); echo "<li class='fail'>\n"; echo "<span>Exception</span>"; $message = 'Unexpected exception of type [' . get_class($exception) . '] with message ['. $exception->getMessage() . '] in ['. $exception->getFile() . ' line ' . $exception->getLine() . ']'; echo "<div class='msg'>" . $this->_htmlEntities($message) . "</div>\n"; $breadcrumb = $this->getTestList(); array_shift($breadcrumb); echo "<div>" . implode(" -&gt; ", $breadcrumb) . "</div>\n"; echo "</li>\n"; }
Paints a PHP exception. @param Exception $exception Exception to display. @return void @access public
paintException
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_html_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_html_reporter.php
MIT
function paintSkip($message) { parent::paintSkip($message); echo "<li class='skipped'>\n"; echo "<span>Skipped</span> "; echo $this->_htmlEntities($message); echo "</li>\n"; }
Prints the message for skipping tests. @param string $message Text of skip condition. @return void @access public
paintSkip
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_html_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_html_reporter.php
MIT
function paintFormattedMessage($message) { echo '<pre>' . $this->_htmlEntities($message) . '</pre>'; }
Paints formatted text such as dumped variables. @param string $message Text to show. @return void @access public
paintFormattedMessage
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_html_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_html_reporter.php
MIT
function _htmlEntities($message) { return htmlentities($message, ENT_COMPAT, $this->_characterSet); }
Character set adjusted entity conversion. @param string $message Plain text or Unicode message. @return string Browser readable message. @access protected
_htmlEntities
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_html_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_html_reporter.php
MIT
function paintDocumentStart() { if (!SimpleReporter::inCli()) { header('Content-type: text/plain'); } }
Sets the text/plain header if the test is not a CLI test. @return void
paintDocumentStart
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_text_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_text_reporter.php
MIT
function paintHeader($test_name) { $this->paintDocumentStart(); echo "$test_name\n"; flush(); }
Paints the title only. @param string $test_name Name class of test. @return void @access public
paintHeader
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_text_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_text_reporter.php
MIT
function paintFail($message) { parent::paintFail($message); echo $this->getFailCount() . ") $message\n"; $breadcrumb = $this->getTestList(); array_shift($breadcrumb); echo "\tin " . implode("\n\tin ", array_reverse($breadcrumb)); echo "\n"; }
Paints the test failure as a stack trace. @param string $message Failure message displayed in the context of the other tests. @return void @access public
paintFail
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_text_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_text_reporter.php
MIT
function paintError($message) { parent::paintError($message); echo "Exception " . $this->getExceptionCount() . "!\n$message\n"; $breadcrumb = $this->getTestList(); array_shift($breadcrumb); echo "\tin " . implode("\n\tin ", array_reverse($breadcrumb)); echo "\n"; }
Paints a PHP error. @param string $message Message to be shown. @return void @access public
paintError
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_text_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_text_reporter.php
MIT
function paintException($exception) { parent::paintException($exception); $message = 'Unexpected exception of type [' . get_class($exception) . '] with message ['. $exception->getMessage() . '] in ['. $exception->getFile() . ' line ' . $exception->getLine() . ']'; echo "Exception " . $this->getExceptionCount() . "!\n$message\n"; $breadcrumb = $this->getTestList(); array_shift($breadcrumb); echo "\tin " . implode("\n\tin ", array_reverse($breadcrumb)); echo "\n"; }
Paints a PHP exception. @param Exception $exception Exception to describe. @return void @access public
paintException
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_text_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_text_reporter.php
MIT
function testCaseList() { $testCases = parent::testCaseList(); $app = $this->params['app']; $plugin = $this->params['plugin']; $buffer = "Core Test Cases:\n"; $urlExtra = ''; if ($app) { $buffer = "App Test Cases:\n"; $urlExtra = '&app=true'; } elseif ($plugin) { $buffer = Inflector::humanize($plugin) . " Test Cases:\n"; $urlExtra = '&plugin=' . $plugin; } if (1 > count($testCases)) { $buffer .= "EMPTY"; echo $buffer; } foreach ($testCases as $testCaseFile => $testCase) { $buffer .= $_SERVER['SERVER_NAME'] . $this->baseUrl() ."?case=" . $testCase . "&output=text"."\n"; } $buffer .= "\n"; echo $buffer; }
Generate a test case list in plain text. Creates as series of url's for tests that can be run. One case per line. @return void
testCaseList
php
Datawalke/Coordino
cake/tests/lib/reporter/cake_text_reporter.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/lib/reporter/cake_text_reporter.php
MIT
function main() { $this->out('This is the main method called from TestPlugin.ExampleShell'); }
main method @access public @return void
main
php
Datawalke/Coordino
cake/tests/test_app/plugins/test_plugin/vendors/shells/example.php
https://github.com/Datawalke/Coordino/blob/master/cake/tests/test_app/plugins/test_plugin/vendors/shells/example.php
MIT
public function parse(int $type, $annotationObject): array { if ($type != self::TYPE_PROPERTY) { return []; } ValidatorRegister::registerValidatorItem($this->className, $this->propertyName, $annotationObject); return []; }
@param int $type @param object $annotationObject @return array @throws ReflectionException @throws ValidatorException
parse
php
swoft-cloud/swoft
app/Annotation/Parser/AlphaDashParser.php
https://github.com/swoft-cloud/swoft/blob/master/app/Annotation/Parser/AlphaDashParser.php
Apache-2.0
public function getList(Client $client): array { // Get health service from consul $services = $this->agent->services(); $services = [ ]; return $services; }
@param Client $client @return array @throws ClientException @throws ServerException @example [ 'host:port', 'host:port', 'host:port', ]
getList
php
swoft-cloud/swoft
app/Common/RpcProvider.php
https://github.com/swoft-cloud/swoft/blob/master/app/Common/RpcProvider.php
Apache-2.0
public function checkAccess(): void { \bean('httpRouter')->each(function (Route $route) { $path = $route->getPath(); // Skip some routes if ($route->getMethod() !== 'GET' || false !== \strpos($path, '{')) { return; } $command = sprintf('curl -I 127.0.0.1:18306%s', $path); Show::colored('> ' . $command); \exec($command); }); }
Mock request some api for test server @CommandMapping("ca")
checkAccess
php
swoft-cloud/swoft
app/Console/Command/TestCommand.php
https://github.com/swoft-cloud/swoft/blob/master/app/Console/Command/TestCommand.php
Apache-2.0
public function handle(Throwable $except, Response $response): Response { $data = [ 'code' => $except->getCode(), 'error' => sprintf('(%s) %s', get_class($except), $except->getMessage()), 'file' => sprintf('At %s line %d', $except->getFile(), $except->getLine()), 'trace' => $except->getTraceAsString(), ]; return $response->withData($data); }
@param Throwable $except @param Response $response @return Response
handle
php
swoft-cloud/swoft
app/Exception/Handler/ApiExceptionHandler.php
https://github.com/swoft-cloud/swoft/blob/master/app/Exception/Handler/ApiExceptionHandler.php
Apache-2.0
public function handle(Throwable $e, Response $response): Response { // Log error message Log::error($e->getMessage()); CLog::error('%s. (At %s line %d)', $e->getMessage(), $e->getFile(), $e->getLine()); // Debug is false if (!APP_DEBUG) { return $response->withStatus(500)->withContent($e->getMessage()); } $data = [ 'code' => $e->getCode(), 'error' => sprintf('(%s) %s', get_class($e), $e->getMessage()), 'file' => sprintf('At %s line %d', $e->getFile(), $e->getLine()), 'trace' => $e->getTraceAsString(), ]; // Debug is true return $response->withData($data); }
@param Throwable $e @param Response $response @return Response
handle
php
swoft-cloud/swoft
app/Exception/Handler/HttpExceptionHandler.php
https://github.com/swoft-cloud/swoft/blob/master/app/Exception/Handler/HttpExceptionHandler.php
Apache-2.0
public function del(): array { return ['del' => Cache::delete('ckey')]; }
@RequestMapping("del") @return array @throws InvalidArgumentException
del
php
swoft-cloud/swoft
app/Http/Controller/CacheController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/CacheController.php
Apache-2.0
public function get(Request $request): array { return $request->getCookieParams(); }
@RequestMapping() @param Request $request @return array
get
php
swoft-cloud/swoft
app/Http/Controller/CookieController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/CookieController.php
Apache-2.0
public function find(Response $response): Response { $id = $this->getId(); $user = User::find($id); return $response->withData($user); }
@RequestMapping(route="find") @param Response $response @return Response @throws Throwable
find
php
swoft-cloud/swoft
app/Http/Controller/DbModelController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/DbModelController.php
Apache-2.0
public function save(): array { $user = new User(); $user->setAge(random_int(1, 100)); $user->setUserDesc('desc'); $user->save(); $count = Count::new(); $count->setUserId($user->getId()); $count->save(); return $user->toArray(); }
@RequestMapping(route="save") @return array @throws Exception
save
php
swoft-cloud/swoft
app/Http/Controller/DbModelController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/DbModelController.php
Apache-2.0
public function update(): array { $id = $this->getId(); User::updateOrInsert(['id' => $id], ['name' => 'swoft', 'userDesc' => 'swoft']); $user = User::find($id); return $user->toArray(); }
@RequestMapping(route="update") @return array @throws Throwable
update
php
swoft-cloud/swoft
app/Http/Controller/DbModelController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/DbModelController.php
Apache-2.0
public function delete(): array { $id = $this->getId(); $result = User::find($id)->delete(); return [$result]; }
@RequestMapping(route="delete") @return array @throws Throwable
delete
php
swoft-cloud/swoft
app/Http/Controller/DbModelController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/DbModelController.php
Apache-2.0
public function ts() { $id = $this->getId(); DB::beginTransaction(); $user = User::find($id); sgo(function () use ($id) { DB::beginTransaction(); User::find($id); }); return json_encode($user->toArray()); }
@RequestMapping(route="ts") @return false|string @throws Throwable
ts
php
swoft-cloud/swoft
app/Http/Controller/DbTransactionController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/DbTransactionController.php
Apache-2.0
public function cm() { $id = $this->getId(); DB::beginTransaction(); $user = User::find($id); DB::commit(); sgo(function () use ($id) { DB::beginTransaction(); User::find($id); DB::commit(); }); return json_encode($user->toArray()); }
@RequestMapping(route="cm") @return false|string @throws Throwable
cm
php
swoft-cloud/swoft
app/Http/Controller/DbTransactionController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/DbTransactionController.php
Apache-2.0
public function rl() { $id = $this->getId(); DB::beginTransaction(); $user = User::find($id); DB::rollBack(); sgo(function () use ($id) { DB::beginTransaction(); User::find($id); DB::rollBack(); }); return json_encode($user->toArray()); }
@RequestMapping(route="rl") @return false|string @throws Throwable
rl
php
swoft-cloud/swoft
app/Http/Controller/DbTransactionController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/DbTransactionController.php
Apache-2.0
public function ts2() { $id = $this->getId(); DB::connection()->beginTransaction(); $user = User::find($id); sgo(function () use ($id) { DB::connection()->beginTransaction(); User::find($id); }); return json_encode($user->toArray()); }
@RequestMapping(route="ts2") @return false|string @throws Throwable
ts2
php
swoft-cloud/swoft
app/Http/Controller/DbTransactionController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/DbTransactionController.php
Apache-2.0
public function cm2() { $id = $this->getId(); DB::connection()->beginTransaction(); $user = User::find($id); DB::connection()->commit(); sgo(function () use ($id) { DB::connection()->beginTransaction(); User::find($id); DB::connection()->commit(); }); return json_encode($user->toArray()); }
@RequestMapping(route="cm2") @return false|string @throws Throwable
cm2
php
swoft-cloud/swoft
app/Http/Controller/DbTransactionController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/DbTransactionController.php
Apache-2.0
public function rl2() { $id = $this->getId(); DB::connection()->beginTransaction(); $user = User::find($id); DB::connection()->rollBack(); sgo(function () use ($id) { DB::connection()->beginTransaction(); User::find($id); DB::connection()->rollBack(); }); return json_encode($user->toArray()); }
@RequestMapping(route="rl2") @return false|string @throws Throwable
rl2
php
swoft-cloud/swoft
app/Http/Controller/DbTransactionController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/DbTransactionController.php
Apache-2.0
public function multiPool() { DB::beginTransaction(); // db3.pool $user = new User3(); $user->setAge(random_int(1, 100)); $user->setUserDesc('desc'); $user->save(); $uid3 = $user->getId(); //db.pool $uid = $this->getId(); $count = new Count(); $count->setUserId(random_int(1, 100)); $count->setAttributes('attr'); $count->setCreateTime(time()); $count->save(); $cid = $count->getId(); DB::rollBack(); $u3 = User3::find($uid3)->toArray(); $u = User::find($uid); $c = Count::find($cid); return [$u3, $u, $c]; }
@RequestMapping() @return array @throws DbException @throws Throwable
multiPool
php
swoft-cloud/swoft
app/Http/Controller/DbTransactionController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/DbTransactionController.php
Apache-2.0
public function hello(string $name): Response { return context()->getResponse()->withContent('Hello' . ($name === '' ? '' : ", {$name}")); }
@RequestMapping("/hello[/{name}]") @param string $name @return Response
hello
php
swoft-cloud/swoft
app/Http/Controller/HomeController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/HomeController.php
Apache-2.0
public function wsTest(): Response { return view('home/ws-test'); }
@RequestMapping("/wstest", method={"GET"}) @return Response @throws Throwable
wsTest
php
swoft-cloud/swoft
app/Http/Controller/HomeController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/HomeController.php
Apache-2.0
public function dataConfig(): array { return bean(GoodsData::class)->getConfig(); }
@RequestMapping("/dataConfig", method={"GET"}) @return array @throws Throwable
dataConfig
php
swoft-cloud/swoft
app/Http/Controller/HomeController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/HomeController.php
Apache-2.0
public function release(): array { sgo(function () { Redis::connection(); }); Redis::connection(); return ['release']; }
Only to use test. The wrong way to use it @RequestMapping("release") @return array @throws RedisException
release
php
swoft-cloud/swoft
app/Http/Controller/RedisController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/RedisController.php
Apache-2.0
public function exPipeline(): array { sgo(function () { Redis::pipeline(function () { throw new RuntimeException(''); }); }); Redis::pipeline(function () { throw new RuntimeException(''); }); return ['exPipeline']; }
Only to use test. The wrong way to use it @RequestMapping("ep") @return array
exPipeline
php
swoft-cloud/swoft
app/Http/Controller/RedisController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/RedisController.php
Apache-2.0
public function exTransaction(): array { sgo(function () { Redis::transaction(function () { throw new RuntimeException(''); }); }); Redis::transaction(function () { throw new RuntimeException(''); }); return ['exPipeline']; }
Only to use test. The wrong way to use it @RequestMapping("et") @return array
exTransaction
php
swoft-cloud/swoft
app/Http/Controller/RedisController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/RedisController.php
Apache-2.0
public function session(Response $response): Response { $sess = HttpSession::current(); $times = $sess->get('times', 0); $times++; $sess->set('times', $times); return $response->withData([ 'times' => $times, 'sessId' => $sess->getSessionId() ]); }
@RequestMapping("/session") @param Response $response @return Response
session
php
swoft-cloud/swoft
app/Http/Controller/SessionController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/SessionController.php
Apache-2.0
public function set(Response $response): Response { $sess = HttpSession::current(); $sess->set('testKey', 'test-value'); $sess->set('testKey1', ['k' => 'v', 'v1', 3]); return $response->withData(['testKey', 'testKey1']); }
@RequestMapping() @param Response $response @return Response
set
php
swoft-cloud/swoft
app/Http/Controller/SessionController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/SessionController.php
Apache-2.0
public function deleteByCo(): array { $data = Task::co('testTask', 'delete', [12]); if (is_bool($data)) { return ['bool']; } return ['notBool']; }
@RequestMapping(route="deleteByCo") @return array @throws TaskException
deleteByCo
php
swoft-cloud/swoft
app/Http/Controller/TaskController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/TaskController.php
Apache-2.0
public function deleteByAsync(): array { $data = Task::async('testTask', 'delete', [12]); return [$data]; }
@RequestMapping(route="deleteByAsync") @return array @throws TaskException
deleteByAsync
php
swoft-cloud/swoft
app/Http/Controller/TaskController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/TaskController.php
Apache-2.0
public function validateAll(Request $request): array { $method = $request->getMethod(); if ($method == RequestMethod::GET) { return $request->getParsedQuery(); } return $request->getParsedBody(); }
Verify all defined fields in the TestValidator validator @RequestMapping() @Validate(validator="TestValidator") @param Request $request @return array
validateAll
php
swoft-cloud/swoft
app/Http/Controller/ValidatorController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/ValidatorController.php
Apache-2.0
public function validateType(Request $request): array { $method = $request->getMethod(); if ($method == RequestMethod::GET) { return $request->getParsedQuery(); } return $request->getParsedBody(); }
Verify only the type field in the TestValidator validator @RequestMapping() @Validate(validator="TestValidator", fields={"type"}) @param Request $request @return array
validateType
php
swoft-cloud/swoft
app/Http/Controller/ValidatorController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/ValidatorController.php
Apache-2.0
public function validatePassword(Request $request): array { $method = $request->getMethod(); if ($method == RequestMethod::GET) { return $request->getParsedQuery(); } return $request->getParsedBody(); }
Verify only the password field in the TestValidator validator @RequestMapping() @Validate(validator="TestValidator", fields={"password"}) @param Request $request @return array
validatePassword
php
swoft-cloud/swoft
app/Http/Controller/ValidatorController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/ValidatorController.php
Apache-2.0
public function validateCustomer(Request $request): array { $method = $request->getMethod(); if ($method == RequestMethod::GET) { return $request->getParsedQuery(); } return $request->getParsedBody(); }
Customize the validator with userValidator @RequestMapping() @Validate(validator="userValidator") @param Request $request @return array
validateCustomer
php
swoft-cloud/swoft
app/Http/Controller/ValidatorController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/ValidatorController.php
Apache-2.0
public function index(Response $response): Response { $response = $response->withContent('<html lang="en"><h1>Swoft framework</h1></html>'); $response = $response->withContentType(ContentType::HTML); return $response; }
@RequestMapping("index") @param Response $response @return Response
index
php
swoft-cloud/swoft
app/Http/Controller/ViewController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/ViewController.php
Apache-2.0
public function indexByViewTag(): array { return [ 'msg' => 'hello' ]; }
Will render view by annotation tag View @RequestMapping("/home") @View("home/index") @throws Throwable
indexByViewTag
php
swoft-cloud/swoft
app/Http/Controller/ViewController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Controller/ViewController.php
Apache-2.0
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $uriPath = $request->getUriPath(); $domain = $request->getUri()->getHost(); if (!isset($this->domain2paths[$domain])) { return context()->getResponse()->withStatus(404)->withContent('invalid request domain'); } foreach ($this->domain2paths[$domain] as $prefix) { // not match route prefix if (strpos($uriPath, $prefix) !== 0) { return context()->getResponse()->withStatus(404)->withContent('page not found'); } } return $handler->handle($request); }
Process an incoming server request. @param ServerRequestInterface|Request $request @param RequestHandlerInterface $handler @return ResponseInterface @inheritdoc
process
php
swoft-cloud/swoft
app/Http/Middleware/DomainLimitMiddleware.php
https://github.com/swoft-cloud/swoft/blob/master/app/Http/Middleware/DomainLimitMiddleware.php
Apache-2.0
public function setId(?int $id): void { $this->id = $id; }
@param int|null $id @return void
setId
php
swoft-cloud/swoft
app/Model/Entity/Count.php
https://github.com/swoft-cloud/swoft/blob/master/app/Model/Entity/Count.php
Apache-2.0
public function setCreateTime(?int $createTime): void { $this->createTime = $createTime; }
@param int|null $createTime @return void
setCreateTime
php
swoft-cloud/swoft
app/Model/Entity/Count.php
https://github.com/swoft-cloud/swoft/blob/master/app/Model/Entity/Count.php
Apache-2.0
public function setAttributes(?string $attributes): void { $this->attributes = $attributes; }
@param string|null $attributes @return void
setAttributes
php
swoft-cloud/swoft
app/Model/Entity/Count.php
https://github.com/swoft-cloud/swoft/blob/master/app/Model/Entity/Count.php
Apache-2.0
public function setUpdateTime(?string $updateTime): void { $this->updateTime = $updateTime; }
@param string|null $updateTime @return void
setUpdateTime
php
swoft-cloud/swoft
app/Model/Entity/Count.php
https://github.com/swoft-cloud/swoft/blob/master/app/Model/Entity/Count.php
Apache-2.0
public function setTestJson(?array $testJson): void { $this->testJson = $testJson; }
@param array|null $testJson @return void
setTestJson
php
swoft-cloud/swoft
app/Model/Entity/User.php
https://github.com/swoft-cloud/swoft/blob/master/app/Model/Entity/User.php
Apache-2.0
public function func(): string { // Do something throw new Exception('Breaker exception'); }
@Breaker(fallback="funcFallback") @return string @throws Exception
func
php
swoft-cloud/swoft
app/Model/Logic/BreakerLogic.php
https://github.com/swoft-cloud/swoft/blob/master/app/Model/Logic/BreakerLogic.php
Apache-2.0
public function loop(): string { // Do something throw new Exception('Breaker exception'); }
@Breaker(fallback="loopFallback") @return string @throws Exception
loop
php
swoft-cloud/swoft
app/Model/Logic/BreakerLogic.php
https://github.com/swoft-cloud/swoft/blob/master/app/Model/Logic/BreakerLogic.php
Apache-2.0
public function loopFallback(): string { // Do something throw new Exception('Breaker exception'); }
@Breaker(fallback="loopFallback2") @return string @throws Exception
loopFallback
php
swoft-cloud/swoft
app/Model/Logic/BreakerLogic.php
https://github.com/swoft-cloud/swoft/blob/master/app/Model/Logic/BreakerLogic.php
Apache-2.0
public function loopFallback2(): string { // Do something throw new Exception('Breaker exception'); }
@Breaker(fallback="loopFallback3") @return string @throws Exception
loopFallback2
php
swoft-cloud/swoft
app/Model/Logic/BreakerLogic.php
https://github.com/swoft-cloud/swoft/blob/master/app/Model/Logic/BreakerLogic.php
Apache-2.0
public function run(Pool $pool, int $workerId): void { while (true) { CLog::info('worker-' . $workerId); Coroutine::sleep(3); } }
@param Pool $pool @param int $workerId
run
php
swoft-cloud/swoft
app/Process/Worker1Process.php
https://github.com/swoft-cloud/swoft/blob/master/app/Process/Worker1Process.php
Apache-2.0
public function run(Pool $pool, int $workerId): void { while (true) { // Database $user = User::find(1)->toArray(); CLog::info('user=' . json_encode($user)); // Redis Redis::set('test', 'ok'); CLog::info('test=' . Redis::get('test')); CLog::info('worker-' . $workerId . ' context=' . context()->getWorkerId()); Coroutine::sleep(3); } }
@param Pool $pool @param int $workerId @throws DbException
run
php
swoft-cloud/swoft
app/Process/Worker2Process.php
https://github.com/swoft-cloud/swoft/blob/master/app/Process/Worker2Process.php
Apache-2.0
public function process(RequestInterface $request, RequestHandlerInterface $requestHandler): ResponseInterface { return $requestHandler->handle($request); }
@param RequestInterface $request @param RequestHandlerInterface $requestHandler @return ResponseInterface
process
php
swoft-cloud/swoft
app/Rpc/Middleware/ServiceMiddleware.php
https://github.com/swoft-cloud/swoft/blob/master/app/Rpc/Middleware/ServiceMiddleware.php
Apache-2.0
public function getList(int $id, $type, int $count = 10): array { return ['name' => ['list']]; }
@param int $id @param mixed $type @param int $count @return array
getList
php
swoft-cloud/swoft
app/Rpc/Service/UserService.php
https://github.com/swoft-cloud/swoft/blob/master/app/Rpc/Service/UserService.php
Apache-2.0
public function test(string $name): string { return 'sync-test-' . $name; }
@TaskMapping() @param string $name @return string
test
php
swoft-cloud/swoft
app/Task/Task/SyncTask.php
https://github.com/swoft-cloud/swoft/blob/master/app/Task/Task/SyncTask.php
Apache-2.0
public function getList(int $id, string $default = 'def'): array { return [ 'list' => [1, 3, 3], 'id' => $id, 'default' => $default ]; }
@TaskMapping(name="list") @param int $id @param string $default @return array
getList
php
swoft-cloud/swoft
app/Task/Task/TestTask.php
https://github.com/swoft-cloud/swoft/blob/master/app/Task/Task/TestTask.php
Apache-2.0
public function delete(int $id): bool { if ($id > 10) { return true; } return false; }
@TaskMapping() @param int $id @return bool
delete
php
swoft-cloud/swoft
app/Task/Task/TestTask.php
https://github.com/swoft-cloud/swoft/blob/master/app/Task/Task/TestTask.php
Apache-2.0
public function returnNull(string $name) { return null; }
@TaskMapping() @param string $name @return null
returnNull
php
swoft-cloud/swoft
app/Task/Task/TestTask.php
https://github.com/swoft-cloud/swoft/blob/master/app/Task/Task/TestTask.php
Apache-2.0
public function list(Response $response): void { $response->setData('[list]allow command: list, echo, demo.echo'); }
@TcpMapping("list", root=true) @param Response $response
list
php
swoft-cloud/swoft
app/Tcp/Controller/DemoController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Tcp/Controller/DemoController.php
Apache-2.0
public function index(Request $request, Response $response): void { $str = $request->getPackage()->getDataString(); $response->setData('[demo.echo]hi, we received your message: ' . $str); }
@TcpMapping("echo") @param Request $request @param Response $response
index
php
swoft-cloud/swoft
app/Tcp/Controller/DemoController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Tcp/Controller/DemoController.php
Apache-2.0
public function strRev(Request $request, Response $response): void { $str = $request->getPackage()->getDataString(); $response->setData(strrev($str)); }
@TcpMapping("strrev", root=true) @param Request $request @param Response $response
strRev
php
swoft-cloud/swoft
app/Tcp/Controller/DemoController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Tcp/Controller/DemoController.php
Apache-2.0
public function echo(Request $request, Response $response): void { // $str = $request->getRawData(); $str = $request->getPackage()->getDataString(); $response->setData('[echo]hi, we received your message: ' . $str); }
@TcpMapping("echo", root=true) @param Request $request @param Response $response
echo
php
swoft-cloud/swoft
app/Tcp/Controller/DemoController.php
https://github.com/swoft-cloud/swoft/blob/master/app/Tcp/Controller/DemoController.php
Apache-2.0
public function process(RequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { $start = '>before '; CLog::info('before handle'); $resp = $handler->handle($request); $resp->setData($start . $resp->getData() . ' after>'); CLog::info('after handle'); return $resp; }
@param RequestInterface $request @param RequestHandlerInterface $handler @return ResponseInterface
process
php
swoft-cloud/swoft
app/Tcp/Middleware/DemoMiddleware.php
https://github.com/swoft-cloud/swoft/blob/master/app/Tcp/Middleware/DemoMiddleware.php
Apache-2.0
public function validate(array $data, array $params): array { $start = $data['start'] ?? null; $end = $data['end'] ?? null; if ($start === null && $end === null) { throw new ValidatorException('Start time and end time cannot be empty'); } if ($start > $end) { throw new ValidatorException('Start cannot be greater than the end time'); } return $data; }
@param array $data @param array $params @return array @throws ValidatorException
validate
php
swoft-cloud/swoft
app/Validator/CustomerValidator.php
https://github.com/swoft-cloud/swoft/blob/master/app/Validator/CustomerValidator.php
Apache-2.0
public function validate(array $data, string $propertyName, $item, $default = null, $strict = false): array { $message = $item->getMessage(); if (!isset($data[$propertyName]) && $default === null) { $message = (empty($message)) ? sprintf('%s must exist!', $propertyName) : $message; throw new ValidatorException($message); } $rule = '/^[A-Za-z0-9\-\_]+$/'; if (preg_match($rule, $data[$propertyName])) { return $data; } $message = (empty($message)) ? sprintf('%s must be a email', $propertyName) : $message; throw new ValidatorException($message); }
@param array $data @param string $propertyName @param object $item @param null $default @param bool $strict @return array @throws ValidatorException
validate
php
swoft-cloud/swoft
app/Validator/Rule/AlphaDashRule.php
https://github.com/swoft-cloud/swoft/blob/master/app/Validator/Rule/AlphaDashRule.php
Apache-2.0
public function onOpen(Request $request, int $fd): void { server()->push($request->getFd(), "Opened, welcome!(FD: $fd)"); $fullClass = Session::current()->getParserClass(); $className = basename($fullClass); $help = <<<TXT Message data parser: $className Send message example: ```json { "cmd": "home.index", "data": "hello" } ``` Description: - cmd `home.index` => App\WebSocket\Chat\HomeController::index() TXT; server()->push($fd, $help); }
@OnOpen() @param Request $request @param int $fd
onOpen
php
swoft-cloud/swoft
app/WebSocket/ChatModule.php
https://github.com/swoft-cloud/swoft/blob/master/app/WebSocket/ChatModule.php
Apache-2.0
public function onMessage(Server $server, Frame $frame): void { $server->push($frame->fd, 'Recv: ' . $frame->data); }
@OnMessage() @param Server $server @param Frame $frame
onMessage
php
swoft-cloud/swoft
app/WebSocket/EchoModule.php
https://github.com/swoft-cloud/swoft/blob/master/app/WebSocket/EchoModule.php
Apache-2.0
public function index(): void { Session::current()->push('hi, this is home.index'); }
Message command is: 'home.index' @return void @MessageMapping()
index
php
swoft-cloud/swoft
app/WebSocket/Chat/HomeController.php
https://github.com/swoft-cloud/swoft/blob/master/app/WebSocket/Chat/HomeController.php
Apache-2.0
public function echo(string $data): void { Session::current()->push('(home.echo)Recv: ' . $data); }
Message command is: 'home.echo' @param string $data @MessageMapping()
echo
php
swoft-cloud/swoft
app/WebSocket/Chat/HomeController.php
https://github.com/swoft-cloud/swoft/blob/master/app/WebSocket/Chat/HomeController.php
Apache-2.0
public function autoReply(string $data): string { return '(home.ar)Recv: ' . $data; }
Message command is: 'home.ar' @param string $data @MessageMapping("ar") @return string
autoReply
php
swoft-cloud/swoft
app/WebSocket/Chat/HomeController.php
https://github.com/swoft-cloud/swoft/blob/master/app/WebSocket/Chat/HomeController.php
Apache-2.0
public function help(string $data): string { return '(home.ar)Recv: ' . $data; }
Message command is: 'help' @param string $data @MessageMapping("help", root=true) @return string
help
php
swoft-cloud/swoft
app/WebSocket/Chat/HomeController.php
https://github.com/swoft-cloud/swoft/blob/master/app/WebSocket/Chat/HomeController.php
Apache-2.0
public function process(RequestInterface $request, MessageHandlerInterface $handler): ResponseInterface { $start = '>before '; CLog::info('before handle'); $resp = $handler->handle($request); $resp->setData($start . $resp->getData() . ' after>'); CLog::info('after handle'); return $resp; }
@param RequestInterface $request @param MessageHandlerInterface $handler @return ResponseInterface
process
php
swoft-cloud/swoft
app/WebSocket/Middleware/DemoMiddleware.php
https://github.com/swoft-cloud/swoft/blob/master/app/WebSocket/Middleware/DemoMiddleware.php
Apache-2.0
public function index(): void { Session::current()->push('hi, this is test.index'); }
Message command is: 'test.index' @return void @MessageMapping()
index
php
swoft-cloud/swoft
app/WebSocket/Test/TestController.php
https://github.com/swoft-cloud/swoft/blob/master/app/WebSocket/Test/TestController.php
Apache-2.0