Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
294 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
composer.phar | ||
/composer.lock | ||
/.idea | ||
/vendor/ | ||
|
||
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file | ||
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file | ||
# composer.lock | ||
/test/ | ||
/*.php | ||
.DS_Store | ||
/docs/ | ||
sync.sh | ||
/var/*.pid | ||
/var/*.log | ||
*.bak |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#! /bin/bash | ||
scriptDir="$( cd "$( dirname "$0" )" && pwd )" | ||
|
||
DESC="cabal daemon" | ||
NAME=CabalServer | ||
|
||
PHP_PATH=php | ||
BIN_PATH=$scriptDir | ||
PIDFILE=$scriptDir/../var/cabal.pid | ||
RUN_ENV= | ||
|
||
while getopts f:e: OPTION | ||
do | ||
case $OPTION in | ||
e) | ||
RUN_ENV="-e $OPTARG" | ||
;; | ||
\?) | ||
echo "error params $OPTARG" | ||
;; | ||
esac | ||
done | ||
do_start() { | ||
|
||
$PHP_PATH $BIN_PATH/cabal.php $RUN_ENV || echo -n "$NAME already running" | ||
} | ||
do_stop() { | ||
kill -TERM `cat $PIDFILE` || echo -n "$NAME not running" | ||
} | ||
do_reload() { | ||
kill -USR1 `cat $PIDFILE` || echo -n "$NAME can't reload" | ||
} | ||
case "${!#}" in | ||
start) | ||
echo -n "Starting $NAME" | ||
do_start | ||
echo "." | ||
;; | ||
stop) | ||
echo -n "Stopping $NAME" | ||
do_stop | ||
echo "." | ||
;; | ||
reload|graceful) | ||
echo -n "Reloading configuration..." | ||
do_reload | ||
echo "." | ||
;; | ||
restart) | ||
echo -n "Restarting $NAME" | ||
do_stop | ||
sleep 1 | ||
do_start | ||
echo "." | ||
;; | ||
*) | ||
echo "Usage: $SCRIPTNAME [-e env] {start|stop|reload|restart}" >&2 | ||
exit 3 | ||
;; | ||
esac | ||
exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#! /bin/bash | ||
|
||
scriptDir="$( cd "$( dirname "$0" )" && pwd )" | ||
|
||
PID_FILE=$scriptDir/../var/cabal.pid | ||
|
||
if [ -e $PID_FILE ] | ||
then | ||
cabal_pid=`cat $PID_FILE` | ||
echo "kill ${cabal_pid}" | ||
kill -9 $cabal_pid | ||
fi | ||
echo "start server..." | ||
|
||
$scriptDir/cabal -e dev start & | ||
|
||
sleep 1 | ||
echo "watching files..." | ||
fswatch $scriptDir/../ -i "*\\.php" | while read file | ||
do | ||
if [[ "$file" =~ .*\.php$ ]] | ||
then | ||
if [ -e $PID_FILE ] | ||
then | ||
cabal_pid=`cat $PID_FILE` | ||
echo "${file} changes, reload server." | ||
kill -USR1 $cabal_pid | ||
fi | ||
fi | ||
done | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?php | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
require __DIR__ . '/../usr/boot.php'; | ||
|
||
$boot->start(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "cabalphp/cabal-skeleton", | ||
"type": "project", | ||
"license": "Apache-2.0", | ||
"authors": [ | ||
{ | ||
"name": "keefe", | ||
"email": "keefe.wu@outlook.com" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"App\\": "usr/App" | ||
} | ||
}, | ||
"require": { | ||
"php": "^7.0.0", | ||
"ext-swoole": "^2.0.0", | ||
"cabalphp/cabal-core": "^0.1", | ||
"cabalphp/cabal-db": "^0.1", | ||
"league/plates": "^3.3" | ||
}, | ||
"repositories": { | ||
"packagist": { | ||
"type": "composer", | ||
"url": "https://packagist.org" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
|
||
return [ | ||
'host' => '0.0.0.0', | ||
'port' => '9501', | ||
|
||
'swoole' => [], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
return [ | ||
'default' => 'mysql', | ||
|
||
'mysql' => [ | ||
// 'read' => [ | ||
// 'host' => ['127.0.0.1', 'localhost', '0.0.0.0'], | ||
// 'user' => 'readonly', | ||
// ], | ||
// 'write' => [ | ||
// 'user' => 'root', | ||
// ], | ||
'user' => 'root', | ||
'host' => '127.0.0.1', | ||
'port' => '3306', | ||
'password' => '123456', | ||
'database' => 'cabal_demo', | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
return [ | ||
'debug' => true, | ||
|
||
'host' => '127.0.0.1', | ||
'port' => '9501', | ||
|
||
'swoole' => [ | ||
'daemonize' => 0, | ||
'worker_num' => 1, | ||
], | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
namespace App\Controller; | ||
|
||
use Cabal\Core\Http\Server; | ||
use Cabal\Core\Http\Response; | ||
use Cabal\Core\Http\Request; | ||
|
||
class DemoController | ||
{ | ||
public function getTest(Server $server, Request $request, $var = []) | ||
{ | ||
return [ | ||
'action' => __METHOD__, | ||
'input' => $request->all(), | ||
'var' => $var, | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
|
||
class Boot extends Cabal\Core\Application\Boot | ||
{ | ||
use Cabal\Core\Http\Boot\HasPlates; | ||
use Cabal\DB\Boot\HasDB; | ||
use Cabal\Core\Cache\Boot\HasCache; | ||
} | ||
|
||
$options = getopt('e:'); | ||
$boot = new Boot(dirname(__DIR__), array_get($options, 'e')); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
use Cabal\Core\Http\Server; | ||
use Cabal\Core\Http\Response; | ||
use Cabal\Core\Http\Request; | ||
|
||
/** | ||
* @var \Cabal\Core\Application\Dispatcher $route | ||
*/ | ||
/** | ||
* @var \Cabal\Route\RouteCollection $dispatcher | ||
*/ | ||
|
||
|
||
$route->get('/', function (Server $server, Request $request, $vars = []) { | ||
$response = new Response(); | ||
$response->getBody() | ||
->write( | ||
$server->boot() | ||
->plates() | ||
->render('home', ['version' => $server->boot()->version()]) | ||
); | ||
return $response; | ||
}); | ||
|
||
$route->group([ | ||
'namespace' => 'App\Controller', | ||
], function ($route) { | ||
$route->get('/test/{id:\d+}', 'DemoController@getTest'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<!DOCTYPE html> | ||
<html lang="zh-CN"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
<meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
<title>CabalPHP - 基于Swoole的稳定、轻量、高效、全异步开源框架。</title> | ||
<style> | ||
|
||
body,html{width:100%;height:100%;background:#fff;margin:0;padding:0;color:#34495e;font:15px/2 Source Sans Pro,Helvetica Neue,Arial,sans-serif} | ||
a{color:#34495e;text-decoration:none} | ||
.main{width:100%;height:100%;text-align:center;background:linear-gradient(to left bottom,hsl(153, 100%, 85%) 0%,hsl(198, 100%, 85%) 100%)} | ||
.main h1,.main p{margin:0;padding:0} | ||
.main h1{font-weight:300;font-size:2.5rem;position:relative;padding-top:150px} | ||
.main h1 small{bottom:-.4375rem;font-size:1rem;position:absolute} | ||
.main blockquote{font-size:1.5rem} | ||
.main ul{list-style:none;margin:0;padding:0 0 30px} | ||
.main a.cabal,.main a.github{border:1px solid #42b983;border-radius:2rem;box-sizing:border-box;color:#42b983;display:inline-block;font-size:1.05rem;letter-spacing:.1rem;margin:.5rem 1rem;padding:.75em 2rem;text-decoration:none;transition:all .15s ease;width:175px} | ||
.main a.cabal{background-color:#42b983;color:#fff} | ||
@media screen and (max-width: 500px) {.main ul {display: none;}.main h1{padding-top: 50px;}} | ||
</style> | ||
</head> | ||
|
||
<body> | ||
<div class="main"> | ||
<h1> | ||
<a href="/" data-id="cabalphp-alphalpha" class="anchor"> | ||
<span> | ||
CabalPHP | ||
<small><?= $version; ?></small> | ||
</span> | ||
</a> | ||
</h1> | ||
<blockquote> | ||
<p>是一个基于Swoole的 | ||
<strong>稳定、轻量、高效、全异步</strong>开源框架</p> | ||
</blockquote> | ||
<ul> | ||
<li></li> | ||
<li>尤其适合前后端分离的API架构和微服务架构</li> | ||
<li>易于学习,开发效率高</li> | ||
<li>使用IDE(Sublime Text/VSCode/PhpStorm等)有<strong>完整的代码提示</strong>!</li> | ||
<li>支持HTTP、TCP、websocket等多种协议</li> | ||
</ul> | ||
<p> | ||
<a class="github" href="https://github.com/cabalphp/cabal-skeleton/" target="_blank">GitHub</a> | ||
<a class="cabal" href="https://www.cabalphp.com" target="_blank">Get Started</a> | ||
</p> | ||
</div> | ||
</body> | ||
</html> |