File tree Expand file tree Collapse file tree 24 files changed +1269
-10
lines changed Expand file tree Collapse file tree 24 files changed +1269
-10
lines changed Original file line number Diff line number Diff line change 1
- /vendor
1
+ /vendor
2
+
3
+ /* /* .pid
4
+ /* /* .log
5
+ session_mm_ * .sem
Original file line number Diff line number Diff line change
1
+
2
+ default :
3
+ @echo " The following commands are available:"
4
+ @echo " "
5
+ @echo " make start start PHP built-in webserver"
6
+ @echo " make stop stop PHP built-in webserver"
7
+
8
+ # start PHP built-in webserver
9
+ start :
10
+ @echo " Starting server for api"
11
+ cd api && $(MAKE ) start
12
+ @echo " Starting server for backend"
13
+ cd backend && $(MAKE ) start
14
+
15
+ # stop PHP built-in webserver
16
+ stop :
17
+ cd api && $(MAKE ) stop
18
+ cd backend && $(MAKE ) stop
19
+
20
+ test :
21
+ cd api && $(MAKE ) test
22
+
23
+ clean : stop
24
+
25
+ .PHONY : start stop clean test
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ Yii Framework Application Template for quickly building API-first applications.
8
8
9
9
git clone https://github.com/cebe/yii2-app-api my-api
10
10
cd my-api
11
+ composer install
11
12
12
13
## Overview
13
14
Original file line number Diff line number Diff line change
1
+ # additional arguments to PHP binary
2
+ PHPARGS =
3
+ # enable XDEBUG for the test runner
4
+ XDEBUG =0
5
+ # enable XDEBUG for the webserver
6
+ XDEBUGW =0
7
+
8
+ WEBPORT =8337
9
+
10
+ ifeq ($(XDEBUG ) ,1)
11
+ XDEBUGARGS=-dzend_extension =xdebug.so -dxdebug.remote_enable=1
12
+ endif
13
+ ifeq ($(XDEBUGW ) ,1)
14
+ XDEBUGARGSW=-dzend_extension =xdebug.so -dxdebug.remote_enable=1
15
+ endif
16
+
17
+
18
+ current_dir =$(shell pwd)
19
+
20
+ default :
21
+
22
+ start : stop
23
+ @echo " Starting PHP webserver at http://localhost:$( WEBPORT) , see php.log for access log."
24
+ @echo " "
25
+ @echo " Run make stop to stop it."
26
+ @echo " "
27
+ YII_ENV=dev php $(PHPARGS ) $(XDEBUGARGSW ) -S localhost:$(WEBPORT ) -t web $(current_dir ) /router.php > php.log 2>&1 & echo " $$ !" > php.pid
28
+
29
+ stop :
30
+ @echo " Stopping PHP webserver..."
31
+ @-if [ -f php.pid ] ; then kill $$(cat php.pid ) ; fi
32
+ @rm -f php.pid
33
+ @rm -f session_mm_* .sem
34
+
35
+ clean : stop
36
+ rm -f php.log
37
+
38
+ .PHONY : start stop clean
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ if (getenv ('YII_ENV ' )) {
4
+ define ('YII_ENV ' , getenv ('YII_ENV ' ));
5
+ define ('YII_DEBUG ' , YII_ENV !== 'prod ' );
6
+ }
7
+
8
+ list ($ pathInfo ) = explode ('? ' , $ _SERVER ["REQUEST_URI " ], 2 );
9
+
10
+ if (is_file (__DIR__ . '/web/ ' . ltrim ($ pathInfo , '/ ' ))) {
11
+ return false ;
12
+ } else {
13
+ $ _SERVER ['SCRIPT_NAME ' ] = '/index.php ' ;
14
+ $ _SERVER ['PHP_SELF ' ] = '/index.php ' ;
15
+ $ _SERVER ['SCRIPT_FILENAME ' ] = __DIR__ . '/web/index.php ' ;
16
+ include __DIR__ . '/web/index.php ' ;
17
+ }
Original file line number Diff line number Diff line change
1
+ # additional arguments to PHP binary
2
+ PHPARGS =
3
+ # enable XDEBUG for the test runner
4
+ XDEBUG =0
5
+ # enable XDEBUG for the webserver
6
+ XDEBUGW =0
7
+
8
+ WEBPORT =8338
9
+
10
+ ifeq ($(XDEBUG ) ,1)
11
+ XDEBUGARGS=-dzend_extension =xdebug.so -dxdebug.remote_enable=1
12
+ endif
13
+ ifeq ($(XDEBUGW ) ,1)
14
+ XDEBUGARGSW=-dzend_extension =xdebug.so -dxdebug.remote_enable=1
15
+ endif
16
+
17
+
18
+ current_dir =$(shell pwd)
19
+
20
+ default :
21
+
22
+ start : stop
23
+ @echo " Starting PHP webserver at http://localhost:$( WEBPORT) , see php.log for access log."
24
+ @echo " "
25
+ @echo " Run make stop to stop it."
26
+ @echo " "
27
+ YII_ENV=dev php $(PHPARGS ) $(XDEBUGARGSW ) -S localhost:$(WEBPORT ) -t web $(current_dir ) /router.php > php.log 2>&1 & echo " $$ !" > php.pid
28
+
29
+ stop :
30
+ @echo " Stopping PHP webserver..."
31
+ @-if [ -f php.pid ] ; then kill $$(cat php.pid ) ; fi
32
+ @rm -f php.pid
33
+ @rm -f session_mm_* .sem
34
+
35
+ clean : stop
36
+ rm -f php.log
37
+
38
+ .PHONY : start stop clean
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /**
4
+ * Main configuration file for the backend application.
5
+ *
6
+ * Develop environment.
7
+ */
8
+
9
+ $ config = array_merge (require (__DIR__ . '/app.php ' ), [
10
+ 'components ' => array_merge (
11
+ require __DIR__ . '/../../config/components.php ' , // common config
12
+ require __DIR__ . '/../../config/components-dev.php ' , // common config (env overrides)
13
+ require __DIR__ . '/components.php ' // backend specific config
14
+ ),
15
+ ]);
16
+
17
+ // enable Gii module
18
+ $ config ['bootstrap ' ][] = 'gii ' ;
19
+ $ config ['modules ' ]['gii ' ] = [
20
+ 'class ' => yii \gii \Module::class,
21
+ 'generators ' => [
22
+ // add ApiGenerator to Gii module
23
+ 'api ' => \cebe \yii2openapi \generator \ApiGenerator::class,
24
+ ],
25
+ ];
26
+
27
+ return $ config ;
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /**
4
+ * Main configuration file for the backend application.
5
+ *
6
+ * Production environment.
7
+ */
8
+
9
+ return array_merge (require (__DIR__ . '/app.php ' ), [
10
+ 'components ' => array_merge (
11
+ require __DIR__ . '/../../config/components.php ' , // common config
12
+ require __DIR__ . '/../../config/components-prod.php ' , // common config (env overrides)
13
+ require __DIR__ . '/components.php ' // backend specific config
14
+ ),
15
+ ]);
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /**
4
+ * Main configuration file for the backend application.
5
+ *
6
+ * Test environment.
7
+ */
8
+
9
+ return array_merge (require (__DIR__ . '/app.php ' ), [
10
+ 'components ' => array_merge (
11
+ require __DIR__ . '/../../config/components.php ' , // common config
12
+ require __DIR__ . '/../../config/components-test.php ' , // common config (env overrides)
13
+ require __DIR__ . '/components.php ' // backend specific config
14
+ ),
15
+ ]);
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /**
4
+ * Main configuration file for the backend application.
5
+ */
6
+
7
+ return [
8
+ 'id ' => 'backend ' ,
9
+
10
+ 'basePath ' => dirname (__DIR__ ),
11
+ 'vendorPath ' => dirname (__DIR__ , 2 ) . '/vendor ' ,
12
+ 'runtimePath ' => dirname (__DIR__ , 2 ) . '/runtime/backend ' ,
13
+ 'aliases ' => [
14
+ '@bower ' => '@vendor/bower-asset ' ,
15
+ '@npm ' => '@vendor/npm-asset ' ,
16
+ ],
17
+ 'controllerNamespace ' => 'backend\controllers ' ,
18
+
19
+ 'bootstrap ' => ['log ' ],
20
+
21
+ 'params ' => require (__DIR__ . '/../../config/params.php ' ),
22
+ ];
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ /**
4
+ * component configuration overrides for the backend application.
5
+ */
6
+
7
+ return [
8
+ 'request ' => [
9
+ 'cookieValidationKey ' => 'api1337 ' , // TODO this should be dynamic
10
+ ],
11
+
12
+ 'urlManager ' => [
13
+ 'enablePrettyUrl ' => true ,
14
+ 'enableStrictParsing ' => true ,
15
+ 'showScriptName ' => false ,
16
+ 'rules ' => require (__DIR__ . '/url-rules.php ' ),
17
+ ],
18
+ 'log ' => [
19
+ 'traceLevel ' => YII_DEBUG ? 3 : 0 ,
20
+ 'targets ' => [
21
+ [
22
+ 'class ' => yii \log \FileTarget::class,
23
+ 'levels ' => ['error ' , 'warning ' ],
24
+ 'logFile ' => '@logs/backend-app.error.log ' ,
25
+ 'except ' => [
26
+ 'yii\web\HttpException* ' ,
27
+ ],
28
+ ],
29
+ [
30
+ 'class ' => yii \log \FileTarget::class,
31
+ 'levels ' => ['error ' , 'warning ' ],
32
+ 'logFile ' => '@logs/backend-http.error.log ' ,
33
+ 'categories ' => [
34
+ 'yii\web\HttpException* ' ,
35
+ ],
36
+ ],
37
+ [
38
+ 'class ' => yii \log \FileTarget::class,
39
+ 'levels ' => ['info ' ],
40
+ 'logFile ' => '@logs/backend-app.info.log ' ,
41
+ 'logVars ' => [],
42
+ 'except ' => [
43
+ 'yii\db\* ' ,
44
+ ],
45
+ ],
46
+ ],
47
+ ],
48
+ ];
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ // TODO configure URL rules with autogenerated spec rules
4
+
5
+ return [
6
+ '' => 'site/index ' ,
7
+ ];
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace backend \controllers ;
4
+
5
+ use yii \web \Controller ;
6
+
7
+ /**
8
+ *
9
+ */
10
+ class SiteController extends Controller
11
+ {
12
+ public function actionIndex ()
13
+ {
14
+ return $ this ->render ('index ' );
15
+ }
16
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ if (getenv ('YII_ENV ' )) {
4
+ define ('YII_ENV ' , getenv ('YII_ENV ' ));
5
+ define ('YII_DEBUG ' , YII_ENV !== 'prod ' );
6
+ }
7
+
8
+ list ($ pathInfo ) = explode ('? ' , $ _SERVER ["REQUEST_URI " ], 2 );
9
+
10
+ if (is_file (__DIR__ . '/web/ ' . ltrim ($ pathInfo , '/ ' ))) {
11
+ return false ;
12
+ } else {
13
+ $ _SERVER ['SCRIPT_NAME ' ] = '/index.php ' ;
14
+ $ _SERVER ['PHP_SELF ' ] = '/index.php ' ;
15
+ $ _SERVER ['SCRIPT_FILENAME ' ] = __DIR__ . '/web/index.php ' ;
16
+ include __DIR__ . '/web/index.php ' ;
17
+ }
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use yii \helpers \Html ;
4
+
5
+ /** @var $this \yii\web\View */
6
+ /** @var $content string */
7
+
8
+ ?>
9
+ <?php $ this ->beginPage () ?>
10
+ <!DOCTYPE html>
11
+ <html lang="<?= Yii::$ app ->language ?> ">
12
+ <head>
13
+ <meta charset="<?= Yii::$ app ->charset ?> "/>
14
+ <meta name="viewport" content="width=device-width, initial-scale=1">
15
+ <?= Html::csrfMetaTags () ?>
16
+ <title><?= Html::encode (empty ($ this ->title ) ? '' : $ this ->title . ' - ' ) ?> </title>
17
+ <?php $ this ->head () ?>
18
+ </head>
19
+ <body>
20
+ <?php $ this ->beginBody () ?>
21
+
22
+ <div class="wrap">
23
+ <?= $ content ?>
24
+ </div>
25
+
26
+ <?php $ this ->endBody () ?>
27
+ </body>
28
+ </html>
29
+ <?php $ this ->endPage () ?>
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use yii \helpers \Html ;
4
+
5
+ /** @var $this \yii\web\View */
6
+
7
+ ?>
8
+ <h1>API Backend</h1>
9
+
10
+ Go to <?= Html::a ('/gii ' , ['/gii ' ]) ?> to generate an API from OpenAPI spec.
Original file line number Diff line number Diff line change
1
+ RewriteEngine on
2
+ # If a directory or a file exists, use the request directly
3
+ RewriteCond %{REQUEST_FILENAME} !-f
4
+ RewriteCond %{REQUEST_FILENAME} !-d
5
+ # Otherwise forward the request to index.php
6
+ RewriteRule . index.php
Original file line number Diff line number Diff line change
1
+ *
2
+ ! .gitignore
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ require (__DIR__ . '/../../config/env.php ' );
4
+
5
+ $ config = require (__DIR__ . '/../config/app- ' . YII_ENV . '.php ' );
6
+
7
+ $ app = new yii \web \Application ($ config );
8
+ $ app ->run ();
Original file line number Diff line number Diff line change
1
+ User-agent: *
2
+ Disallow: /
You can’t perform that action at this time.
0 commit comments