Skip to content

Psr\Log\LoggerInterface not found #229

Closed

Description

@fufudao

What steps will reproduce the problem?

modify vendor directory, then

in index.php
`$config = new Config(
new ConfigPaths($rootPath,'config','../vendor'),
);

// Run HTTP application runner
$runner = new HttpApplicationRunner($rootPath, $_ENV['YII_DEBUG'], $_ENV['YII_ENV']);
$runner->withConfig($config)->run();`

throwable: Yiisoft\Di\NotFoundException: No definition or class found or resolvable for "Psr\Log\LoggerInterface" while building "Yiisoft\ErrorHandler\ErrorHandler" -> "Psr\Log\LoggerInterface". in ****\vendor\yiisoft\di\src\Container.php:542
Stack trace:
#0 ****\vendor\yiisoft\di\src\Container.php(503): Yiisoft\Di\Container->buildInternal()
#1 ****\vendor\yiisoft\di\src\Container.php(153): Yiisoft\Di\Container->build()
#2 ****\vendor\yiisoft\yii-runner-http\src\HttpApplicationRunner.php(86): Yiisoft\Di\Container->get()
#3 ****\webroot\app\index.php(48): Yiisoft\Yii\Runner\Http\HttpApplicationRunner->run()

What is the expected result?

What do you get instead?

Additional info

Q A
Version 1.0.?
PHP version
Operating system

Activity

  1. terabytesoftw commented on Mar 10, 2022

    @terabytesoftw
    Member

    Can you please post the entire index.php, and the full stack, thanks.

  2. fufudao commented on Mar 10, 2022

    @fufudao
    Author

    index.php

    `<?php
    declare(strict_types=1);

    use Yiisoft\Yii\Runner\Http\HttpApplicationRunner;
    use Yiisoft\Config\Config;
    use Yiisoft\Config\ConfigPaths;
    use Yiisoft\Yii\Runner\ConfigFactory;

    /**

    • @psalm-var string $_SERVER['REQUEST_URI']
      */

    // PHP built-in server routing.
    if (PHP_SAPI === 'cli-server') {
    // Serve static files as is.
    /** @psalm-suppress MixedArgument */
    $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
    if (is_file(DIR . $path)) {
    return false;
    }

    // Explicitly set for URLs with dot.
    $_SERVER['SCRIPT_NAME'] = '/index.php';
    

    }

    require_once dirname(DIR,2) . '/app/autoload.php';

    if (getenv('YII_ENV') === 'test') {
    $c3 = dirname(DIR) . '/c3.php';
    if (file_exists($c3)) {
    require_once $c3;
    }
    }
    $rootPath = dirname(DIR,2).'/app';
    $config = new Config(
    new ConfigPaths($rootPath,'config','../vendor'),
    );

    // Run HTTP application runner
    $runner = new HttpApplicationRunner($rootPath, $_ENV['YII_DEBUG'], $_ENV['YII_ENV']);
    $runner->withConfig($config)->run();`


    ### stack
    2022-03-10 07:21:05.871100 [error][application] Yiisoft\Di\NotFoundException with message 'No definition or class found or resolvable for "Psr\Log\LoggerInterface" while building "Yiisoft\ErrorHandler\ErrorHandler" -> "Psr\Log\LoggerInterface".'

    in ***\vendor\yiisoft\di\src\Container.php:542

    Stack trace:
    #0 ***\vendor\yiisoft\di\src\Container.php(503): Yiisoft\Di\Container->buildInternal()
    #1 ***\vendor\yiisoft\di\src\Container.php(153): Yiisoft\Di\Container->build()
    #2 ***\vendor\yiisoft\yii-runner-http\src\HttpApplicationRunner.php(86): Yiisoft\Di\Container->get()
    #3 ***\webroot\app\index.php(56): Yiisoft\Yii\Runner\Http\HttpApplicationRunner->run()
    #4 {main}

    Message context:

    throwable: Yiisoft\Di\NotFoundException: No definition or class found or resolvable for "Psr\Log\LoggerInterface" while building "Yiisoft\ErrorHandler\ErrorHandler" -> "Psr\Log\LoggerInterface". in ***\vendor\yiisoft\di\src\Container.php:542
    Stack trace:
    #0 ***\vendor\yiisoft\di\src\Container.php(503): Yiisoft\Di\Container->buildInternal()
    #1 ***\vendor\yiisoft\di\src\Container.php(153): Yiisoft\Di\Container->build()
    #2 ***\vendor\yiisoft\yii-runner-http\src\HttpApplicationRunner.php(86): Yiisoft\Di\Container->get()
    #3 ***\webroot\app\index.php(56): Yiisoft\Yii\Runner\Http\HttpApplicationRunner->run()
    #4 {main}
    time: 1646896865.871105
    memory: 2721656
    category: 'application'

  3. xepozz commented on Mar 12, 2022

    @xepozz
    Member

    Do you have this file?

  4. fufudao commented on Mar 13, 2022

    @fufudao
    Author

    yes , I have new ErrorHandler in index.php, it's ok, same problem, thanks

    $runner = new HttpApplicationRunner($rootPath, $_ENV['YII_DEBUG'], $_ENV['YII_ENV']);
    $runner->withTemporaryErrorHandler(new ErrorHandler(
    new Logger([new FileTarget(dirname(DIR) . '/runtime/logs/app.log')]),
    new JsonRenderer(),
    ));
    $runner->withConfig($config)->run();

  5. fufudao commented on Mar 13, 2022

    @fufudao
    Author

    yes , I have new ErrorHandler in index.php, it's ok, thanks

  6. xepozz commented on Mar 13, 2022

    @xepozz
    Member

    Could you share your repo?

  7. fufudao commented on Mar 13, 2022

    @fufudao
    Author

    the same with repo, without yiisoft/yii-debug
    "php": "^8.0",
    "httpsoft/http-message": "^1.0.5",
    "psr/container": "^1.0",
    "psr/http-message": "^1.0",
    "psr/http-server-handler": "^1.0",
    "symfony/console": "^5.3",
    "vlucas/phpdotenv": "^5.3",
    "yiisoft/aliases": "^2.0",
    "yiisoft/assets": "^2.0",
    "yiisoft/cache": "^1.0",
    "yiisoft/cache-file": "^1.0",
    "yiisoft/config": "^1.0",
    "yiisoft/csrf": "^1.2",
    "yiisoft/data-response": "^1.0",
    "yiisoft/definitions": "^1.0",
    "yiisoft/di": "^1.0",
    "yiisoft/error-handler": "^2.0",
    "yiisoft/factory": "^1.0",
    "yiisoft/files": "^1.0",
    "yiisoft/html": "^2.0",
    "yiisoft/http": "^1.2",
    "yiisoft/i18n": "^1.0.0",
    "yiisoft/log": "^1.0",
    "yiisoft/log-target-file": "^1.0",
    "yiisoft/router": "^1.0",
    "yiisoft/router-fastroute": "^1.0",
    "yiisoft/view": "^4.0",
    "yiisoft/yii-console": "^1.0",
    "yiisoft/yii-event": "^1.0",
    "yiisoft/yii-http": "^1.0",
    "yiisoft/yii-runner-console": "^1.0",
    "yiisoft/yii-runner-http": "^1.0",
    "yiisoft/yii-view": "^4.0"

  8. xepozz commented on Mar 13, 2022

    @xepozz
    Member

    So let's roll from the scratch:

    1. mkdir /tmp/yii3log; cd /tmp/yii3log; git clone https://github.com/yiisoft/app .
    2. rm composer.lock
    3. nano composer.lock
    4. paste your dependencies, remove yii-debug-* packages from require-dev section
    5. composer i --prefer-dist
    6. ./yii serve &
    7. curl -I localhost:8080

    And we will see the following output:

    HTTP/1.1 200 OK
    Host: localhost:8080
    Date: Sun, 13 Mar 2022 09:43:58 GMT
    Connection: close
    Set-Cookie: PHPSESSID=s72n72r674fsn06tujtlmckp8vqkqj6e47hhaanib7lafmgn; Domain=localhost; Path=/; HttpOnly; SameSite=Lax
    Content-Type: text/html; charset=UTF-8
    

    If it works for you and doesn't work from your app please share whole project as git repository. Just commit all files and push them to remote repository.

  9. fufudao commented on Mar 17, 2022

    @fufudao
    Author

    hi, I follow your advice, it's ok, then I move app/public to another place, error!
    I use this index.php

    <?php
    
    declare(strict_types=1);
    
    use Yiisoft\Yii\Runner\Http\HttpApplicationRunner;
    use Yiisoft\Config\Config;
    use Yiisoft\Config\ConfigPaths;
    /**
     * @psalm-var string $_SERVER['REQUEST_URI']
     */
    
    // PHP built-in server routing.
    if (PHP_SAPI === 'cli-server') {
        // Serve static files as is.
        /** @psalm-suppress MixedArgument */
        $path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
        if (is_file(__DIR__ . $path)) {
            return false;
        }
    
        // Explicitly set for URLs with dot.
        $_SERVER['SCRIPT_NAME'] = '/index.php';
    }
    
    // require_once dirname(__DIR__) . '/autoload.php';
    require_once dirname(__DIR__,2) . '/app/autoload.php';
    $rootPath = dirname(__DIR__,2).'/app';
    $config = new Config(
        new ConfigPaths($rootPath,'config','vendor'),
    );
    
    echo '3';
    // Run HTTP application runner
    $runner = new HttpApplicationRunner($rootPath, $_ENV['YII_DEBUG'], $_ENV['YII_ENV']);
    // $runner->run();
    $runner->withConfig($config)->run();
    

    log-----------------------------------

    2022-03-17 05:40:49.366700 [error][application] ErrorException with message 'Duplicate key "yiisoft/yii-debug" in the following configs while building "params" group:
     - vendor/yiisoft/yii-debug-api/config/params.php
     - vendor/yiisoft/yii-debug/config/params.php' 
    
    in D:\code\code\yii3\app\vendor\yiisoft\config\src\Merger.php:282
    
    Stack trace:
    #0 D:\code\code\yii3\app\vendor\yiisoft\config\src\Merger.php(145): Yiisoft\Config\Merger->throwDuplicateKeyErrorException()
    #1 D:\code\code\yii3\app\vendor\yiisoft\config\src\Merger.php(69): Yiisoft\Config\Merger->performMerge()
    #2 D:\code\code\yii3\app\vendor\yiisoft\config\src\Config.php(126): Yiisoft\Config\Merger->merge()
    #3 D:\code\code\yii3\app\vendor\yiisoft\config\src\Config.php(99): Yiisoft\Config\Config->buildGroup()
    #4 D:\code\code\yii3\app\vendor\yiisoft\config\src\Config.php(89): Yiisoft\Config\Config->runBuildGroup()
    #5 D:\code\code\yii3\app\vendor\yiisoft\config\src\Config.php(72): Yiisoft\Config\Config->runBuildParams()
    #6 D:\code\code\yii3\app\vendor\yiisoft\yii-runner\src\ApplicationRunner.php(188): Yiisoft\Config\Config->get()
    #7 D:\code\code\yii3\app\vendor\yiisoft\yii-runner\src\ApplicationRunner.php(163): Yiisoft\Yii\Runner\ApplicationRunner->createDefaultContainer()
    #8 D:\code\code\yii3\app\vendor\yiisoft\yii-runner-http\src\HttpApplicationRunner.php(81): Yiisoft\Yii\Runner\ApplicationRunner->getContainer()
    #9 D:\code\code\yii3\webroot\public\index.php(36): Yiisoft\Yii\Runner\Http\HttpApplicationRunner->run()
    #10 {main}
    

    Message context:

    throwable: ErrorException: Duplicate key "yiisoft/yii-debug" in the following configs while building "params" group:
     - vendor/yiisoft/yii-debug-api/config/params.php
     - vendor/yiisoft/yii-debug/config/params.php in D:\code\code\yii3\app\vendor\yiisoft\config\src\Merger.php:282
    Stack trace:
    #0 D:\code\code\yii3\app\vendor\yiisoft\config\src\Merger.php(145): Yiisoft\Config\Merger->throwDuplicateKeyErrorException()
    #1 D:\code\code\yii3\app\vendor\yiisoft\config\src\Merger.php(69): Yiisoft\Config\Merger->performMerge()
    #2 D:\code\code\yii3\app\vendor\yiisoft\config\src\Config.php(126): Yiisoft\Config\Merger->merge()
    #3 D:\code\code\yii3\app\vendor\yiisoft\config\src\Config.php(99): Yiisoft\Config\Config->buildGroup()
    #4 D:\code\code\yii3\app\vendor\yiisoft\config\src\Config.php(89): Yiisoft\Config\Config->runBuildGroup()
    #5 D:\code\code\yii3\app\vendor\yiisoft\config\src\Config.php(72): Yiisoft\Config\Config->runBuildParams()
    #6 D:\code\code\yii3\app\vendor\yiisoft\yii-runner\src\ApplicationRunner.php(188): Yiisoft\Config\Config->get()
    #7 D:\code\code\yii3\app\vendor\yiisoft\yii-runner\src\ApplicationRunner.php(163): Yiisoft\Yii\Runner\ApplicationRunner->createDefaultContainer()
    #8 D:\code\code\yii3\app\vendor\yiisoft\yii-runner-http\src\HttpApplicationRunner.php(81): Yiisoft\Yii\Runner\ApplicationRunner->getContainer()
    #9 D:\code\code\yii3\webroot\public\index.php(36): Yiisoft\Yii\Runner\Http\HttpApplicationRunner->run()
    #10 {main}
    time: 1647495649.366654
    memory: 5610952
    category: 'application'
    
  10. vjik commented on Mar 17, 2022

    @vjik
    Member

    @fufudao try replace

    $config = new Config(
        new ConfigPaths($rootPath,'config','vendor'),
    );
    

    to

    $config = \Yiisoft\Yii\Runner\ConfigFactory::create(new ConfigPaths($rootPath,'config','vendor'), null);
    

    Config should use recursive merge for params. ConfigFactory configure it.

  11. locked and limited conversation to collaborators on Mar 18, 2022
  12. converted this issue into a discussion #231 on Mar 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions