I want to run console like in normal symfony app by php bin/console
but configuration is difficult for me.
AppKernel.php
use Symfony\Bundle\FrameworkBundle\Kernel\MicroKernelTrait;
...
$loader = require __DIR__.'/../vendor/autoload.php';
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
class AppKernel extends Kernel
{
use MicroKernelTrait;
public function registerBundles()
{
$bundles = array(
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
...
);
return $bundles;
}
protected function configureContainer(ContainerBuilder $c, LoaderInterface $loader)
{
$loader->load(__DIR__.'/config/config.yml');
}
protected function configureRoutes(RouteCollectionBuilder $routes)
{
$routes->import(__DIR__.'/../src/App/Controller/', '/', 'annotation');
}
public function getCacheDir()
{
return __DIR__.'/../var/cache/'.$this->getEnvironment();
}
public function getLogDir()
{
return __DIR__.'/../var/logs';
}
}
File structure:
├─ app/
| ├─ AppKernel.php
│ ├─ config/
│ └─ Resources
| └─ views
| └─ micro
├─ src/
│ └─ App
| └─ Controller
| └─ MicroController.php
├─ var/
| ├─ cache/
│ └─ logs/
├─ vendor/
│ └─ ...
├─ web/
| └─ index.php
├─ composer.json
└─ composer.lock
└─ console
I add bin dir with console file like is in normal symfony but I get:
Fatal error: require(): Failed opening required 'C:\xampp\htdocs\symfony-skeleton-micro-app/app/autoload.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\symfony-skeleton-micro-app\console on line 16 PHP Warning: require(C:\xampp\htdocs\symfony-skeleton-micro-app/app/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\symfony-skeleton-micro-app\console on line 16 PHP Fatal error: require(): Failed opening required 'C:\xampp\htdocs\symfony-skeleton-micro-app/app/autoload.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\symfony-skeleton-micro-app\console on line 16
console
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;
// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/setup.html#checking-symfony-application-configuration-and-setup
// for more information
//umask(0000);
set_time_limit(0);
/** @var Composer\Autoload\ClassLoader $loader */
$loader = require __DIR__.'/app/autoload.php';
$input = new ArgvInput();
$env = $input->getParameterOption(['--env', '-e'], getenv('SYMFONY_ENV') ?: 'dev');
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(['--no-debug', '']) && $env !== 'prod';
if ($debug) {
Debug::enable();
}
$kernel = new AppKernel($env, $debug);
$application = new Application($kernel);
$application->run($input);
$loader
variable points toproject_root/app
instead ofproject_root/vendor
. Try fixing that first. – Artamiel$loader = require __DIR__.'/../vendor/autoload.php';
? – mcekbin/console
require the autoload file to be inapp/autoload.php
? github.com/symfony/symfony-standard/blob/3.2/bin/console#L15 – Yann EugonéPHP Fatal error: Class 'AppKernel' not found in C:\xampp\htdocs\symfony-skeleton-micro-app\console on line 27
– mcek