Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working Symfony 6 example? #655

Closed
imper86 opened this issue Mar 27, 2022 · 4 comments · Fixed by #886
Closed

Working Symfony 6 example? #655

imper86 opened this issue Mar 27, 2022 · 4 comments · Fixed by #886
Milestone

Comments

@imper86
Copy link

imper86 commented Mar 27, 2022

Hello,

I just started having fun with Box and tried to compile simple (empty) symfony 6 application. After successfully compiling I have an error:

PHP Warning:  Constant  already defined in /home/imper/projects/phartest/build/app.phar on line 16
PHP Fatal error:  Uncaught TypeError: Invalid return value: callable object expected, "int" returned from "./build/app.phar". in phar:///home/imper/projects/phartest/build/app.phar/vendor/autoload_runtime.php:12
Stack trace:
#0 phar:///home/imper/projects/phartest/build/app.phar/bin/console(10): require_once()
#1 /home/imper/projects/phartest/build/app.phar(14): require('...')
#2 {main}
  thrown in phar:///home/imper/projects/phartest/build/app.phar/vendor/autoload_runtime.php on line 12

I'm stuck, don't know what I should do with this. Do you have any working Symfony 6 example repository? Should I maybe modify bin/console somehow?

@Braxilior
Copy link

Hello,

I had the same error and I found this issue: symfony/symfony#41771

I did the following modifications and it worked for me.

bin/console:

#!/usr/bin/env php
<?php

if (!is_file(dirname(__DIR__).'/config/autoload_runtime.php')) {
    throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".');
}

require_once dirname(__DIR__).'/config/autoload_runtime.php';

config/autoload_runtime.php

<?php

use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;

if (true === (require_once __DIR__.'/../vendor/autoload.php')) {
    return;
}

$app = function (array $context) {
    $kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
    return new Application($kernel);
};

if (!is_object($app)) {
    throw new TypeError(sprintf('Invalid return value: callable object expected, "%s" returned from "%s".', get_debug_type($app), $_SERVER['SCRIPT_FILENAME']));
}

$runtime = $_SERVER['APP_RUNTIME'] ?? $_ENV['APP_RUNTIME'] ?? 'Symfony\\Component\\Runtime\\SymfonyRuntime';
$runtime = new $runtime(($_SERVER['APP_RUNTIME_OPTIONS'] ?? $_ENV['APP_RUNTIME_OPTIONS'] ?? []) + [
        'project_dir' => dirname(__DIR__, 1),
    ]);

[$app, $args] = $runtime
    ->getResolver($app)
    ->resolve();

$app = $app(...$args);

exit(
$runtime
    ->getRunner($app)
    ->run()
);

@theofidry
Copy link
Member

I've created symfony/symfony#49443 to workout a solution.

@theofidry
Copy link
Member

theofidry commented Feb 19, 2023

(commenting here because for some reasons I currently cannot comment on the PR itself, I'm getting a 500...)

Thank you for the PR (#881) @aradoje.

I'm unfortunately not going to merge this immediately for a few reasons:

  • I would like to add an E2E test within Box to ensure it works fine with Symfony6, with or without the suggested solution (see doc: Add a Symfony6 example #886)
  • I think the current suggested solution is sub-par: when you end up doing is circumventing the Symfony runtime component: so it will work within the PHAR, but the regular console script no longer really use the runtime component. IMO a cleaner solution would be to remove the runtime component altogether.*

*: I opened symfony/symfony#49443 because I do think the runtime component should just work with PHARs out of the box, rather than requiring more fiddling.

@aradoje
Copy link
Contributor

aradoje commented Feb 19, 2023

Thanks, sounds good 👍🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants