Skip to content

Commit

Permalink
changed config filename
Browse files Browse the repository at this point in the history
code style
  • Loading branch information
ericyzhu committed Sep 5, 2020
1 parent e2f7843 commit e1e85eb
Show file tree
Hide file tree
Showing 19 changed files with 186 additions and 129 deletions.
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
9 changes: 4 additions & 5 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
<?php

$header = <<<'EOF'
This file is part of Hyperf.
This file is part of hyperf-ext/encryption.
@link https://www.hyperf.io
@document https://hyperf.wiki
@contact [email protected]
@license https://github.com/hyperf/hyperf/blob/master/LICENSE
@link https://github.com/hyperf-ext/encryption
@contact [email protected]
@license https://github.com/hyperf-ext/encryption/blob/master/LICENSE
EOF;

return PhpCsFixer\Config::create()
Expand Down
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ composer require hyperf-ext/encryption
php bin/hyperf.php vendor:publish hyperf-ext/encryption
```

> 配置文件位于 `config/autoload/ext-encryption.php`
> 配置文件位于 `config/autoload/encryption.php`
## 设置

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"hyperf",
"encryption"
],
"description": "The unofficial Hyperf Encryption package.",
"description": "The Hyperf Encryption package.",
"authors": [
{
"name": "Eric Zhu",
Expand Down
12 changes: 7 additions & 5 deletions publish/ext-encryption.php → publish/encryption.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
<?php

declare(strict_types=1);

/**
* This file is part of hyperf-ext/encryption.
*
* @link https://github.com/hyperf-ext/encryption
* @contact [email protected]
* @license https://github.com/hyperf-ext/encryption/blob/master/LICENSE
*/
return [

'default' => 'aes',

'driver' => [

'aes' => [
'class' => \HyperfExt\Encryption\Driver\AesDriver::class,
'options' => [
'key' => env('AES_KEY', ''),
'cipher' => env('AES_CIPHER', 'AES-128-CBC'),
],
],

],

];
16 changes: 10 additions & 6 deletions src/Command/GenKeyCommand.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<?php

declare(strict_types=1);

/**
* This file is part of hyperf-ext/encryption.
*
* @link https://github.com/hyperf-ext/encryption
* @contact [email protected]
* @license https://github.com/hyperf-ext/encryption/blob/master/LICENSE
*/
namespace HyperfExt\Encryption\Command;

use Hyperf\Command\Command as HyperfCommand;
Expand Down Expand Up @@ -33,23 +39,21 @@ public function configure()
*/
public function handle()
{
$driverName = $this->choice('Select driver', array_keys($this->config->get('ext-encryption.driver')));
$driverName = $this->choice('Select driver', array_keys($this->config->get('encryption.driver')));

$key = $this->generateRandomKey($driverName);

$this->line('<comment>'.$key.'</comment>');
$this->line('<comment>' . $key . '</comment>');
}

/**
* Generate a random key for the application.
*
* @param string $driverName
*
* @return string
*/
protected function generateRandomKey(string $driverName)
{
$config = $this->config->get("ext-encryption.driver.{$driverName}");
$config = $this->config->get("encryption.driver.{$driverName}");
return call([$config['class'], 'generateKey'], [['options' => $config['options']]]);
}
}
12 changes: 9 additions & 3 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<?php

declare(strict_types=1);

/**
* This file is part of hyperf-ext/encryption.
*
* @link https://github.com/hyperf-ext/encryption
* @contact [email protected]
* @license https://github.com/hyperf-ext/encryption/blob/master/LICENSE
*/
namespace HyperfExt\Encryption;

use HyperfExt\Encryption\Command\GenKeyCommand;
Expand All @@ -22,8 +28,8 @@ public function __invoke(): array
[
'id' => 'config',
'description' => 'The config for HyperfExt\\Encryption.',
'source' => __DIR__ . '/../publish/ext-encryption.php',
'destination' => BASE_PATH . '/config/autoload/ext-encryption.php',
'source' => __DIR__ . '/../publish/encryption.php',
'destination' => BASE_PATH . '/config/autoload/encryption.php',
],
],
];
Expand Down
11 changes: 9 additions & 2 deletions src/Contract/AsymmetricDriverInterface.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
<?php

declare(strict_types=1);

/**
* This file is part of hyperf-ext/encryption.
*
* @link https://github.com/hyperf-ext/encryption
* @contact [email protected]
* @license https://github.com/hyperf-ext/encryption/blob/master/LICENSE
*/
namespace HyperfExt\Encryption\Contract;

interface AsymmetricDriverInterface extends DriverInterface
{
public function getPublicKey(): string;

public function getPrivateKey(): string;
}
}
17 changes: 8 additions & 9 deletions src/Contract/DriverInterface.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
<?php

declare(strict_types=1);

/**
* This file is part of hyperf-ext/encryption.
*
* @link https://github.com/hyperf-ext/encryption
* @contact [email protected]
* @license https://github.com/hyperf-ext/encryption/blob/master/LICENSE
*/
namespace HyperfExt\Encryption\Contract;

interface DriverInterface
Expand All @@ -10,9 +16,6 @@ interface DriverInterface
* Encrypt the given value.
*
* @param mixed $value
* @param bool $serialize
*
* @return string
*
* @throws \HyperfExt\Encryption\Exception\EncryptException
*/
Expand All @@ -21,12 +24,8 @@ public function encrypt($value, bool $serialize = true): string;
/**
* Decrypt the given value.
*
* @param string $payload
* @param bool $unserialize
*
* @return mixed
*
* @throws \HyperfExt\Encryption\Exception\DecryptException
* @return mixed
*/
public function decrypt(string $payload, bool $unserialize = true);
}
10 changes: 7 additions & 3 deletions src/Contract/EncryptionInterface.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<?php

declare(strict_types=1);

/**
* This file is part of hyperf-ext/encryption.
*
* @link https://github.com/hyperf-ext/encryption
* @contact [email protected]
* @license https://github.com/hyperf-ext/encryption/blob/master/LICENSE
*/
namespace HyperfExt\Encryption\Contract;

interface EncryptionInterface extends DriverInterface
{
/**
* Get a driver instance.
*
* @param string|null $name
*
* @return \HyperfExt\Encryption\Contract\DriverInterface
*/
public function getDriver(?string $name = null): DriverInterface;
Expand Down
11 changes: 9 additions & 2 deletions src/Contract/SymmetricDriverInterface.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
<?php

declare(strict_types=1);

/**
* This file is part of hyperf-ext/encryption.
*
* @link https://github.com/hyperf-ext/encryption
* @contact [email protected]
* @license https://github.com/hyperf-ext/encryption/blob/master/LICENSE
*/
namespace HyperfExt\Encryption\Contract;

interface SymmetricDriverInterface extends DriverInterface
{
public function getKey(): string;

public static function generateKey(array $options = []): string;
}
}
10 changes: 8 additions & 2 deletions src/Crypt.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<?php

declare(strict_types=1);

/**
* This file is part of hyperf-ext/encryption.
*
* @link https://github.com/hyperf-ext/encryption
* @contact [email protected]
* @license https://github.com/hyperf-ext/encryption/blob/master/LICENSE
*/
namespace HyperfExt\Encryption;

use Hyperf\Utils\ApplicationContext;
use HyperfExt\Encryption\Contract\DriverInterface;
use HyperfExt\Encryption\Contract\EncryptionInterface;
use Hyperf\Utils\ApplicationContext;

abstract class Crypt
{
Expand Down
Loading

0 comments on commit e1e85eb

Please sign in to comment.