Skip to content

Commit 50ad603

Browse files
committed
added backend application and Gii
1 parent fd0ae1f commit 50ad603

24 files changed

+1269
-10
lines changed

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1-
/vendor
1+
/vendor
2+
3+
/*/*.pid
4+
/*/*.log
5+
session_mm_*.sem

Makefile

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
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

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Yii Framework Application Template for quickly building API-first applications.
88

99
git clone https://github.com/cebe/yii2-app-api my-api
1010
cd my-api
11+
composer install
1112

1213
## Overview
1314

api/Makefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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

api/router.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
}

backend/Makefile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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

backend/config/app-dev.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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;

backend/config/app-prod.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
]);

backend/config/app-test.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
]);

backend/config/app.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
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+
];

0 commit comments

Comments
 (0)