Skip to content

Commit

Permalink
Merge pull request #146 from filsh/refactor
Browse files Browse the repository at this point in the history
- feat: added MacOS ignores
- feat: added Docker configs for development env
- fix: updated composer.json
- feat: added YiiRequestAdapter for Yii2 >= 2.0.13
  • Loading branch information
varp authored Aug 3, 2020
2 parents 1a2db88 + bfab338 commit b9c6e55
Show file tree
Hide file tree
Showing 29 changed files with 115 additions and 26 deletions.
32 changes: 32 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@

### macOS.gitignore

# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon


# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


# Folders to ignore
vendor

Expand Down
7 changes: 7 additions & 0 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM vardan/ubuntu:php-7.2

ENV PHP_DOCUMENT_ROOT /app

ENV WORK_DIR ${PHP_DOCUMENT_ROOT}

WORKDIR ${WORK_DIR}
10 changes: 7 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,25 @@
{
"name": "Igor Maliy",
"email": "[email protected]"
},
{
"name": "Vardan Pogosian",
"email": "[email protected]"
}
],
"require": {
"yiisoft/yii2": "*",
"bshaffer/oauth2-server-php": "~1.7"
"bshaffer/oauth2-server-php": "^1.7"
},
"autoload": {
"psr-4": {
"filsh\\yii2\\oauth2server\\": ""
"filsh\\yii2\\oauth2server\\": "src/"
}
},
"extra": {
"bootstrap": "filsh\\yii2\\oauth2server\\Bootstrap",
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "2.1.x-dev"
}
}
}
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
version: "3"
services:
php:
image: filsh/yii2-oauth2-server
build:
dockerfile: Dockerfile.dev
context: .
volumes:
- ".:/app"

networks:
default:
File renamed without changes.
File renamed without changes.
20 changes: 12 additions & 8 deletions Module.php → src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

namespace filsh\yii2\oauth2server;

use \Yii;
use Yii;
use yii\i18n\PhpMessageSource;
use \array_key_exists;

use function array_key_exists;

/**
* For example,
*
*
* ```php
* 'oauth2' => [
* 'class' => 'filsh\yii2\oauth2server\Module',
Expand All @@ -31,7 +32,7 @@
*/
class Module extends \yii\base\Module
{
const VERSION = '2.0.0';
const VERSION = '2.1.0';

/**
* @var array Model's map
Expand Down Expand Up @@ -140,10 +141,13 @@ public function getServer()

public function getRequest()
{
if(!$this->has('request')) {
if (!$this->has('request')) {
$this->set('request', Request::createFromGlobals());
}
return $this->get('request');

$request = $this->get('request');

return $request instanceof \yii\web\Request ? new YiiRequestAdapter($request) : $request;
}

public function getResponse()
Expand All @@ -163,8 +167,8 @@ public function registerTranslations()
{
if(!isset(Yii::$app->get('i18n')->translations['modules/oauth2/*'])) {
Yii::$app->get('i18n')->translations['modules/oauth2/*'] = [
'class' => PhpMessageSource::className(),
'basePath' => __DIR__ . '/messages',
'class' => PhpMessageSource::className(),
'basePath' => __DIR__.'/messages',
];
}
}
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
42 changes: 42 additions & 0 deletions src/YiiRequestAdapter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php


namespace filsh\yii2\oauth2server;


use OAuth2\RequestInterface;

class YiiRequestAdapter implements RequestInterface
{
private $request;

public function __construct(\yii\web\Request $request)
{
$this->request = $request;
}

public function query($name, $default = null)
{
return $this->request->get($name, $default);
}

public function request($name, $default = null)
{
return $this->request->post($name, $default);
}

public function server($name, $default = null)
{
return isset($_SERVER[$name]) ? $_SERVER[$name] : $default;
}

public function headers($name, $default = null)
{
return $this->request->headers->get($name, $default);
}

public function getAllQueryParameters()
{
return $this->request->queryParams;
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

namespace filsh\yii2\oauth2server\controllers;

use Yii;
use yii\helpers\ArrayHelper;
use filsh\yii2\oauth2server\filters\ErrorToExceptionFilter;
use yii\helpers\ArrayHelper;

class RestController extends \yii\rest\Controller
{
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

namespace filsh\yii2\oauth2server\filters;

use Yii;
use yii\base\Controller;
use filsh\yii2\oauth2server\Module;
use filsh\yii2\oauth2server\exceptions\HttpException;
use filsh\yii2\oauth2server\Module;
use yii\base\Controller;

class ErrorToExceptionFilter extends \yii\base\Behavior
{
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace filsh\yii2\oauth2server\models;

use Yii;

/**
* This is the model class for table "oauth_access_tokens".
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace filsh\yii2\oauth2server\models;

use Yii;

/**
* This is the model class for table "oauth_authorization_codes".
*
Expand Down
2 changes: 0 additions & 2 deletions models/OauthClients.php → src/models/OauthClients.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace filsh\yii2\oauth2server\models;

use Yii;

/**
* This is the model class for table "oauth_clients".
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace filsh\yii2\oauth2server\models;

use Yii;

/**
* This is the model class for table "oauth_refresh_tokens".
*
Expand Down
2 changes: 0 additions & 2 deletions models/OauthScopes.php → src/models/OauthScopes.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace filsh\yii2\oauth2server\models;

use Yii;

/**
* This is the model class for table "oauth_scopes".
*
Expand Down
File renamed without changes.
File renamed without changes.

0 comments on commit b9c6e55

Please sign in to comment.