slimphp / Slim-Skeleton

Slim Framework 4 Skeleton Application
http://www.slimframework.com
MIT License
1.59k stars 479 forks source link

install composer package symfony/console #216

Closed aboutsam closed 3 years ago

aboutsam commented 3 years ago

Hey guys, can you guide me to install the composer package symfony/console?

l0gicgate commented 3 years ago

If you have composer install you could simply do composer require symfony/console.

Is that what you need?

aboutsam commented 3 years ago

I'm not sure how it works. I created a bin/console.php

<?php

require __DIR__ . '/../vendor/autoload.php';

use App\Command\ShowTablesCommand;
use App\Command\ImportTablesCommand;
use App\Command\ImportSubscriptionCommand;
use Symfony\Component\Console\Application;

$app = new Application();

$app->add(new ShowTablesCommand());
$app->add(new ImportTablesCommand());
$app->add(new ImportSubscriptionCommand());

$app->run();

the command appear in my terminal php bin/console.php

Unfortunately, i do not have access to the database when i try to run e.g. ImportSubscriptionCommand

My ImportSubscriptionCommand:

<?php

namespace App\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Illuminate\Database\Capsule\Manager as Capsule;

class ImportSubscriptionCommand extends Command
{
    protected static $defaultName = 'import:subscriptions';

    public function configure()
    {
        $this->setDescription('Import Tables');
    }
    public function execute(InputInterface $input, OutputInterface $output)
    {
        Capsule::schema()->dropIfExists('subscriptions');
        Capsule::schema()->create('subscriptions', function ($table) {
            $table->increments('id');
            $table->integer('store_id')->unsigned(); // 1
            $table->integer('quote_id')->unsigned(); //
            $table->integer('mage_id')->unsigned(); // 836919
            $table->integer('customer_id');
            $table->text('product_data');
            $table->timestamps();
        });

        $output->write("\nImported");
        return Command::SUCCESS;
    }
}

PHP Fatal error: Uncaught Error: Call to a member function connection() on null in /Users/sam/Workspace/lemabo/slim/vendor/illuminate/database/Capsule/Manager.php:98

I guess symfony/console is not part of the PHP-DI. I try to add the commands in my settings and create an cli.php

<?php

use DI\ContainerBuilder;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Input\InputOption;
use App\Command\ExampleCommand;

return function (ContainerBuilder $containerBuilder) {
    $containerBuilder->addDefinitions([
        Application::class => function (ContainerInterface $container) {
            $application = new Application();

            $application->getDefinition()->addOption(
                new InputOption('--env', '-e', InputOption::VALUE_REQUIRED, 'The Environment name.', 'development')
            );

            foreach ($container->get('settings')['commands'] as $class) {
                $application->add($container->get($class));
            }

            return $application;
        }
    ]);
};

Did you already get this up to run?

l0gicgate commented 3 years ago

Closing this as stale.