Skip to content

Commit edf5e12

Browse files
committed
first commit
0 parents  commit edf5e12

67 files changed

Lines changed: 1331 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.bowerrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"directory" : "vendor/bower"
3+
}

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/.gitattributes export-ignore

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# yii console command
2+
/yii
3+
4+
# phpstorm project files
5+
.idea
6+
7+
# netbeans project files
8+
nbproject
9+
10+
# zend studio for eclipse project files
11+
.buildpath
12+
.project
13+
.settings
14+
15+
# windows thumbnail cache
16+
Thumbs.db
17+
18+
# composer vendor dir
19+
/vendor
20+
21+
# composer itself is not needed
22+
composer.phar
23+
24+
# Mac DS_Store Files
25+
.DS_Store
26+
27+
# phpunit itself is not needed
28+
phpunit.phar
29+
# local phpunit config
30+
/phpunit.xml

README.md

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
Yii 2 Basic API Template
2+
===============================
3+
4+
Yii 2 Basic API Template is a skeleton [Yii 2](http://www.yiiframework.com) application best for rapidly
5+
creating small API applications.
6+
7+
The template is designed to work in a team development environment.
8+
It supports deploying the application in different environments.
9+
10+
INSTALLATION
11+
------------
12+
13+
## Install via Composer
14+
15+
Run the [Composer](http://getcomposer.org) commands to install:
16+
17+
```bash
18+
composer global require fxp/composer-asset-plugin ~1.1.1
19+
composer create-project --prefer-dist frostealth/yii2-api-basic my-api
20+
```
21+
22+
## Preparing application
23+
24+
After you install the application, you have to conduct the following steps to initialize
25+
the installed application. You only need to do these once for all.
26+
27+
1. Execute the `init` command and select `dev` as environment.
28+
29+
```
30+
php /path/to/my-api/init --env=development
31+
```
32+
33+
Otherwise, in production execute `init` in non-interactive mode.
34+
35+
```
36+
php /path/to/my-api/init --env=production --overwrite=a
37+
```
38+
39+
2. Create a new database and adjust the configuration in `common/config/db-local.php` accordingly.
40+
41+
DIRECTORY STRUCTURE
42+
-------------------
43+
44+
```
45+
commands/ contains console controllers (commands)
46+
common
47+
controllers/ contains shared api-specific controllers
48+
models/ contains shared api-specific model classes
49+
config/ contains application configurations
50+
mail/ contains view files for e-mails
51+
runtime/ contains files generated during runtime
52+
versions contains api versions as modules
53+
v1/
54+
controllers/ contains version-specific controllers
55+
models/ contains version-specific model classes
56+
web/ contains the entry script
57+
vendor/ contains dependent 3rd-party packages
58+
environments/ contains environment-based overrides
59+
```

commands/.gitkeep

Whitespace-only changes.

common/controllers/Controller.php

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
namespace app\common\controllers;
4+
5+
use yii\filters\auth\CompositeAuth;
6+
use yii\filters\auth\HttpBearerAuth;
7+
use yii\filters\auth\QueryParamAuth;
8+
9+
/**
10+
* Class Controller
11+
*
12+
* @package app\common\controllers
13+
*/
14+
class Controller extends \yii\rest\Controller
15+
{
16+
/** @inheritdoc */
17+
public $serializer = [
18+
'class' => 'yii\rest\Serializer',
19+
'collectionEnvelope' => 'items',
20+
];
21+
22+
/**
23+
* @inheritdoc
24+
*/
25+
public function behaviors()
26+
{
27+
$behaviors = parent::behaviors();
28+
$behaviors['authenticator'] = [
29+
'class' => CompositeAuth::className(),
30+
'authMethods' => [
31+
[
32+
'class' => HttpBearerAuth::className(),
33+
'only' => $this->authOnly(),
34+
'except' => $this->authExcept(),
35+
],
36+
[
37+
'class' => QueryParamAuth::className(),
38+
'only' => $this->authOnly(),
39+
'except' => $this->authExcept(),
40+
],
41+
],
42+
];
43+
44+
return $behaviors;
45+
}
46+
47+
/**
48+
* @inheritdoc
49+
*/
50+
protected function verbs()
51+
{
52+
return [
53+
'create' => ['POST'],
54+
'update' => ['PUT', 'PATCH'],
55+
'delete' => ['DELETE'],
56+
'index' => ['GET', 'HEAD'],
57+
'view' => ['GET', 'HEAD'],
58+
];
59+
}
60+
61+
/**
62+
* @return array
63+
*/
64+
protected function authOnly()
65+
{
66+
return [];
67+
}
68+
69+
/**
70+
* @return array
71+
*/
72+
protected function authExcept()
73+
{
74+
return [];
75+
}
76+
}

common/models/.gitkeep

Whitespace-only changes.

composer.json

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "frostealth/yii2-api-basic",
3+
"description": "Yii 2 Basic API Template",
4+
"keywords": ["yii2", "framework", "basic", "project template", "api"],
5+
"type": "project",
6+
"license": "BSD-3-Clause",
7+
"minimum-stability": "dev",
8+
"require": {
9+
"php": ">=5.4.0",
10+
"yiisoft/yii2": ">=2.0.6",
11+
"yiisoft/yii2-swiftmailer": "*"
12+
},
13+
"require-dev": {
14+
"yiisoft/yii2-codeception": "*",
15+
"yiisoft/yii2-faker": "*",
16+
"yiisoft/yii2-gii": "*"
17+
},
18+
"config": {
19+
"process-timeout": 1800
20+
},
21+
"extra": {
22+
"asset-installer-paths": {
23+
"npm-asset-library": "vendor/npm",
24+
"bower-asset-library": "vendor/bower"
25+
}
26+
}
27+
}

config/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*-local.php

config/bootstrap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<?php

0 commit comments

Comments
 (0)