diff --git a/.gitignore b/.gitignore index 82cfc4e..c541baa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ -.idea -composer.lock -vendor +.idea/ +vendor/ +.phpunit.result.cache +.php-cs-fixer.cache \ No newline at end of file diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..1c72787 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,23 @@ + + * Powered by PhpStorm + * Created on 2023/1/9 + */ + +$finder = PhpCsFixer\Finder::create()->in([ + __DIR__ . '/publish', + __DIR__ . '/src', + __DIR__ . '/tests', +]); + +$config = new PhpCsFixer\Config(); +return $config->setRules([ + '@PSR12' => true, + 'strict_param' => true, + 'array_syntax' => ['syntax' => 'short'], +]) + ->setUsingCache(false) + ->setFinder($finder); diff --git a/.versionrc b/.versionrc new file mode 100644 index 0000000..017437c --- /dev/null +++ b/.versionrc @@ -0,0 +1,68 @@ +{ + "header": "# 版本更新日志", + "preMajor": true, + "types": [ + { + "type": "feat", + "section": "✨ Features | 新功能" + }, + { + "type": "fix", + "section": "🐛 Bug Fixes | Bug 修复" + }, + { + "type": "init", + "section": "🎉 Init | 初始化" + }, + { + "type": "docs", + "section": "✏️ Documentation | 文档" + }, + { + "type": "style", + "section": "💄 Styles | 风格" + }, + { + "type": "refactor", + "section": "♻️ Code Refactoring | 代码重构" + }, + { + "type": "perf", + "section": "⚡ Performance Improvements | 性能优化" + }, + { + "type": "tests", + "section": "✅ Tests | 测试" + }, + { + "type": "test", + "section": "✅ Tests | 测试" + }, + { + "type": "revert", + "section": "⏪ Revert | 回退" + }, + { + "type": "build", + "section": "📦‍ Build System | 打包构建" + }, + { + "type": "chore", + "section": "🚀 Chore | 构建/工程依赖/工具" + }, + { + "type": "ci", + "section": "👷 Continuous Integration | CI 配置" + } + ], + "bumpFiles": [ + { + "filename": "VERSION_TRACKER.txt", + "type": "plain-text" + }, + { + "filename": "composer.json", + "type": "json" + } + ] +} diff --git a/bin/release.sh b/bin/release.sh deleted file mode 100755 index 938553e..0000000 --- a/bin/release.sh +++ /dev/null @@ -1,54 +0,0 @@ -#!/usr/bin/env bash -set -e - -if (( "$#" != 1 )) -then - echo "Tag has to be provided" - - exit 1 -fi - -NOW=$(date +%s) -CURRENT_BRANCH="master" -VERSION=$1 -BASEPATH=$(cd `dirname $0`; cd ../src/; pwd) - -# Always prepend with "v" -if [[ $VERSION != v* ]] -then - VERSION="v$VERSION" -fi - -git tag $VERSION -git push origin --tags - -repos=$(ls $BASEPATH) - -for REMOTE in $repos -do - echo "" - echo "" - echo "Cloning $REMOTE"; - TMP_DIR="/tmp/hyperf-split" - REMOTE_URL="git@github.com:hyperf-admin/$REMOTE.git" - - rm -rf $TMP_DIR; - mkdir $TMP_DIR; - - ( - cd $TMP_DIR; - - git clone $REMOTE_URL . - git checkout "$CURRENT_BRANCH"; - - if [[ $(git log --pretty="%d" -n 1 | grep tag --count) -eq 0 ]]; then - echo "Releasing $REMOTE" - git tag $VERSION - git push origin --tags - fi - ) -done - -TIME=$(echo "$(date +%s) - $NOW" | bc) - -printf "Execution time: %f seconds" $TIME diff --git a/bin/split.sh b/bin/split.sh deleted file mode 100755 index a91c0a0..0000000 --- a/bin/split.sh +++ /dev/null @@ -1,30 +0,0 @@ -#!/usr/bin/env bash - -set -e -set -x - -CURRENT_BRANCH="master" -BASEPATH=$(cd `dirname $0`; cd ../src/; pwd) -REPOS=$@ - -function split() -{ - SHA1=`./bin/splitsh-lite --prefix=$1` - git push $2 "$SHA1:refs/heads/$CURRENT_BRANCH" -f -} - -function remote() -{ - git remote add $1 $2 || true -} - -if [[ $# -eq 0 ]]; then - REPOS=$(ls $BASEPATH) -fi - -for REPO in $REPOS ; do - remote $REPO git@github.com:hyperf-admin/$REPO.git - split "src/$REPO" $REPO -done - -git pull origin $CURRENT_BRANCH diff --git a/bin/splitsh-lite b/bin/splitsh-lite deleted file mode 100755 index 71a4d89..0000000 Binary files a/bin/splitsh-lite and /dev/null differ diff --git a/guide.md b/guide.md new file mode 100644 index 0000000..04c5175 --- /dev/null +++ b/guide.md @@ -0,0 +1,128 @@ +# PHP Package boilerplate project explanation + +PHP is a general-purpose server-side scripting language primarily used in web development. Originally created by Rasmus Lerdorf in 1994, it is now by The PHP Development Team. + +PHP originally stood for "Personal Home Page", but now stands for "PHP: Hypertext Preprocessor". + +## Further Material + + - Homepage: [php.net](https://secure.php.net/) + - Documentation: [php.net/docs.php](https://secure.php.net/docs.php) + - PHP: The Right Way: [phptherightway.com](http://www.phptherightway.com/) + - Interactive PHP Tutorial: [learn-php.org](http://www.learn-php.org/) + +## Topics, Tools and Terms + +PHP packages were traditionally installed via PEAR (PHP Extension and Application Repository), but more recently the standard package and dependency management tool is Composer. + +Composer lets us run install commands to add packages to our system, for example `composer require phpunit` would add the unit testing framework PHPUnit to our system. + +For instructions on how to install Composer visit [getcomposer.org](https://getcomposer.org/download/). + +### Dependency Management + +Managing dependencies manually is time-consuming, fortunately Composer can automate this. + +We can list our dependencies in a `composer.json` file and run `composer install` to bring these into our project. + +An example `composer.json` file looks like this: + +```json +{ + "name": "example-project", + "require": { + "twig/twig": "^3.0" + }, + "require-dev": { + "phpunit/phpunit": "^8.4" + } +} +``` + +The "require" block tells Composer that the Twig templating package is required for production use and can install Twig with a version of 3.x.x (ie. up to, but not including, version 4). + +The "require-dev" block tells Composer that PHPUnit is required in development, but not in production. + +Dependencies can be added to `composer.json` by + +```bash +composer require author/package-name +``` + +Development dependencies can be added by + +```bash +composer require author/package-name --dev +``` + +Dependencies can be updated to their latest maximum version by running + +```bash +composer update +``` + +Composer will also generate a `composer.lock` file on each `composer update` and the initial `composer install`. This is not meant to be edited directly, it tells Composer to use specific versions of packages - particularly useful when hyhou want your development dependencies to match what you will push to production. + +### Testing Tools + +There are a number of testing tools available for PHP. The most popular one is [PHPUnit](https://phpunit.de/). PHPUnit follows the classic xUnit approach. + +[Behat](http://behat.org/en/latest/) is the most popular behaviour-driven development (BDD) testing framework. + +[Codeception](http://codeception.com/) is a framework combining BDD, unit testing, and integration testing, and is cross-compatible with PHPUnit. + +In this guide we will be using PHPUnit as the testing framework. + +## Directory Structure + +A typical directory structure for a PHP project consists of a `src` directory that contains all source files and a `tests` directory that includes all tests. For web applications the publicly accessible files (eg. `index.php`) would reside in a `public` directory which would then be your webservers document root. + +Another common convention is having a `bin` directory that may contain executable files to start your application. + + - src/ + - test/ + - public/ + - composer.json + - composer.lock + +### Naming Conventions + +Directory names are in lower case. Class and interface files should be in upper case and match the class or interface names. +Configuration, routes, and publicly accessible files should be in lower case. + +For example the class `Example` should be contained in file `Example.php`, the publicly accessible route to the application should be `index.php`. + +Tests match their production code file names with a `Test` suffix, e.g. tests for code in `src/Example.php` should be written in `test/ExampleTest.php`. + +## Example Project + +The main application consists of basically two files: + +- `public/example.php` is the main executable that instantiates and runs: + - `src/Example/Greeting.php` contains the main application. + +### Running the Tests + +All tests can be run by executing + +```bash +vendor/phpunit/phpunit/phpunit +``` + +`phpunit` will automatically find all tests inside the `test` directory and run them based on the configuration in the `phpunit.xml` file. + +#### Testing Approach + +The test for the class `Greeting` verifies that the return value of the `sayHello` method returns the string "Hello {name}", where {name} is the value passed through to the constructor. + +### Running the Application + +PHP has an in-built server for local development. To run this change into the directory `public` and run + +```bash +php -S localhost:8000 +``` + +Then open your browser at `http://localhost:8000/example.php` + +You should see the text "Hello Ada Lovelace" being printed. diff --git a/phpstan.dist.neon b/phpstan.dist.neon new file mode 100644 index 0000000..fad74b2 --- /dev/null +++ b/phpstan.dist.neon @@ -0,0 +1,13 @@ +parameters: + level: 6 + reportUnmatchedIgnoredErrors: false + checkGenericClassInNonGenericObjectType: false + paths: + - publish + - src + - tests + ignoreErrors: + - '#Constant BASE_PATH not found#' + - '#Property [a-zA-Z0-9\\_]+::\$[a-zA-Z0-9]+ is never written, only read\.#' + - '#Method [a-zA-Z0-9\\_]+::[a-zA-Z0-9]+\(\) is unused\.#' + - '#Method [a-zA-Z0-9\\_]+::[a-zA-Z0-9]+\(\) has parameter \$response with no value type specified in iterable type array\.#' diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..df1e643 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,10 @@ + + + + + + ./tests/Unit/ + + + diff --git a/scripts/docker-env.sh b/scripts/docker-env.sh new file mode 100755 index 0000000..9ef8fd5 --- /dev/null +++ b/scripts/docker-env.sh @@ -0,0 +1,10 @@ +#!/usr/bin/env sh + +docker run \ + --pull always \ + -ti --rm --name "hdk-admin" \ + -w "/srv/www" \ + -v "$(pwd)":/srv/www \ + -v ~/.ssh:/root/.ssh \ + -v ~/.gitconfig:/root/.gitconfig \ + harbor.luxcreo.cn/library/hyperf:7.4-swoole /bin/ash diff --git a/scripts/release.sh b/scripts/release.sh new file mode 100755 index 0000000..d141824 --- /dev/null +++ b/scripts/release.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env sh + +docker run --rm -it \ + -v $(pwd):/app -e "GIT_AUTHOR_NAME=$(git config user.name)" -e "EMAIL=$(git config user.email)" \ + detouched/standard-version:latest $1