yuki777 / bear-sunday-tutorial1-php8

0 stars 0 forks source link

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

Open yuki777 opened 3 years ago

yuki777 commented 3 years ago

https://bearsunday.github.io/manuals/1.0/ja/tutorial.html#diphp 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 adachi@macbookpro.local:~/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)"
}
# log
==> var/log/cli-hal-api-app/app.log <==
[2021-09-03T16:38:40.017344+09:00] DEBUG: req:"get app://self/weekday?year=2011&month=05&day=23" code:0 e:Ray\Di\Exception\Unbound(dependency 'MyVendor\Weekday\MyLoggerInterface' with name '' used in /Users/adachi/tmp/MyVendor.Weekday/src/Resource/App/Wee
kday.php:14 ($logger)) logref:c201017d []

==> var/log/cli-hal-api-app/logref.c201017d.log <==
Fri, 03 Sep 2021 16:38:40 +0900
get app://self/weekday?year=2011&month=05&day=23

Ray\Di\Exception\Unbound(dependency 'MyVendor\Weekday\MyLoggerInterface' with name '' used in /Users/adachi/tmp/MyVendor.Weekday/src/Resource/App/Weekday.php:14 ($logger))
 in file /Users/adachi/tmp/MyVendor.Weekday/vendor/ray/di/src/di/Arguments.php on line 57

#0 /Users/adachi/tmp/MyVendor.Weekday/vendor/ray/di/src/di/Arguments.php(36): Ray\Di\Arguments->getParameter(Object(Ray\Di\Container), Object(Ray\Di\Argument))
#1 /Users/adachi/tmp/MyVendor.Weekday/vendor/ray/di/src/di/NewInstance.php(51): Ray\Di\Arguments->inject(Object(Ray\Di\Container))
#2 /Users/adachi/tmp/MyVendor.Weekday/vendor/ray/di/src/di/Dependency.php(76): Ray\Di\NewInstance->__invoke(Object(Ray\Di\Container))
#3 /Users/adachi/tmp/MyVendor.Weekday/vendor/ray/di/src/di/Container.php(103): Ray\Di\Dependency->inject(Object(Ray\Di\Container))
#4 /Users/adachi/tmp/MyVendor.Weekday/vendor/ray/di/src/di/Container.php(61): Ray\Di\Container->getDependency('MyVendor\\Weekda...')
#5 /Users/adachi/tmp/MyVendor.Weekday/vendor/ray/di/src/di/Injector.php(99): Ray\Di\Container->getInstance('MyVendor\\Weekda...', '')
#6 /Users/adachi/tmp/MyVendor.Weekday/vendor/ray/di/src/di/Injector.php(81): Ray\Di\Injector->bind('MyVendor\\Weekda...')
#7 /Users/adachi/tmp/MyVendor.Weekday/vendor/bear/resource/src/AppAdapter.php(63): Ray\Di\Injector->getInstance('MyVendor\\Weekda...')
#8 /Users/adachi/tmp/MyVendor.Weekday/vendor/bear/resource/src/Factory.php(55): BEAR\Resource\AppAdapter->get(Object(BEAR\Resource\Uri))
#9 /Users/adachi/tmp/MyVendor.Weekday/vendor/bear/resource/src/Resource.php(104): BEAR\Resource\Factory->newInstance(Object(BEAR\Resource\Uri))
#10 /Users/adachi/tmp/MyVendor.Weekday/vendor/bear/resource/src/Resource.php(124): BEAR\Resource\Resource->newInstance(Object(BEAR\Resource\Uri))
#11 /Users/adachi/tmp/MyVendor.Weekday/src/Bootstrap.php(41): BEAR\Resource\Resource->uri('app://self/week...')
#12 /Users/adachi/tmp/MyVendor.Weekday/bin/app.php(8): MyVendor\Weekday\Bootstrap->__invoke('cli-hal-api-app', Array, Array)
#13 {main}
yuki777 commented 3 years ago

以前、php8でチュートリアル1を行ったときは問題なかったので、 依存パッケージのアップデート関連かもしれません。

koriym commented 3 years ago
% php bin/app.php get /weekday/2011/05/23
200 OK
Content-Type: application/hal+json

{
    "weekday": "Mon",
    "_links": {
        "self": {
            "href": "/weekday/2011/05/23"
        }
    }
}

となり、再現できませんでした。

yuki777 commented 3 years ago

composer compileはエラーありません。

#2021-09-03 18:07:18 adachi@macbookpro.local:~/tmp/MyVendor.Weekday main 4eee14d php8.0
 composer compile
> ./vendor/bin/bear.compile 'MyVendor\Weekday' prod-app ./
............................................................
........

Compilation (1/2) took 0.240000 seconds and used 36.846000MB of memory
Success: 68 Failed: 0
Preload compile: /Users/adachi/tmp/MyVendor.Weekday/preload.php
Object graph diagram: /Users/adachi/tmp/MyVendor.Weekday/var/log/prod-app/module.dot
Compilation (2/2) took 0.020000 seconds and used 3.553000MB of memory
autoload.php: /Users/adachi/tmp/MyVendor.Weekday/autoload.php (overwritten)

が、実行ではエラーでした。

#2021-09-03 18:12:50 adachi@macbookpro.local:~/tmp/MyVendor.Weekday main 4eee14d [🤷] 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)"
}
yuki777 commented 3 years ago

(composer compile後に、) autoloadを変更してみました

#2021-09-03 18:15:06 adachi@macbookpro.local:~/tmp/MyVendor.Weekday main 4eee14d [🤷] php8.0
 cat << EOF > autoload.php
<?php
require __DIR__ . '/vendor/autoload.php';
EOF

#2021-09-03 18:15:25 adachi@macbookpro.local:~/tmp/MyVendor.Weekday main 4eee14d [🤷] php8.0
 cat autoload.php
<?php
require __DIR__ . '/vendor/autoload.php';

#2021-09-03 18:15:28 adachi@macbookpro.local:~/tmp/MyVendor.Weekday main 4eee14d [🤷] 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)"
}
#2021-09-03 18:15:49 adachi@macbookpro.local:~/tmp/MyVendor.Weekday main 4eee14d [🤷] php8.0
yuki777 commented 3 years ago

https://github.com/bearsunday/tutorial1/tree/php8 のコードを参照してみます。

yuki777 commented 3 years ago

(composer compile実行せずに、) autoloadを変更して実行したところ、エラーでなくなりました。正常に動作しました。 https://github.com/yuki777/bear-sunday-tutorial1-php8/commit/e8da3cb00e3a532ede617c8050ee400e9f4d9f58

yuki777 commented 3 years ago

(composer compile実行せずに、) autoloadを変更して実行したところ、エラーでなくなりました。正常に動作しました。

こちらのコミットは不要でした。 rm -fr var/tmpでエラーがなくなりました。

koriym commented 3 years ago

rm -fr var/tmpでエラーがなくなりました。

この内容を比較すればもっと分かりそうですね!

yuki777 commented 3 years ago

https://gist.github.com/yuki777/87026e08a85b7fdbb9d9745215a1f53c こちらに再現手順がありました。

# 一時ディレクトリ作成する
cd /tmp

# skeltonからプロジェクトを作成し、MyVendor、Weekdayを入力する
composer create-project bear/skeleton MyVendor.Weekday
 # => What is the vendor name ? MyVendor
 # => What is the project name ? Weekday

# チュートリアル1を自動実行するスクリプトをダウンロードする
wget https://gist.githubusercontent.com/yuki777/87026e08a85b7fdbb9d9745215a1f53c/raw/1fe9db02fe35cf8681aa03c65b9dda4123339903/bear-sunday-tutorial1-php8.bash

# チュートリアル1を実行する
/bin/bash ./bear-sunday-tutorial1-php8.bash