diff --git a/.gitignore b/.gitignore index 3542b8e..420f071 100755 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..d52ad9e --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,7 @@ +FROM vardan/ubuntu:php-7.2 + +ENV PHP_DOCUMENT_ROOT /app + +ENV WORK_DIR ${PHP_DOCUMENT_ROOT} + +WORKDIR ${WORK_DIR} \ No newline at end of file diff --git a/composer.json b/composer.json index 7052c37..995e522 100755 --- a/composer.json +++ b/composer.json @@ -13,21 +13,25 @@ { "name": "Igor Maliy", "email": "imaliy.filsh@gmail.com" + }, + { + "name": "Vardan Pogosian", + "email": "vardan.pogosyan@gmail.com" } ], "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" } } } diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..775f20f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: "3" +services: + php: + image: filsh/yii2-oauth2-server + build: + dockerfile: Dockerfile.dev + context: . + volumes: + - ".:/app" + +networks: + default: \ No newline at end of file diff --git a/Bootstrap.php b/src/Bootstrap.php similarity index 100% rename from Bootstrap.php rename to src/Bootstrap.php diff --git a/BootstrapTrait.php b/src/BootstrapTrait.php similarity index 100% rename from BootstrapTrait.php rename to src/BootstrapTrait.php diff --git a/Module.php b/src/Module.php similarity index 93% rename from Module.php rename to src/Module.php index 2573aab..ca3813e 100755 --- a/Module.php +++ b/src/Module.php @@ -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', @@ -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 @@ -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() @@ -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', ]; } } diff --git a/Request.php b/src/Request.php similarity index 100% rename from Request.php rename to src/Request.php diff --git a/Response.php b/src/Response.php similarity index 100% rename from Response.php rename to src/Response.php diff --git a/Server.php b/src/Server.php similarity index 100% rename from Server.php rename to src/Server.php diff --git a/src/YiiRequestAdapter.php b/src/YiiRequestAdapter.php new file mode 100644 index 0000000..d0966b5 --- /dev/null +++ b/src/YiiRequestAdapter.php @@ -0,0 +1,42 @@ +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; + } +} \ No newline at end of file diff --git a/commands/empty b/src/commands/.gitkeep similarity index 100% rename from commands/empty rename to src/commands/.gitkeep diff --git a/controllers/RestController.php b/src/controllers/RestController.php similarity index 99% rename from controllers/RestController.php rename to src/controllers/RestController.php index 8e88eda..68a95fa 100755 --- a/controllers/RestController.php +++ b/src/controllers/RestController.php @@ -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 { diff --git a/exceptions/HttpException.php b/src/exceptions/HttpException.php similarity index 100% rename from exceptions/HttpException.php rename to src/exceptions/HttpException.php diff --git a/filters/ErrorToExceptionFilter.php b/src/filters/ErrorToExceptionFilter.php similarity index 99% rename from filters/ErrorToExceptionFilter.php rename to src/filters/ErrorToExceptionFilter.php index 2b6967d..72eae2c 100755 --- a/filters/ErrorToExceptionFilter.php +++ b/src/filters/ErrorToExceptionFilter.php @@ -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 { diff --git a/filters/auth/CompositeAuth.php b/src/filters/auth/CompositeAuth.php similarity index 100% rename from filters/auth/CompositeAuth.php rename to src/filters/auth/CompositeAuth.php diff --git a/messages/en/common.php b/src/messages/en/common.php similarity index 100% rename from messages/en/common.php rename to src/messages/en/common.php diff --git a/messages/es/oauth2server.php b/src/messages/es/oauth2server.php similarity index 100% rename from messages/es/oauth2server.php rename to src/messages/es/oauth2server.php diff --git a/messages/hu/oauth2server.php b/src/messages/hu/oauth2server.php similarity index 100% rename from messages/hu/oauth2server.php rename to src/messages/hu/oauth2server.php diff --git a/messages/zh-CN/oauth2server.php b/src/messages/zh-CN/oauth2server.php similarity index 100% rename from messages/zh-CN/oauth2server.php rename to src/messages/zh-CN/oauth2server.php diff --git a/messages/zh-TW/oauth2server.php b/src/messages/zh-TW/oauth2server.php similarity index 100% rename from messages/zh-TW/oauth2server.php rename to src/messages/zh-TW/oauth2server.php diff --git a/migrations/m140501_075311_add_oauth2_server.php b/src/migrations/m140501_075311_add_oauth2_server.php similarity index 100% rename from migrations/m140501_075311_add_oauth2_server.php rename to src/migrations/m140501_075311_add_oauth2_server.php diff --git a/models/OauthAccessTokens.php b/src/models/OauthAccessTokens.php similarity index 99% rename from models/OauthAccessTokens.php rename to src/models/OauthAccessTokens.php index 6edb901..d7d6c84 100755 --- a/models/OauthAccessTokens.php +++ b/src/models/OauthAccessTokens.php @@ -2,8 +2,6 @@ namespace filsh\yii2\oauth2server\models; -use Yii; - /** * This is the model class for table "oauth_access_tokens". * diff --git a/models/OauthAuthorizationCodes.php b/src/models/OauthAuthorizationCodes.php similarity index 99% rename from models/OauthAuthorizationCodes.php rename to src/models/OauthAuthorizationCodes.php index 3c613e6..6128ec7 100755 --- a/models/OauthAuthorizationCodes.php +++ b/src/models/OauthAuthorizationCodes.php @@ -2,8 +2,6 @@ namespace filsh\yii2\oauth2server\models; -use Yii; - /** * This is the model class for table "oauth_authorization_codes". * diff --git a/models/OauthClients.php b/src/models/OauthClients.php similarity index 99% rename from models/OauthClients.php rename to src/models/OauthClients.php index 77c1999..620a555 100755 --- a/models/OauthClients.php +++ b/src/models/OauthClients.php @@ -2,8 +2,6 @@ namespace filsh\yii2\oauth2server\models; -use Yii; - /** * This is the model class for table "oauth_clients". * diff --git a/models/OauthRefreshTokens.php b/src/models/OauthRefreshTokens.php similarity index 99% rename from models/OauthRefreshTokens.php rename to src/models/OauthRefreshTokens.php index 6fb5714..9e2b740 100755 --- a/models/OauthRefreshTokens.php +++ b/src/models/OauthRefreshTokens.php @@ -2,8 +2,6 @@ namespace filsh\yii2\oauth2server\models; -use Yii; - /** * This is the model class for table "oauth_refresh_tokens". * diff --git a/models/OauthScopes.php b/src/models/OauthScopes.php similarity index 98% rename from models/OauthScopes.php rename to src/models/OauthScopes.php index d1a24a9..31cf604 100755 --- a/models/OauthScopes.php +++ b/src/models/OauthScopes.php @@ -2,8 +2,6 @@ namespace filsh\yii2\oauth2server\models; -use Yii; - /** * This is the model class for table "oauth_scopes". * diff --git a/storage/Pdo.php b/src/storage/Pdo.php similarity index 100% rename from storage/Pdo.php rename to src/storage/Pdo.php diff --git a/traits/ClassNamespace.php b/src/traits/ClassNamespace.php similarity index 100% rename from traits/ClassNamespace.php rename to src/traits/ClassNamespace.php