commit b47194deed153c8975513c9e941cd1d4d331804e
parent 656bc3752cd98d25af5ff0bc3deb9ea8f00bf316
Author: Timo A. Hummel <felicitus@felicitus.org>
Date: Sat, 23 May 2015 20:43:34 +0200
Added command "partkeepr:user:create"
Diffstat:
2 files changed, 56 insertions(+), 0 deletions(-)
diff --git a/src/PartKeepr/AuthBundle/Console/Command/CreateUserCommand.php b/src/PartKeepr/AuthBundle/Console/Command/CreateUserCommand.php
@@ -0,0 +1,46 @@
+<?php
+namespace PartKeepr\AuthBundle\Console\Command;
+
+use Doctrine\ORM\EntityManager;
+use PartKeepr\AuthBundle\Entity\User\User;
+use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
+use Symfony\Component\Console\Input\InputArgument;
+use Symfony\Component\Console\Input\InputInterface;
+use Symfony\Component\Console\Output\OutputInterface;
+
+class CreateUserCommand extends ContainerAwareCommand
+{
+ protected function configure()
+ {
+ $this
+ ->setName('partkeepr:user:create')
+ ->setDescription('Creates an user')
+ ->addArgument(
+ 'username',
+ InputArgument::REQUIRED,
+ 'The username'
+ )
+ ->addArgument(
+ 'password',
+ InputArgument::REQUIRED,
+ 'The password'
+ );
+ }
+
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
+ $username = $input->getArgument('username');
+ $password = $input->getArgument('password');
+
+ $user = new User($username, $password);
+
+ $em = $this->getContainer()->get('doctrine')->getManager();
+
+ /** @var $em EntityManager */
+
+ $em->persist($user);
+ $em->flush();
+
+ $output->writeln("User created");
+ }
+}+
\ No newline at end of file
diff --git a/src/PartKeepr/AuthBundle/PartKeeprAuthBundle.php b/src/PartKeepr/AuthBundle/PartKeeprAuthBundle.php
@@ -2,8 +2,17 @@
namespace PartKeepr\AuthBundle;
+use PartKeepr\AuthBundle\Console\Command\CreateUserCommand;
+use Symfony\Component\Console\Application;
use Symfony\Component\HttpKernel\Bundle\Bundle;
class PartKeeprAuthBundle extends Bundle
{
+ /**
+ * {@inheritDoc}
+ */
+ public function registerCommands(Application $application)
+ {
+ $application->add(new CreateUserCommand());
+ }
}