यदि आपको तर्क (और/या विकल्प) पास करना है, तो v2.0.12 (और बाद के संस्करणों के लिए सच हो सकता है) में, आपको इनपुट ऑब्जेक्ट को तुरंत चालू करने से पहले इनपुट डिफिनेशन निर्दिष्ट करना होगा।
use // you will need the following
Symfony\Component\Console\Input\InputOption,
Symfony\Component\Console\Input\InputArgument,
Symfony\Component\Console\Input\InputDefinition,
Symfony\Component\Console\Input\ArgvInput,
Symfony\Component\Console\Output\NullOutput;
// tell symfony what to expect in the input
$inputDefinition = new InputDefinition(array(
new InputArgument('myArg1', InputArgument::REQUIRED),
new InputArgument('myArg2', InputArgument::REQUIRED),
new InputOption('debug', '0', InputOption::VALUE_OPTIONAL),
));
// then pass the values for arguments to constructor, however make sure
// first param is dummy value (there is an array_shift() in ArgvInput's constructor)
$input = new ArgvInput(
array(
'dummySoInputValidates' => 'dummy',
'myArg2' => 'myValue1',
'myArg2' => 'myValue2'),
$inputDefinition);
$output = new NullOutput();
एक तरफ ध्यान दें, यदि आप उपयोग कर रहे हैं आप अपने आदेश में getContainer() का उपयोग कर रहे हैं, उसके बाद निम्न समारोह अपने command.php के लिए आसान हो सकता है:
/**
* Inject a dependency injection container, this is used when using the
* command as a service
*
*/
function setContainer(\Symfony\Component\DependencyInjection\ContainerInterface $container = null)
{
$this->container = $container;
}
/**
* Since we are using command as a service, getContainer() is not available
* hence we need to pass the container (via services.yml) and use this function to switch
* between conatiners..
*
*/
public function getcontainer()
{
if (is_object($this->container))
return $this->container;
return parent::getcontainer();
}
'--some-option' उदाहरण के लिए +1 – gondo
मुझे 2.4 – RedactedProfile
@DJDarkViper में' setContainer' विधि नहीं मिलती है अद्यतन उत्तर देखें। – Dmitriy