Code Monkey home page Code Monkey logo

bearsunday.github.io's Introduction

BEAR.Sunday - A resource oriented framework

A resource orientated framework with a REST Hypermedia centered architecture, implementing Dependency Injection and Aspect Orientated Programming' at it's core.

Hosting and Rendering

The documentations are rendered with Jekyll and hosted at http://bearsunday.github.io/.

Start Server with Docker

./bin/served.sh

Start Server in local Ruby environment

Install

gem install jekyll bundler
bundle install

Run

./bin/servel.sh

bearsunday.github.io's People

Contributors

77web avatar apple-x-co avatar bakura10 avatar dependabot[bot] avatar kawanamiyuu avatar kazuyauchida avatar kenjis avatar koriym avatar kuma-guy avatar kumamidori avatar kushibikimashu avatar mackstar avatar madapaja avatar momospnr avatar naokitsuchiya avatar nes801 avatar odelgreg avatar oishii-pudding avatar okapon avatar piotzkhider avatar polidog avatar pon57 avatar rydein avatar sasezaki avatar suzumaze avatar t-miura0203 avatar tnohara46 avatar yahiru avatar yoshikitanaka avatar yutakachiba avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bearsunday.github.io's Issues

アプリケーションインポートが動作しない

アプリケーション環境

  • bear/sunday: "1.0.1"
    • ray/di: "2.2.2"

問題点

下記チュートリアルの「アプリケーションのインポート」セクションにて、

次にアプリケーションをインポートするためにsrc/Module/AppModule.phpでImportAppModuleを上書き(override)インストールします。

とあるが、この箇所が動作しない。

http://bearsunday.github.io/manuals/1.0/ja/tutorial.html

詳細

下記のとおり Context クラスがが使われているのだが、このクラスは実際には存在していない。

https://github.com/bearsunday/MyVendor.Weekday/blob/1.x/src/Module/AppModule.php#L16
use BEAR\Package\Context;
https://github.com/bearsunday/MyVendor.Weekday/blob/1.x/src/Module/AppModule.php#L48
$this->override(new ImportAppModule($importConfig , Context::class));

すみませんが、解決方法が分かりませんでした。ご確認頂ければと思います 🍊

Optional parameters

In the first example in the tutorial:

class Weekday extends ResourceObject
{
    public function onGet(int $year, int $month, int $day) : ResourceObject
    {
        $date = \DateTime::createFromFormat('Y-m-d', "$year-$month-$day");
        $this['weekday'] = $date->format('D');

        return $this;
    }
}

It's returning 400 if none of the parameters are set. Does changing the signature from int $day to int $day = 1 makes it optional by convention?

Should likely be specified here in the doc :)

Comments ?

