Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
cabal-php committed Apr 18, 2018
1 parent 9234fd0 commit ec211e0
Show file tree
Hide file tree
Showing 14 changed files with 294 additions and 5 deletions.
15 changes: 10 additions & 5 deletions .gitignore
@@ -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
61 changes: 61 additions & 0 deletions bin/cabal
@@ -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
31 changes: 31 additions & 0 deletions bin/cabal-listen
@@ -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

6 changes: 6 additions & 0 deletions bin/cabal.php
@@ -0,0 +1,6 @@
<?php
require __DIR__ . '/../vendor/autoload.php';

require __DIR__ . '/../usr/boot.php';

$boot->start();
29 changes: 29 additions & 0 deletions composer.json
@@ -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"
}
}
}
8 changes: 8 additions & 0 deletions conf/cabal.php
@@ -0,0 +1,8 @@
<?php

return [
'host' => '0.0.0.0',
'port' => '9501',

'swoole' => [],
];
20 changes: 20 additions & 0 deletions conf/db.php
@@ -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',
],
];
13 changes: 13 additions & 0 deletions conf/dev/cabal.php
@@ -0,0 +1,13 @@
<?php

return [
'debug' => true,

'host' => '127.0.0.1',
'port' => '9501',

'swoole' => [
'daemonize' => 0,
'worker_num' => 1,
],
];
1 change: 1 addition & 0 deletions lib/functions.php
@@ -0,0 +1 @@
<?php
18 changes: 18 additions & 0 deletions usr/App/Controller/DemoController.php
@@ -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,
];
}
}
14 changes: 14 additions & 0 deletions usr/boot.php
@@ -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'));

30 changes: 30 additions & 0 deletions usr/routes.php
@@ -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');
});
2 changes: 2 additions & 0 deletions var/log/.gitignore
@@ -0,0 +1,2 @@
*
!.gitignore
51 changes: 51 additions & 0 deletions var/template/home.php
@@ -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>

0 comments on commit ec211e0

Please sign in to comment.