Last active
June 9, 2021 17:32
-
-
Save a-r-m-i-n/a46d20ed10122b422c073f9d46107a85 to your computer and use it in GitHub Desktop.
Using Symfony on CLI without a Console application
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
use App\Entity\User; | |
use App\Kernel; | |
use Doctrine\Bundle\DoctrineBundle\Registry; | |
if (!is_file(dirname(__DIR__).'/vendor/autoload_runtime.php')) { | |
throw new LogicException('Symfony Runtime is missing. Try running "composer require symfony/runtime".'); | |
} | |
require_once dirname(__DIR__).'/vendor/autoload_runtime.php'; | |
return function (array $context) { | |
$kernel = new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']); | |
$kernel->boot(); | |
$container = $kernel->getContainer(); | |
/** @var Registry $doctrine */ | |
$doctrine = $container->get('doctrine'); | |
$em = $doctrine->getManagerForClass(User::class); | |
$user = $em->find(User::class, 1); | |
var_dump($user); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment