Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
ericyzhu committed Sep 6, 2020
0 parents commit 22465d9
Show file tree
Hide file tree
Showing 78 changed files with 8,795 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/tests export-ignore
/.github export-ignore
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
on:
push:
# Sequence of patterns matched against refs/tags
tags:
- 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

name: Release

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Create Release
id: create_release
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ github.ref }}
release_name: Release ${{ github.ref }}
draft: false
prerelease: false
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/vendor/
composer.lock
*.cache
*.log
.idea/
.DS_Store
91 changes: 91 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?php

$header = <<<'EOF'
This file is part of hyperf-ext/auth.
@link https://github.com/hyperf-ext/auth
@contact eric@zhu.email
@license https://github.com/hyperf-ext/auth/blob/master/LICENSE
EOF;

return PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@PSR2' => true,
'@Symfony' => true,
'@DoctrineAnnotation' => true,
'@PhpCsFixer' => true,
'header_comment' => [
'commentType' => 'PHPDoc',
'header' => $header,
'separate' => 'none',
'location' => 'after_declare_strict',
],
'array_syntax' => [
'syntax' => 'short'
],
'list_syntax' => [
'syntax' => 'short'
],
'concat_space' => [
'spacing' => 'one'
],
'blank_line_before_statement' => [
'statements' => [
'declare',
],
],
'general_phpdoc_annotation_remove' => [
'annotations' => [
'author'
],
],
'ordered_imports' => [
'imports_order' => [
'class', 'function', 'const',
],
'sort_algorithm' => 'alpha',
],
'single_line_comment_style' => [
'comment_types' => [
],
],
'yoda_style' => [
'always_move_variable' => false,
'equal' => false,
'identical' => false,
],
'phpdoc_align' => [
'align' => 'left',
],
'multiline_whitespace_before_semicolons' => [
'strategy' => 'no_multi_line',
],
'constant_case' => [
'case' => 'lower',
],
'class_attributes_separation' => true,
'combine_consecutive_unsets' => true,
'declare_strict_types' => true,
'linebreak_after_opening_tag' => true,
'lowercase_static_reference' => true,
'no_useless_else' => true,
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'not_operator_with_space' => false,
'ordered_class_elements' => true,
'php_unit_strict' => false,
'phpdoc_separation' => false,
'single_quote' => true,
'standardize_not_equals' => true,
'multiline_comment_opening_closing' => true,
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude('bin')
->exclude('public')
->exclude('runtime')
->exclude('vendor')
->in(__DIR__)
)
->setUsingCache(false);
38 changes: 38 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
language: php

sudo: required

matrix:
include:
- php: 7.2
env: SW_VERSION="4.5.3RC1"
- php: 7.3
env: SW_VERSION="4.5.3RC1"
- php: 7.4
env: SW_VERSION="4.5.3RC1"

allow_failures:
- php: master

services:
- docker

before_install:
- export PHP_MAJOR="$(`phpenv which php` -r 'echo phpversion();' | cut -d '.' -f 1)"
- export PHP_MINOR="$(`phpenv which php` -r 'echo phpversion();' | cut -d '.' -f 2)"
- echo $PHP_MAJOR
- echo $PHP_MINOR

install:
- cd $TRAVIS_BUILD_DIR
- bash .travis/swoole.install.sh
- phpenv config-rm xdebug.ini || echo "xdebug not available"
- phpenv config-add .travis/ci.ini

before_script:
- cd $TRAVIS_BUILD_DIR
- composer config -g process-timeout 900 && composer update

script:
- composer analyse
- composer test
5 changes: 5 additions & 0 deletions .travis/ci.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[opcache]
opcache.enable_cli=1

[swoole]
extension = "swoole.so"
10 changes: 10 additions & 0 deletions .travis/swoole.install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
wget https://github.com/swoole/swoole-src/archive/v"${SW_VERSION}".tar.gz -O swoole.tar.gz
mkdir -p swoole
tar -xf swoole.tar.gz -C swoole --strip-components=1
rm swoole.tar.gz
cd swoole || exit
phpize
./configure --enable-openssl --enable-mysqlnd --enable-http2
make -j "$(nproc)"
make install
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) Taylor Otwell
Copyright (c) Eric Zhu

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Hyperf 认证组件

该组件移植了 Laravel Auth 组件([illuminate/auth](https://github.com/illuminate/auth ))相对完整的功能特性,除了中间件传参和邮件通知。

* Hyperf 的中间件遵循 PSR-15 的规范,无法使用 Laravel 的方式通过路由向中间件传递值,故在实现上与 Laravel 不同,仅实现了一个基础的身份认证中间件抽象类 `HyperfExt\Auth\Middlewares\AbstractAuthenticateMiddleware`
* 邮件([illuminate/mail](https://github.com/illuminate/mail ))和通知([illuminate/notifications](https://github.com/illuminate/notifications ))尚未移植完成。

该组件实现了两个自定义注解。
* Hyperf\Di\Annotations\AbstractAnnotation\Auth
可用于类和方法,语法 `Auth({"GUARD_CONF_NAME"[, ...]}[, passable=bool])`
* 第一个参数为 Guard 名列表
* 第二个 `passable` 可选参数默认值为 `false`,设置为 `true` 时未认证的用户也可以通过 Guard,不会抛出为认证的异常,在某些特殊情况下将会比较有用。例如,同一个 API 需要对认证用户和非认证用户展示不同的数据。

* Hyperf\Di\Annotations\AbstractAnnotation\Policy
可用于类,语法 `Policy({"MODEL_FQCN"\[, ...\]})`
* 参数为模型 FQCN 列表

另外,Gate 和策略的注册方法与 Laravel 不同。

Gate 可以通过注入 `HyperfExt\Auth\Contracts\Access\GateManagerInterface` 来调用实例的 `define` 方法注册。或者监听 `HyperfExt\Auth\Events\GateManagerResolved` 事件来在监听器中访问事件的 `gate` 属性(GateManagerInterface)来注册。

策略可以通过 `gen:policy` 命令来创建,例如 `gen:policy PostPolicy --model=App\\Model\\Post`。也可以在配置文件的 `policies` 中定义模型类和策略类的映射。

## 安装

```shell script
composer require hyperf-ext/auth
```

## 发布配置

```shell script
php bin/hyperf.php vendor:publish hyperf-ext/auth
```

> 文件位于 `config/autoload/auth.php`
## 配置

> 详细说明见配置文件。
## 使用

### 身份认证

文档待完成。

### 授权

文档待完成。
66 changes: 66 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"name": "hyperf-ext/auth",
"type": "library",
"license": "MIT",
"keywords": [
"php",
"hyperf",
"auth"
],
"description": "The Hyperf Auth package.",
"authors": [
{
"name": "Eric Zhu",
"email": "eric@zhu.email"
},
{
"name": "Taylor Otwell",
"email": "taylor@laravel.com"
}
],
"autoload": {
"psr-4": {
"HyperfExt\\Auth\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"HyperfTest\\": "tests"
}
},
"require": {
"php": ">=7.2",
"ext-swoole": ">=4.5",
"hyperf-ext/hashing": "^2.0",
"hyperf/command": "^2.0",
"hyperf/config": "^2.0",
"hyperf/database": "^2.0",
"hyperf/db-connection": "^2.0",
"hyperf/di": "^2.0",
"hyperf/framework": "^2.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.14",
"hyperf/testing": "^2.0",
"phpstan/phpstan": "^0.12",
"swoole/ide-helper": "dev-master",
"mockery/mockery": "^1.0"
},
"suggest": {
"hyperf/session": "Required to use session guard.",
"hyperf-ext/cookie": "Required to use session guard."
},
"config": {
"sort-packages": true
},
"scripts": {
"test": "co-phpunit -c phpunit.xml --colors=always",
"analyse": "phpstan analyse --memory-limit 1024M -l 0 ./src",
"cs-fix": "php-cs-fixer fix $1"
},
"extra": {
"hyperf": {
"config": "HyperfExt\\Auth\\ConfigProvider"
}
}
}
15 changes: 15 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="tests/bootstrap.php"
backupGlobals="false"
backupStaticAttributes="false"
verbose="true"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuite name="Testsuite">
<directory>./tests/</directory>
</testsuite>
</phpunit>
Loading

0 comments on commit 22465d9

Please sign in to comment.