0

i have problem with get my class function to which i send files from terminal. It's see that:

terminal: // php src/AppBundle/Provider/CommissionCost.php test.csv 

in CommissionCost i want only put data to my function in Parser/CommissionDataParser.php

    global $kernel;

    $data = $kernel->getContainer()->get('data.parser')->getData($argv[1]);

    var_dump($data);
//Uncaught Error: Call to a member function getContainer() on null  
// this example i see in stackoverflow in topic about container : )

service:

 services:
   data.parser:
          class: AppBundle\Parser\CommissionDataParser
          arguments: ["@doctrine.orm.entity_manager"]
  • 4
    OMG `global`? really? http://stackoverflow.com/questions/12445972/stop-using-global-in-php – Tomasz Madeyski Nov 08 '16 at 13:38
  • 1
    It looks like you are trying to run CommissionCost directly? Is there anything in there that is initializing the app kernel? I suspect not. To gain access to the full symfonf container you will need to wrap your functionality in a console command: http://symfony.com/doc/current/console.html – Cerad Nov 08 '16 at 13:44
  • i need send from terminal file, if i create console command , how i send file? –  Nov 08 '16 at 13:59
  • php bin/console commission_cost test.csv I suspect we have a language barrier here and I'm answering something completely different than what is being aaked. – Cerad Nov 08 '16 at 14:04
  • yes, my english is very badly : ) i undestand that you want say me, but i try create console command and after run that you talk me and catch error because after command name, can be arguments but not file , maybe with something arguments ? –  Nov 08 '16 at 14:09

1 Answers1

0

You need to add this in the configure method:

$this->addArgument('arg1', InputArgument::REQUIRED, 'Your first arg');

Then, you can access to it in the execute method by:

$input->getArgument('arg1');
progg
  • 294
  • 1
  • 4