We feel a more work is needed for the documentation. But what is it ? What are we missing / inefficient for ? :( Please let us know. Any comment or review are welcome and helpful.

http://bearsunday.github.io/

  • Missing chapter
  • Unclear points
  • Example code
  • Terminology
  • Bad English

Proofreading / 校正

http://bearsunday.github.io/

校正方法

Wikiの校正リストを開きます。

  1. 章を選びます。チェックがついてないものは誰もまだ校正してないか、その後に編集が行われてからは構成されていないものです。
  2. 通読して意味は分かるか、誤字脱字はないか、読んでみて問題が無ければこのissueに追記します。提案や疑問はissueにお願いします。
  3. @BEARSundayにもメンションして完了です!

チュートリアルでPOSTリクエストを実行するとエラーが発生する

チュートリアルのDBにtodoを追加するPOSTリクエストを行うと下記のエラーが発生する。

php bin/test.php get '/todos?id=1'

PHP Fatal error:  Uncaught exception 'Ray\Compiler\Exception\Unbound' with message 'Psr\Cache\CacheItemPoolInterface-Ray\PsrCacheModule\Annotation\Shared'

  thrown in /{HOME}/MyVendor.Weekday/vendor/ray/compiler/src/CompileInjector.php on line 164

Fatal error: Uncaught exception 'Ray\Compiler\Exception\Unbound' with message 'Psr\Cache\CacheItemPoolInterface-Ray\PsrCacheModule\Annotation\Shared'

  thrown in /{HOME}/MyVendor.Weekday/vendor/ray/compiler/src/CompileInjector.php on line 164

チュートリアル1のDIでエラーになる

https://bearsunday.github.io/manuals/1.0/ja/tutorial.html#di
php bin/app.php get /weekday/2011/05/23 を実行するとエラーになる。

再現手順

composer install
php bin/app.php get /weekday/2011/05/23

実行

#2021-09-03 16:34:56 [email protected]:~/tmp/MyVendor.Weekday php8.0
! php bin/app.php get /weekday/2011/05/23

500 Internal Server Error
content-type: application/vnd.error+json

{
"message": "Internal Server Error",
"logref": "c201017d",
"request": "get app://self/weekday?year=2011&month=05&day=23",
"exceptions": "Ray\Di\Exception\Unbound(dependency 'MyVendor\Weekday\MyLoggerInterface' with name '' used in /Users/adachi/tmp/MyVendor.Weekday/src/Resource/App/Weekday.php:14 ($logger))",
"file": "/Users/adachi/tmp/MyVendor.Weekday/vendor/ray/di/src/di/Arguments.php(57)"
}

チュートリアル2のモジュールでエラーになる

概要

https://bearsunday.github.io/manuals/1.0/ja/tutorial2.html
composer require ray/identity-value-module ray/media-query を実行するとエラーになる

再現手順

composer require ray/identity-value-module ray/media-query

実行結果

Using version ^1.0 for ray/identity-value-module
Using version ^0.5.0 for ray/media-query
./composer.json has been updated
Running composer update ray/identity-value-module ray/media-query
Loading composer repositories with package information
Updating dependencies
Your requirements could not be resolved to an installable set of packages.

  Problem 1
    - Root composer.json requires ray/media-query ^0.5.0 -> satisfiable by ray/media-query[0.5.0].
    - ray/media-query 0.5.0 requires aura/sql ^4.0 || ^5.0 -> found aura/sql[4.0.0, 5.0.0, 5.0.1] but the package is fixed to 3.0.0 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.

Use the option --with-all-dependencies (-W) to allow upgrades, downgrades and removals for packages currently locked to specific versions.
You can also try re-running composer require with an explicit version constraint, e.g. "composer require ray/identity-value-module:*" to figure out if any version is installable, or "composer require ray/identity-value-module:^2.1" if you know which you need.

チュートリアルでRay\\Di\\Exception\\Unboundが発生する

Bug Report

チュートリアルのHTMLの章で以下のコマンドを実行時エラーが発生する

php bin/page.php get '/?year=2000&month=1&day=1'

エラー

php bin/page.php get '/?year=2000&month=1&day=1'
500 Internal Server Error
content-type: application/vnd.error+json

{
    "message": "Internal Server Error",
    "logref": "8447963f",
    "request": "get page://self/?year=2000&month=1&day=1",
    "exceptions": "Ray\\Di\\Exception\\Unbound(dependency 'MyVendor\\Weekday\\Resource\\App\\Weekday' with name '' used in /Users/daichi.yamazaki/git/MyVendor.Weekday/src/Resource/Page/Index.php:12 ($weekday))",
    "file": "/Users/daichi.yamazaki/git/MyVendor.Weekday/vendor/ray/di/src/di/Arguments.php(56)"
}

インストールされているdiがv2.16.1なため、AppModule.phpに以下を追記してエラーは解消できました

$this->bind(Weekday::class);

チュートリアル2のハイパーメディアAPIテストでエラー

現象: チュートリアル2のハイパーメディアAPIテストで以下のエラーが発生します。

bash-5.1# ./vendor/bin/phpunit --testsuite hypermedia
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.

ESSS                                                                4 / 4 (100%)

Time: 00:00.360, Memory: 10.00 MB

There was 1 error:

1) MyVendor\Ticket\Hypermedia\WorkflowTest::testIndex
BEAR\Resource\Exception\ResourceNotFoundException: app://self/index

