Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
c8ea19a
古のコードなのでいったんキレイにする
kento-oka Jan 22, 2022
2ec45d4
最低限必要な開発用のライブラリを追加
kento-oka Jan 22, 2022
94994ac
コード品質系の各設定ファイルを配置
kento-oka Jan 22, 2022
ae1e2f3
script登録
kento-oka Jan 22, 2022
ad154bc
CI追加
kento-oka Jan 22, 2022
3325811
いろいろ追加
kento-oka Feb 23, 2022
f451952
改行の扱い
kento-oka Feb 23, 2022
77f7e4e
レスポンスを出力する処理はそこまで特徴がなさそうなのでここに実装を置いてしまう
kento-oka Feb 23, 2022
ecf55d0
移動
kento-oka Mar 5, 2022
cdc3477
ルートパラメータも受け取れるようにしなければならない
kento-oka Mar 5, 2022
5e7fd7a
直接このイベントを発生させてはいけない。
kento-oka Mar 5, 2022
9d9fa1c
例のテーブルから対応表を持ってくる
kento-oka Mar 5, 2022
66bf619
reason phrase が空の場合の対応
kento-oka Mar 5, 2022
e25a466
seek対応
kento-oka Mar 5, 2022
1d93c89
移動
kento-oka Mar 5, 2022
c620a59
レスポンスが決定した後に発火するイベント。
kento-oka Mar 5, 2022
9b592fa
命名変更
kento-oka Mar 5, 2022
7cc7c29
actionじゃなくてcontroller
kento-oka Mar 5, 2022
aa73ec1
コントローラーを実行するミドルウェアを追加
kento-oka Mar 5, 2022
20cbbcf
composer phpcbf
kento-oka Mar 5, 2022
732bb36
コントローラーコールバックを直接設定するように
kento-oka Mar 5, 2022
7d537db
一行が長かった
kento-oka Mar 6, 2022
ded98b8
こっちに移す
kento-oka Mar 6, 2022
d43c573
ちょっと変えた
kento-oka Mar 6, 2022
b77c9f6
Merge pull request #5 from fratily/featuer/add_iroiro_1st
kento-oka Mar 6, 2022
bdc5235
typo
kento-oka Mar 13, 2022
cf0c6c9
最低限呼び出せるようにはしておく
kento-oka Mar 23, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto eol=lf
92 changes: 92 additions & 0 deletions .github/workflows/code_quality.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: "Code Quality"

on:
pull_request:
paths:
- src
- composer.json
- phpcs.xml.dist
- phpstan.neon.dist
- phpunit.xml.dist
push:
branches:
- master

jobs:
test:
name: "Test"
runs-on: ${{ matrix.operating-system }}
timeout-minutes: 60

strategy:
fail-fast: false
matrix:
php-version: [ "8.0", "8.1" ]
operating-system: [ ubuntu-latest, windows-latest ]

steps:
- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"

- name: "Install"
run: "composer install --no-interaction --no-progress"

- name: "Test"
run: "composer test"

format:
name: "Format"
runs-on: ${{ matrix.operating-system }}
timeout-minutes: 60

strategy:
fail-fast: false
matrix:
php-version: [ "8.0", "8.1" ]
operating-system: [ ubuntu-latest, windows-latest ]

steps:
- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"

- name: "Install"
run: "composer install --no-interaction --no-progress"

- name: "Format"
run: "composer format"

lint:
name: "Lint"
runs-on: ${{ matrix.operating-system }}
timeout-minutes: 60

strategy:
fail-fast: false
matrix:
php-version: [ "8.0", "8.1" ]
operating-system: [ ubuntu-latest, windows-latest ]

steps:
- name: "Checkout"
uses: "actions/checkout@v2"

- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"

- name: "Install"
run: "composer install --no-interaction --no-progress"

- name: "Lint"
run: "composer lint"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
/vendor/
/composer.lock
/composer.lock
/.phpunit.result.cache
20 changes: 4 additions & 16 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,9 @@
MIT License

Copyright (c) 2017 FratilyPHP
Copyright FratilyPHP

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:
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 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.
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.
92 changes: 0 additions & 92 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,93 +1 @@
# FratilyPHP

Fratily is a web application framework being developed with PHP, for studying.

# 現状での使い方

