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
Eugene Terentev
committed
Apr 23, 2018
1 parent
23273e6
commit 0146734
Showing
74 changed files
with
560 additions
and
13,654 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
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
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 | ||
/** | ||
* @author Eugene Terentev <eugene@terentev.net> | ||
*/ | ||
|
||
$cache = [ | ||
'class' => yii\caching\FileCache::class, | ||
'cachePath' => '@api/runtime/cache' | ||
]; | ||
|
||
if (YII_ENV_DEV) { | ||
$cache = [ | ||
'class' => yii\caching\DummyCache::class | ||
]; | ||
} | ||
|
||
return $cache; |
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,10 @@ | ||
<?php | ||
return [ | ||
'class' => 'yii\web\UrlManager', | ||
'enablePrettyUrl' => true, | ||
'showScriptName' => false, | ||
'rules' => [ | ||
// Api | ||
['class' => 'yii\rest\UrlRule', 'controller' => 'api/v1/article', 'only' => ['index', 'view', 'options']], | ||
] | ||
]; |
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 [ | ||
'id' => 'frontend', | ||
'basePath' => dirname(__DIR__), | ||
'components' => [ | ||
'urlManager' => require(__DIR__ . '/_urlManager.php'), | ||
'cache' => require(__DIR__ . '/_cache.php'), | ||
], | ||
]; |
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,4 @@ | ||
<?php | ||
/** | ||
* @author Eugene Terentev <eugene@terentev.net> | ||
*/ |
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,4 @@ | ||
<?php | ||
return [ | ||
|
||
]; |
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,36 @@ | ||
<?php | ||
$config = [ | ||
'homeUrl' => Yii::getAlias('@apiUrl'), | ||
'controllerNamespace' => 'api\controllers', | ||
'defaultRoute' => 'site/index', | ||
'bootstrap' => ['maintenance'], | ||
'modules' => [ | ||
'v1' => \api\modules\v1\Module::class | ||
], | ||
'components' => [ | ||
'errorHandler' => [ | ||
'errorAction' => 'site/error' | ||
], | ||
'maintenance' => [ | ||
'class' => common\components\maintenance\Maintenance::class, | ||
'enabled' => function ($app) { | ||
if (env('APP_MAINTENANCE') === '1') { | ||
return true; | ||
} | ||
return $app->keyStorage->get('frontend.maintenance') === 'enabled'; | ||
} | ||
], | ||
'request' => [ | ||
'enableCookieValidation' => false, | ||
], | ||
'user' => [ | ||
'class' => yii\web\User::class, | ||
'identityClass' => common\models\User::class, | ||
'loginUrl' => ['/user/sign-in/login'], | ||
'enableAutoLogin' => true, | ||
'as afterLogin' => common\behaviors\LoginTimestampBehavior::class | ||
] | ||
] | ||
]; | ||
|
||
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,30 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace api\controllers; | ||
|
||
use Yii; | ||
use yii\web\Controller; | ||
use yii\web\NotFoundHttpException; | ||
|
||
class SiteController extends Controller | ||
{ | ||
public function actionIndex() | ||
{ | ||
return $this->redirect(\Yii::getAlias('@frontendUrl')); | ||
} | ||
|
||
public function actionError() | ||
{ | ||
if (($exception = Yii::$app->getErrorHandler()->exception) === null) { | ||
$exception = new NotFoundHttpException(Yii::t('yii', 'Page not found.')); | ||
} | ||
|
||
if ($exception instanceof \HttpException) { | ||
Yii::$app->response->setStatusCode($exception->getCode()); | ||
} else { | ||
Yii::$app->response->setStatusCode(500); | ||
} | ||
|
||
return $this->asJson(['error' => $exception->getMessage(), 'code' => $exception->getCode()]); | ||
} | ||
} |
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,47 @@ | ||
<?php | ||
|
||
namespace api\modules\v1; | ||
|
||
use Yii; | ||
use yii\filters\ContentNegotiator; | ||
use yii\filters\RateLimiter; | ||
use yii\web\Response; | ||
|
||
class Module extends \yii\base\Module | ||
{ | ||
/** @var string */ | ||
public $controllerNamespace = 'api\modules\v1\controllers'; | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function init() | ||
{ | ||
parent::init(); | ||
Yii::$app->user->identityClass = 'api\modules\v1\models\ApiUserIdentity'; | ||
Yii::$app->user->enableSession = false; | ||
Yii::$app->user->loginUrl = null; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function behaviors() | ||
{ | ||
$behaviors = parent::behaviors(); | ||
|
||
$behaviors['contentNegotiator'] = [ | ||
'class' => ContentNegotiator::class, | ||
'formats' => [ | ||
'application/json' => Response::FORMAT_JSON, | ||
'application/xml' => Response::FORMAT_XML, | ||
], | ||
]; | ||
|
||
$behaviors['rateLimiter'] = [ | ||
'class' => RateLimiter::class, | ||
]; | ||
|
||
return $behaviors; | ||
} | ||
} |
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
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,60 @@ | ||
<?php | ||
|
||
namespace api\modules\v1\controllers; | ||
|
||
use common\models\User; | ||
use yii\filters\auth\CompositeAuth; | ||
use yii\filters\auth\HttpBasicAuth; | ||
use yii\filters\auth\HttpBearerAuth; | ||
use yii\filters\auth\HttpHeaderAuth; | ||
use yii\filters\auth\QueryParamAuth; | ||
use yii\rest\Controller; | ||
use yii\rest\OptionsAction; | ||
|
||
/** | ||
* @author Eugene Terentev <eugene@terentev.net> | ||
*/ | ||
class UserController extends Controller | ||
{ | ||
/** | ||
* @return array | ||
*/ | ||
public function behaviors() | ||
{ | ||
$behaviors = parent::behaviors(); | ||
|
||
$behaviors['authenticator'] = [ | ||
'class' => CompositeAuth::class, | ||
'authMethods' => [ | ||
HttpBasicAuth::class, | ||
HttpBearerAuth::class, | ||
HttpHeaderAuth::class, | ||
QueryParamAuth::class | ||
] | ||
]; | ||
|
||
return $behaviors; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function actions() | ||
{ | ||
return [ | ||
'options' => [ | ||
'class' => OptionsAction::class | ||
] | ||
]; | ||
} | ||
|
||
/** | ||
* @return User|null|\yii\web\IdentityInterface | ||
*/ | ||
public function actionIndex() | ||
{ | ||
$resource = new User(); | ||
$resource->load(\Yii::$app->user->getIdentity()->attributes, ''); | ||
return $resource; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...modules/api/v1/models/ApiUserIdentity.php → api/modules/v1/models/ApiUserIdentity.php
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
2 changes: 1 addition & 1 deletion
2
...tend/modules/api/v1/resources/Article.php → api/modules/v1/resources/Article.php
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
2 changes: 1 addition & 1 deletion
2
frontend/modules/api/v1/resources/User.php → api/modules/v1/resources/User.php
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
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,29 @@ | ||
<?php | ||
require(__DIR__ . '/../../tests/bootstrap.php'); | ||
|
||
// NOTE: Make sure this file is not accessible when deployed to production | ||
if (YII_ENV !== 'test') { | ||
die('You are not allowed to access this file.'); | ||
} | ||
|
||
// Environment | ||
require(__DIR__ . '/../../common/env.php'); | ||
|
||
// Yii | ||
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'); | ||
|
||
// Bootstrap application | ||
require(__DIR__ . '/../../common/config/bootstrap.php'); | ||
require(__DIR__ . '/../config/bootstrap.php'); | ||
|
||
$config = yii\helpers\ArrayHelper::merge( | ||
require(__DIR__ . '/../../common/config/base.php'), | ||
require(__DIR__ . '/../../common/config/web.php'), | ||
require(__DIR__ . '/../config/base.php'), | ||
require(__DIR__ . '/../config/web.php'), | ||
require(__DIR__ . '/../../tests/config/base.php'), | ||
require(__DIR__ . '/../../tests/config/common/acceptance.php'), | ||
require(__DIR__ . '/../../tests/config/frontend/acceptance.php') | ||
); | ||
|
||
(new yii\web\Application($config))->run(); |
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,22 @@ | ||
<?php | ||
// Composer | ||
require(__DIR__ . '/../../vendor/autoload.php'); | ||
|
||
// Environment | ||
require(__DIR__ . '/../../common/env.php'); | ||
|
||
// Yii | ||
require(__DIR__ . '/../../vendor/yiisoft/yii2/Yii.php'); | ||
|
||
// Bootstrap application | ||
require(__DIR__ . '/../../common/config/bootstrap.php'); | ||
require(__DIR__ . '/../config/bootstrap.php'); | ||
|
||
$config = \yii\helpers\ArrayHelper::merge( | ||
require(__DIR__ . '/../../common/config/base.php'), | ||
require(__DIR__ . '/../../common/config/web.php'), | ||
require(__DIR__ . '/../config/base.php'), | ||
require(__DIR__ . '/../config/web.php') | ||
); | ||
|
||
(new yii\web\Application($config))->run(); |
Oops, something went wrong.