/var/www/html/MyVendor.Ticket/vendor/bear/resource/src/AppAdapter.php:80
/var/www/html/MyVendor.Ticket/vendor/bear/resource/src/AppAdapter.php:67
/var/www/html/MyVendor.Ticket/vendor/bear/resource/src/Factory.php:55
/var/www/html/MyVendor.Ticket/vendor/bear/resource/src/Resource.php:104
/var/www/html/MyVendor.Ticket/vendor/bear/resource/src/Resource.php:124
/var/www/html/MyVendor.Ticket/vendor/bear/resource/src/Resource.php:206
/var/www/html/MyVendor.Ticket/vendor/bear/resource/src/Resource.php:151
/var/www/html/MyVendor.Ticket/tests/Hypermedia/WorkflowTest.php:30

Caused by
Ray\Di\Exception\Unbound: MyVendor\Ticket\Resource\App\Index-

/var/www/html/MyVendor.Ticket/vendor/ray/di/src/di/Container.php:136
/var/www/html/MyVendor.Ticket/vendor/ray/di/src/di/Container.php:99
/var/www/html/MyVendor.Ticket/vendor/ray/di/src/di/Container.php:62
/var/www/html/MyVendor.Ticket/vendor/ray/di/src/di/Injector.php:75
/var/www/html/MyVendor.Ticket/vendor/bear/resource/src/AppAdapter.php:64
/var/www/html/MyVendor.Ticket/vendor/bear/resource/src/Factory.php:55
/var/www/html/MyVendor.Ticket/vendor/bear/resource/src/Resource.php:104
/var/www/html/MyVendor.Ticket/vendor/bear/resource/src/Resource.php:124
/var/www/html/MyVendor.Ticket/vendor/bear/resource/src/Resource.php:206
/var/www/html/MyVendor.Ticket/vendor/bear/resource/src/Resource.php:151
/var/www/html/MyVendor.Ticket/tests/Hypermedia/WorkflowTest.php:30

ERRORS!   
Tests: 4, Assertions: 0, Errors: 1, Skipped: 3.

Index.phpsrc/Resource/Page ではなく src/Resource/App に置くとテストは動作します。

bash-5.1# ./vendor/bin/phpunit --testsuite hypermedia
PHPUnit 9.5.10 by Sebastian Bergmann and contributors.

....                                                                4 / 4 (100%)

Time: 00:00.397, Memory: 16.00 MB

OK (4 tests, 4 assertions)

Index.php のパスがコミット ID 5255c26src/Resource/App から src/Resource/Page に変更されていますが、コンテキストが hal-api-app のため元の src/Resource/App/Index.php にあるのが正しいと思います。

Tutorial2 migration の実行時エラー

概要

tutorial2 、マイグレーションの章内の設定、手順通りに実行するとマイグレーションが実行されない。

リポジトリ

以下のコミットが #192 の修正後の設定ファイル郡になります。
NaokiTsuchiya/BEARSunday.tutorial2@e00faf5

詳細

接続先のポート番号指定が省略されている

上記コミットの状態で./vendor/bin/phinx create Ticket -c var/phinx/phinx.phpを実行すると以下のエラーになります。

./vendor/bin/phinx create Ticket -c var/phinx/phinx.php             
Phinx by CakePHP - https://phinx.org.

using config file var/phinx/phinx.php

In phinx.php line 9:

  SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known


In phinx.php line 9:

  PDO::__construct(): php_network_getaddresses: getaddrinfo failed: nodename nor servname provided, or not known


create [-c|--configuration CONFIGURATION] [-p|--parser PARSER] [-t|--template TEMPLATE] [-l|--class CLASS] [--path PATH] [--] [<name>]

単にMySQL側のポート番号が省略されているだけかもしれませんが、TKT_DB_HOST=127.0.0.1:3360 のように書き換えても良いかもしれません。

./vendor/bin/phinx create Ticket -c var/phinx/phinx.php 実行時にUnknown database error

上記のポート番号の設定を追加後の状態が以下になります。

https://github.com/NaokiTsuchiya/BEARSunday.tutorial2/commits/can-not-run-migration

この状態で再度 ./vendor/bin/phinx create Ticket -c var/phinx/phinx.php を実行すると、以下のエラーになります。

./vendor/bin/phinx create Ticket -c var/phinx/phinx.php                             
Phinx by CakePHP - https://phinx.org.

using config file var/phinx/phinx.php

