-
Notifications
You must be signed in to change notification settings - Fork 12
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
ywisax
committed
Nov 14, 2016
0 parents
commit 9a40585
Showing
45 changed files
with
3,081 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.idea/ | ||
vendor/ | ||
composer.lock |
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,3 @@ | ||
# workerman-yii2 | ||
|
||
使用 workerman 实现一个能运行 Yii2 的 HTTP Server. |
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 @@ | ||
{ | ||
"name": "tourze/swoole-yii2", | ||
"authors": [ | ||
{ | ||
"name": "tourze", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"minimum-stability": "stable", | ||
"require": { | ||
"php": ">=5.6.0", | ||
"workerman/workerman": "^3.3.4", | ||
"yiisoft/yii2": "^2.0", | ||
"yiisoft/yii2-bootstrap": "~2.0.0", | ||
"yiisoft/yii2-swiftmailer": "~2.0.0", | ||
"yiisoft/yii2-redis": "^2.0", | ||
"pbweb/xhprof": "^1.0" | ||
}, | ||
"require-dev": { | ||
"yiisoft/yii2-debug": "~2.0.0", | ||
"yiisoft/yii2-gii": "~2.0.0", | ||
"yiisoft/yii2-faker": "~2.0.0", | ||
"codeception/base": "^2.2.3", | ||
"codeception/verify": "~0.3.1" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"tourze\\workerman\\yii2\\": "src" | ||
} | ||
} | ||
} |
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,3 @@ | ||
<?php | ||
|
||
Yii::setAlias('@demo', realpath(__DIR__ . '/../')); |
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,70 @@ | ||
<?php | ||
|
||
$params = require(__DIR__ . '/params.php'); | ||
|
||
$config = [ | ||
'id' => 'basic', | ||
'basePath' => dirname(__DIR__), | ||
'vendorPath' => realpath(__DIR__ . '/../../vendor'), | ||
'bootstrap' => ['log'], | ||
'controllerNamespace' => 'demo\controllers', | ||
'components' => [ | ||
'request' => [ | ||
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation | ||
'cookieValidationKey' => 'test', | ||
], | ||
'cache' => [ | ||
'class' => 'yii\caching\FileCache', | ||
], | ||
'user' => [ | ||
'identityClass' => 'app\models\User', | ||
'enableAutoLogin' => true, | ||
], | ||
'errorHandler' => [ | ||
'errorAction' => 'site/error', | ||
], | ||
'mailer' => [ | ||
'class' => 'yii\swiftmailer\Mailer', | ||
// send all mails to a file by default. You have to set | ||
// 'useFileTransport' to false and configure a transport | ||
// for the mailer to send real emails. | ||
'useFileTransport' => true, | ||
], | ||
'log' => [ | ||
'traceLevel' => YII_DEBUG ? 3 : 0, | ||
'targets' => [ | ||
[ | ||
'class' => 'yii\log\FileTarget', | ||
'levels' => ['error', 'warning'], | ||
], | ||
], | ||
], | ||
'db' => require(__DIR__ . '/db.php'), | ||
'redis' => [ | ||
'class' => 'yii\redis\Connection', | ||
'hostname' =>'127.0.0.1', | ||
'database' => 8, | ||
], | ||
'urlManager' => [ | ||
'enablePrettyUrl' => true, | ||
'showScriptName' => false, | ||
'rules' => [], | ||
], | ||
], | ||
'params' => $params, | ||
]; | ||
|
||
if (YII_ENV_DEV) { | ||
// configuration adjustments for 'dev' environment | ||
$config['bootstrap'][] = 'debug'; | ||
$config['modules']['debug'] = [ | ||
'class' => 'yii\debug\Module', | ||
]; | ||
|
||
$config['bootstrap'][] = 'gii'; | ||
$config['modules']['gii'] = [ | ||
'class' => 'yii\gii\Module', | ||
]; | ||
} | ||
|
||
return $config; |
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,9 @@ | ||
<?php | ||
|
||
return [ | ||
'class' => 'yii\db\Connection', | ||
'dsn' => 'mysql:host=localhost;dbname=yii2advanced', | ||
'username' => 'root', | ||
'password' => 'root', | ||
'charset' => 'utf8', | ||
]; |
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,5 @@ | ||
<?php | ||
|
||
return [ | ||
'adminEmail' => '[email protected]', | ||
]; |
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,45 @@ | ||
<?php | ||
|
||
namespace demo\controllers; | ||
|
||
use demo\models\User; | ||
use Yii; | ||
use yii\web\Controller; | ||
use yii\web\Response; | ||
|
||
/** | ||
* API相关的测试控制器 | ||
* | ||
* @package demo\controllers | ||
*/ | ||
class ApiController extends Controller | ||
{ | ||
|
||
/** | ||
* 返回json | ||
* | ||
* @return array | ||
*/ | ||
public function actionJson() | ||
{ | ||
Yii::$app->response->format = Response::FORMAT_JSON; | ||
return ['time' => time(), 'str' => 'hello']; | ||
} | ||
|
||
/** | ||
* 查找所有用户 | ||
*/ | ||
public function actionGetUsers() | ||
{ | ||
Yii::$app->response->format = Response::FORMAT_JSON; | ||
$rs = []; | ||
|
||
/** @var User[] $users */ | ||
$users = User::find()->all(); | ||
foreach ($users as $user) | ||
{ | ||
$rs[] = $user->toArray(); | ||
} | ||
return $rs; | ||
} | ||
} |
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 | ||
|
||
namespace demo\controllers; | ||
|
||
use Yii; | ||
use yii\web\Controller; | ||
|
||
class SiteController extends Controller | ||
{ | ||
|
||
public function actionIndex() | ||
{ | ||
return $this->render('index'); | ||
} | ||
|
||
public function actionError() | ||
{ | ||
return (string) Yii::$app->errorHandler->exception; | ||
} | ||
} |
Binary file not shown.
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 @@ | ||
<?php | ||
|
||
use tourze\workerman\yii2\server\HttpServer; | ||
|
||
defined('YII_DEBUG') or define('YII_DEBUG', false); | ||
defined('YII_ENV') or define('YII_ENV', 'prod'); | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; | ||
require_once __DIR__ . '/../vendor/yiisoft/yii2/Yii.php'; | ||
|
||
/** @var HttpServer $server */ | ||
$server = new HttpServer; | ||
$server->run([ | ||
'host' => '127.0.0.1', | ||
'port' => '6688', | ||
'root' => __DIR__, | ||
'xhprofDebug' => false, | ||
// bootstrap文件, 只会引入一次 | ||
'bootstrapFile' => [ | ||
__DIR__ . '/config/aliases.php', | ||
], | ||
// Yii的配置文件, 只会引入一次 | ||
'configFile' => [ | ||
__DIR__ . '/config/config.php', | ||
], | ||
// 有一些模块比较特殊, 无法实现Refreshable接口, 此时唯有在这里指定他的类名 | ||
'bootstrapRefresh' => [], | ||
'server' => [ | ||
'count' => 4, | ||
], | ||
]); |
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,17 @@ | ||
<?php | ||
|
||
namespace demo\models; | ||
|
||
use yii\db\ActiveRecord; | ||
|
||
class User extends ActiveRecord | ||
{ | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public static function tableName() | ||
{ | ||
return '{{%user_user}}'; | ||
} | ||
} |
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,77 @@ | ||
<?php | ||
|
||
/* @var $this \yii\web\View */ | ||
/* @var $content string */ | ||
|
||
use yii\helpers\Html; | ||
use yii\bootstrap\Nav; | ||
use yii\bootstrap\NavBar; | ||
use yii\widgets\Breadcrumbs; | ||
|
||
?> | ||
<?php $this->beginPage() ?> | ||
<!DOCTYPE html> | ||
<html lang="<?= Yii::$app->language ?>"> | ||
<head> | ||
<meta charset="<?= Yii::$app->charset ?>"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<?= Html::csrfMetaTags() ?> | ||
<title><?= Html::encode($this->title) ?></title> | ||
<?php $this->head() ?> | ||
</head> | ||
<body> | ||
<?php $this->beginBody() ?> | ||
|
||
<div class="wrap"> | ||
<?php | ||
NavBar::begin([ | ||
'brandLabel' => 'My Company', | ||
'brandUrl' => Yii::$app->homeUrl, | ||
'options' => [ | ||
'class' => 'navbar-inverse navbar-fixed-top', | ||
], | ||
]); | ||
echo Nav::widget([ | ||
'options' => ['class' => 'navbar-nav navbar-right'], | ||
'items' => [ | ||
['label' => 'Home', 'url' => ['/site/index']], | ||
['label' => 'About', 'url' => ['/site/about']], | ||
['label' => 'Contact', 'url' => ['/site/contact']], | ||
Yii::$app->user->isGuest ? ( | ||
['label' => 'Login', 'url' => ['/site/login']] | ||
) : ( | ||
'<li>' | ||
. Html::beginForm(['/site/logout'], 'post') | ||
. Html::submitButton( | ||
'Logout (' . Yii::$app->user->identity->username . ')', | ||
['class' => 'btn btn-link logout'] | ||
) | ||
. Html::endForm() | ||
. '</li>' | ||
) | ||
], | ||
]); | ||
NavBar::end(); | ||
?> | ||
|
||
<div class="container"> | ||
<?= Breadcrumbs::widget([ | ||
'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [], | ||
]) ?> | ||
<?= $content ?> | ||
</div> | ||
</div> | ||
|
||
<footer class="footer"> | ||
<div class="container"> | ||
<p class="pull-left">© My Company <?= date('Y') ?></p> | ||
|
||
<p class="pull-right"><?= Yii::powered() ?></p> | ||
</div> | ||
</footer> | ||
|
||
<?php $this->endBody() ?> | ||
</body> | ||
</html> | ||
<?php $this->endPage() ?> | ||
|
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,53 @@ | ||
<?php | ||
|
||
/* @var $this yii\web\View */ | ||
|
||
$this->title = 'My Yii Application'; | ||
?> | ||
<div class="site-index"> | ||
|
||
<div class="jumbotron"> | ||
<h1>Congratulations!</h1> | ||
|
||
<p class="lead">You have successfully created your Yii-powered application.</p> | ||
|
||
<p><a class="btn btn-lg btn-success" href="http://www.yiiframework.com">Get started with Yii</a></p> | ||
</div> | ||
|
||
<div class="body-content"> | ||
|
||
<div class="row"> | ||
<div class="col-lg-4"> | ||
<h2>Heading</h2> | ||
|
||
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et | ||
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip | ||
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu | ||
fugiat nulla pariatur.</p> | ||
|
||
<p><a class="btn btn-default" href="http://www.yiiframework.com/doc/">Yii Documentation »</a></p> | ||
</div> | ||
<div class="col-lg-4"> | ||
<h2>Heading</h2> | ||
|
||
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et | ||
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip | ||
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu | ||
fugiat nulla pariatur.</p> | ||
|
||
<p><a class="btn btn-default" href="http://www.yiiframework.com/forum/">Yii Forum »</a></p> | ||
</div> | ||
<div class="col-lg-4"> | ||
<h2>Heading</h2> | ||
|
||
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et | ||
dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip | ||
ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu | ||
fugiat nulla pariatur.</p> | ||
|
||
<p><a class="btn btn-default" href="http://www.yiiframework.com/extensions/">Yii Extensions »</a></p> | ||
</div> | ||
</div> | ||
|
||
</div> | ||
</div> |
Oops, something went wrong.