Skip to content
This repository was archived by the owner on Aug 17, 2022. It is now read-only.

Add console command example #6

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
composer.lock
composer.lock
/nbproject
37 changes: 37 additions & 0 deletions Command/HelloCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Zikula\SpecModule\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class HelloCommand extends ContainerAwareCommand
{
/**
* @var TranslatorInterface
*/
protected $translator;

public function setContainer(ContainerInterface $container = null)
{
parent::setContainer($container);
$this->translator = $container->get('translator.default');
}

protected function configure()
{
$this
->setName('specmodule:hello')
->setDescription('Print hello message.')
->setHelp('This command is just a test.');
}

protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$io->text($this->translator->__('Hello, world.'));
}
}
10 changes: 10 additions & 0 deletions ZikulaSpecModule.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,14 @@

class ZikulaSpecModule extends AbstractModule
{
/**
* This function is necesssary for console commands in Command/*Command.php
* to be recognized by app/console.php
*
* @return boolean
*/
protected function hasCommands()
{
return true;
}
}