In phinx.php line 8:

  SQLSTATE[HY000] [1049] Unknown database 'ticket'


create [-c|--configuration CONFIGURATION] [-p|--parser PARSER] [-t|--template TEMPLATE] [-l|--class CLASS] [--path PATH] [--] [<name>]

上記エラーはTKT_DB_DSN=mysql:host=${TKT_DB_HOST};dbname=${TKT_DB_NAME} のように dbname が指定されていますが、この時点ではticket database が存在しないことが原因です。

./vendor/bin/phinx create Ticket -c var/phinx/phinx.php の実行前に、composer setup を実行していれば回避できるので、実行順を変更した方が良いかもしれません。

もしくは、以下のような手順にする必要があります。

  • TKT_DB_DSN=mysql:host=${TKT_DB_HOST}のように接続先のdbnameを省略して ./vendor/bin/phinx create Ticket -c var/phinx/phinx.php を実行する
  • TKT_DB_DSN=mysql:host=${TKT_DB_HOST};dbname=${TKT_DB_NAME} に変更して composer setup を実行

上記の場合だと1stepファイルの変更が増えてしまいます。

Japanese manual

現在manuail/enをmanual/jaにコピーしてあるので、それをBEAR.Resource / Ray.Di等の日本語READMEあるいは、Google codeのwiki等から日本語を抜き出して現在英語の/jaを日本語化する。

リンク切れがあります

https://bearsunday.github.io/manuals/1.0/ja/tutorial.html#aop

(メソッド実行オブジェクトMethodInvocation $invocationから元メソッドのオブジェクトとメソッドの名前を取得しています。)

MethodInvocationにリンクされているURL http://www.bear-project.net/Ray.Aop/build/apigen/class-Ray.Aop.MethodInvocation.html がリンク切れ起こしています。

同様に

次にベンチマークをしたいメソッドに目印をつけるためのアノテーションをsrc/Annotation/BenchMark.php に作成します。

アノテーションにリンクされている http://www.bear-project.net/Ray.Aop/build/apigen/class-Ray.Aop.MethodInvocation.html もリンク切れを起こしています。

https://bearsunday.github.io/manuals/1.0/ja/tutorial.html
内のほかのリンクも踏んでみましたがリンク切れはこの2カ所だけのようでした。

ご対応ください。

チュートリアル2(ticketリソース、ticketsリソース)でJsonSchemaの記述をするとエラーになる

ticketリソース

https://bearsunday.github.io/manuals/1.0/ja/tutorial2.html#tikcetリソース
src/Resource/App/Ticket.phpに以下を記述。

<?php

declare(strict_types=1);

namespace MyVendor\Ticket\Resource\App;

use BEAR\Resource\Annotation\JsonSchema;
use BEAR\Resource\ResourceObject;
use MyVendor\Ticket\Query\TicketQueryInterface;

class Ticket extends ResourceObject
{
    public function __construct(
        private TicketQueryInterface $query
    ){}
    
   #[JsonSchema("ticket.json")]
   public function onGet(string $id = ''): static
    {
        $this->body = $this->query->item($id);

        return $this;
    }
}

php bin/app.php get '/ticket?id=1'を実行すると、以下のエラーになる。

shotamiyazaki@kiseki0001noMacBook-Air MyVendor.Ticket % php bin/app.php get '/ticket?id=1'
500 Internal Server Error
content-type: application/vnd.error+json

{
    "message": "Internal Server Error",
    "logref": "072c4608",
    "request": "get app://self/ticket?id=1",
    "exceptions": "BEAR\\Resource\\Exception\\JsonSchemaException([id] The property id is required; [title] The property title is required; [date_created] The property date_created is required; [] Array value found, but an array is required; by /Users/shotamiyazaki/PhpstormProjects/MyVendor.Ticket/var/schema/response/ticket.json)",
    "file": "/Users/shotamiyazaki/PhpstormProjects/MyVendor.Ticket/vendor/bear/resource/src/JsonSchema/Interceptor/JsonSchemaInterceptor.php(168)"
}

src/Resource/App/Ticket.phpの#[JsonSchema("ticket.json")]の部分をコメントアウトすると、エラーになることなく、以下のデータが取得できる。