```php

/**
* Aura DI コンテナ
*/
class DefaultConfig extends Aura\Di\ContainerConfig{

public function define(Aura\Di\Container $di){
$di->set(Interop\Http\Factory\ResponseFactoryInterface::class, $di->lazyNew(Fratily\Http\Factory\ResponseFactory::class));
}
}

/**
* コントローラークラス
*/
class IndexController extends Fratily\Framework\Controller\Controller{

public function index(){
return "This is index page";
}

public function page($page){
return "This is page$page page";
}
}

/*
* アクセスログのようなものを出力するミドルウェア
*/
class AccessMiddleware implements Psr\Http\Server\MiddlewareInterface{

private $dir;

public function __construct(string $dir){
if(!is_dir($dir)){
throw new InvalidArgumentException();
}

$this->dir = realpath($dir);
}

public function process(\Psr\Http\Message\ServerRequestInterface $request, \Psr\Http\Server\RequestHandlerInterface $handler): \Psr\Http\Message\ResponseInterface{
$fp = fopen($this->dir . DIRECTORY_SEPARATOR . "log", "a+");

fwrite($fp, date("Y-m-d H:i:s") . " " . $_SERVER["REQUEST_METHOD"] . "\t" . $_SERVER["REQUEST_URI"] . PHP_EOL);

return $handler->handle($request);
}
}

// DIコンテナを生成
$c = (new Aura\Di\ContainerBuilder)->newConfiguredInstance([
DefaultConfig::class
]);

// ルート定義
$routes = new Fratily\Router\RouteCollector();

$routes->get("index", "/", [
"action" => [IndexController::class, "index"]
]);

$routes->get("page", "/page/{page:[1-9][0-9]*}", [
"action" => [IndexController::class, "page"]
]);

$routes->get("func", "/func", [
"action" => function(){
return "This is function page.";
}
]);

// アプリケーションインスタンスを生成
$app = new Fratily\Framework\Application($c, $routes, true);
// ミドルウェアを追加
$app->append(new AccessMiddleware(__DIR__));

// リクエストインスタンスを生成
$request = (new Fratily\Http\Factory\ServerRequestFactory())->createServerRequestFromArray($_SERVER);

// ミドルウェアハンドラを実行
$handler = $app->generateHandler($request);

// レスポンスを送信
$emitter = new Fratily\Http\Message\Response\Emitter();
$emitter->emit($handler->handle($request));
```
48 changes: 25 additions & 23 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,41 @@
}
],
"license": "MIT",
"scripts": {
"test": [ "@phpunit:unit" ],
"format": [ "@phpcs" ],
"lint": [ "@phpstan" ],

"phpunit:unit": "phpunit --testsuite unit",
"phpcs": "phpcs",
"phpcbf": "phpcbf",
"phpstan": "phpstan analyze"
},
"require": {
"php": "^7.1",
"psr/container": "^1.0",
"psr/log": "^1.0",
"fratily/cache": "^0.0.1",
"fratily/router": "^0.4.0",
"fratily/http-message": "^0.1.0",
"fratily/http-message-factory": "^0.2.0",
"fratily/http-server-middleware": "^0.2.0",
"fratily/reflection": "^0.4.0",
"fratily/utility": "^0.1.0",
"fratily/container": "^0.3.0",
"fratily/event-manager": "^0.1.0",
"twig/twig": "^2.0",
"fratily/debugbar": "^0.2.0"
"php": "^8.0",
"psr/event-dispatcher": "^1.0",
"psr/http-message": "^1.0",
"psr/http-server-handler": "^1.0",
"psr/http-server-middleware": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5",
"squizlabs/php_codesniffer": "^3.6",
"phpstan/phpstan": "^1.4",
"phpstan/phpstan-phpunit": "^1.0",
"phpstan/phpstan-strict-rules": "^1.1"
},
"autoload": {
"psr-4": {
"Fratily\\Framework\\": "src/"
},
"files": [
"src/bootstrap.php"
]
},
"require-dev": {
"phpunit/phpunit": "^7.0"
}
},
"autoload-dev": {
"psr-4": {
"Fratily\\Tests\\Framework\\": "tests/"
}
},
"scripts": {
"test": "phpunit"
"config": {
"sort-packages": true
}
}
22 changes: 22 additions & 0 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<ruleset
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd"
>
<arg name="extensions" value="php" />
<arg name="report" value="code"/>
<arg name="colors"/>
<arg value="ps"/>

<file>./src</file>
<file>./tests</file>

<rule ref="PSR12"></rule>

<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
</ruleset>
10 changes: 10 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
- vendor/phpstan/phpstan-phpunit/rules.neon
- vendor/phpstan/phpstan-strict-rules/rules.neon
parameters:
paths:
- src
- tests
level: max
ignoreErrors:
21 changes: 0 additions & 21 deletions phpunit.xml

This file was deleted.

13 changes: 13 additions & 0 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true"
>
<testsuites>
<testsuite name="unit">
<directory>./tests/Unit</directory>
</testsuite>
</testsuites>
</phpunit>
Loading