shotamiyazaki@kiseki0001noMacBook-Air MyVendor.Ticket % php bin/app.php get '/ticket?id=1'
200 OK
Content-Type: application/hal+json

{
    "0": {
        "id": "1",
        "title": "foo",
        "date_created": "1970-01-01 00:00:00"
    },
    "_embedded": {
        "project": {
            "title": "Project A",
            "_links": {
                "self": {
                    "href": "/project"
                }
            }
        }
    },
    "_links": {
        "self": {
            "href": "/ticket?id=1"
        }
    }
}

ticketsリソース

https://bearsunday.github.io/manuals/1.0/ja/tutorial2.html#ticketsリソース
src/resource/App/Tickets.phpに以下を記述

<?php

declare(strict_types=1);

namespace MyVendor\Ticket\Resource\App;

use BEAR\Resource\Annotation\JsonSchema;
use BEAR\Resource\Annotation\Link;
use BEAR\Resource\ResourceObject;
use Koriym\HttpConstants\ResponseHeader;
use Koriym\HttpConstants\StatusCode;
use MyVendor\Ticket\Query\TicketCommandInterface;
use MyVendor\Ticket\Query\TicketQueryInterface;
use Ray\IdentityValueModule\UuidInterface;
use function uri_template;

class Tickets extends ResourceObject
{
    public function __construct(
        private TicketQueryInterface $query,
        private TicketCommandInterface $command,
        private UuidInterface $uuid
    ){}

    #[Link(rel: "doPost", href: '/tickets')]
    #[Link(rel: "goTicket", href: '/ticket{?id}')]
    #[JsonSchema("tickets.json")]
    public function onGet(): static
    {
        $this->body = [
            'tickets' => $this->query->list()
        ];
        
        return $this;
    }

    #[Link(rel: "goTickets", href: '/tickets')]
    public function onPost(string $title): static
    {
        $id = (string) $this->uuid;
        $this->command->add($id, $title);

        $this->code = StatusCode::CREATED;
        $this->headers[ResponseHeader::LOCATION] = uri_template('/ticket{?id}', ['id' => $id]);

        return $this;
    }
}

php bin/app.php get '/tickets'を実行すると、以下のエラーになる。

shotamiyazaki@kiseki0001noMacBook-Air MyVendor.Ticket % php bin/app.php get '/tickets'
500 Internal Server Error
content-type: application/vnd.error+json

{
    "message": "Internal Server Error",
    "logref": "a606b750",
    "request": "get app://self/tickets",
    "exceptions": "BEAR\\Resource\\Exception\\JsonSchemaException([tickets[0]] Object value found, but an array is required; [tickets[1]] Object value found, but an array is required; [tickets[2]] Object value found, but an array is required; by /Users/shotamiyazaki/PhpstormProjects/MyVendor.Ticket/var/schema/response/tickets.json)",
    "file": "/Users/shotamiyazaki/PhpstormProjects/MyVendor.Ticket/vendor/bear/resource/src/JsonSchema/Interceptor/JsonSchemaInterceptor.php(168)"
}

src/Resource/App/Tickets.phpの#[JsonSchema("ticket.json")]の部分をコメントアウトすると、エラーになることなく、以下のデータが取得できる。

shotamiyazaki@kiseki0001noMacBook-Air MyVendor.Ticket % php bin/app.php get '/tickets'
200 OK
Content-Type: application/hal+json

{
    "tickets": [
        {
            "id": "1",
            "title": "foo",
            "date_created": "1970-01-01 00:00:00"
        },
        {
            "id": "e8835c88-a834-427a-a4ef-13566cfc3889",
            "title": "ffff",
            "date_created": "2022-06-03 09:25:48"
        },
        {
            "id": "c4009526-7913-4d69-89d2-ad36868eacda",
            "title": "test",
            "date_created": "2022-06-06 00:09:55"
        }
    ],
    "_links": {
        "self": {
            "href": "/tickets"
        },
        "doPost": {
            "href": "/tickets"
        },
        "goTicket": {
            "href": "/ticket"
        }
    }
}

@Todo

Here are my thoughts.

  • DI / AOP section is OK.
  • Transfer REST section in google-code to Hypermedia in github.io
  • Application section also needs to be transferred.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.