forked from sensiolabs/SensioDistributionBundle
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Import Acme demo bundle from symfony standard edition
- Loading branch information
1 parent
7e5be79
commit 9e806a9
Showing
31 changed files
with
775 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
Resources/skeleton/acme-demo-bundle/Acme/DemoBundle/AcmeDemoBundle.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Acme\DemoBundle; | ||
|
||
use Symfony\Component\HttpKernel\Bundle\Bundle; | ||
|
||
class AcmeDemoBundle extends Bundle | ||
{ | ||
} |
48 changes: 48 additions & 0 deletions
48
Resources/skeleton/acme-demo-bundle/Acme/DemoBundle/Command/HelloWorldCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Acme\DemoBundle\Command; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Hello World command for demo purposes. | ||
* | ||
* You could also extend from Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand | ||
* to get access to the container via $this->getContainer(). | ||
* | ||
* @author Tobias Schultze <http://tobion.de> | ||
*/ | ||
class HelloWorldCommand extends Command | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('acme:hello') | ||
->setDescription('Hello World example command') | ||
->addArgument('who', InputArgument::OPTIONAL, 'Who to greet.', 'World') | ||
->setHelp(<<<EOF | ||
The <info>%command.name%</info> command greets somebody or everybody: | ||
<info>php %command.full_name%</info> | ||
The optional argument specifies who to greet: | ||
<info>php %command.full_name%</info> Fabien | ||
EOF | ||
); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$output->writeln(sprintf('Hello <comment>%s</comment>!', $input->getArgument('who'))); | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
Resources/skeleton/acme-demo-bundle/Acme/DemoBundle/Controller/DemoController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
namespace Acme\DemoBundle\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Symfony\Component\HttpFoundation\RedirectResponse; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Acme\DemoBundle\Form\ContactType; | ||
|
||
// these import the "@Route" and "@Template" annotations | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | ||
|
||
class DemoController extends Controller | ||
{ | ||
/** | ||
* @Route("/", name="_demo") | ||
* @Template() | ||
*/ | ||
public function indexAction() | ||
{ | ||
return array(); | ||
} | ||
|
||
/** | ||
* @Route("/hello/{name}", name="_demo_hello") | ||
* @Template() | ||
*/ | ||
public function helloAction($name) | ||
{ | ||
return array('name' => $name); | ||
} | ||
|
||
/** | ||
* @Route("/contact", name="_demo_contact") | ||
* @Template() | ||
*/ | ||
public function contactAction(Request $request) | ||
{ | ||
$form = $this->createForm(new ContactType()); | ||
$form->handleRequest($request); | ||
|
||
if ($form->isValid()) { | ||
$mailer = $this->get('mailer'); | ||
|
||
// .. setup a message and send it | ||
// http://symfony.com/doc/current/cookbook/email.html | ||
|
||
$request->getSession()->getFlashBag()->set('notice', 'Message sent!'); | ||
|
||
return new RedirectResponse($this->generateUrl('_demo')); | ||
} | ||
|
||
return array('form' => $form->createView()); | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
Resources/skeleton/acme-demo-bundle/Acme/DemoBundle/Controller/SecuredController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace Acme\DemoBundle\Controller; | ||
|
||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\Security\Core\SecurityContext; | ||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | ||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security; | ||
|
||
/** | ||
* @Route("/demo/secured") | ||
*/ | ||
class SecuredController extends Controller | ||
{ | ||
/** | ||
* @Route("/login", name="_demo_login") | ||
* @Template() | ||
*/ | ||
public function loginAction(Request $request) | ||
{ | ||
if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) { | ||
$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR); | ||
} else { | ||
$error = $request->getSession()->get(SecurityContext::AUTHENTICATION_ERROR); | ||
} | ||
|
||
return array( | ||
'last_username' => $request->getSession()->get(SecurityContext::LAST_USERNAME), | ||
'error' => $error, | ||
); | ||
} | ||
|
||
/** | ||
* @Route("/login_check", name="_security_check") | ||
*/ | ||
public function securityCheckAction() | ||
{ | ||
// The security layer will intercept this request | ||
} | ||
|
||
/** | ||
* @Route("/logout", name="_demo_logout") | ||
*/ | ||
public function logoutAction() | ||
{ | ||
// The security layer will intercept this request | ||
} | ||
|
||
/** | ||
* @Route("/hello", defaults={"name"="World"}), | ||
* @Route("/hello/{name}", name="_demo_secured_hello") | ||
* @Template() | ||
*/ | ||
public function helloAction($name) | ||
{ | ||
return array('name' => $name); | ||
} | ||
|
||
/** | ||
* @Route("/hello/admin/{name}", name="_demo_secured_hello_admin") | ||
* @Security("is_granted('ROLE_ADMIN')") | ||
* @Template() | ||
*/ | ||
public function helloadminAction($name) | ||
{ | ||
return array('name' => $name); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
Resources/skeleton/acme-demo-bundle/Acme/DemoBundle/Controller/WelcomeController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Acme\DemoBundle\Controller; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
|
||
class WelcomeController extends Controller | ||
{ | ||
public function indexAction() | ||
{ | ||
/* | ||
* The action's view can be rendered using render() method | ||
* or @Template annotation as demonstrated in DemoController. | ||
* | ||
*/ | ||
|
||
return $this->render('AcmeDemoBundle:Welcome:index.html.twig'); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...urces/skeleton/acme-demo-bundle/Acme/DemoBundle/DependencyInjection/AcmeDemoExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Acme\DemoBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader; | ||
use Symfony\Component\HttpKernel\DependencyInjection\Extension; | ||
use Symfony\Component\Config\FileLocator; | ||
|
||
class AcmeDemoExtension extends Extension | ||
{ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | ||
$loader->load('services.xml'); | ||
} | ||
|
||
public function getAlias() | ||
{ | ||
return 'acme_demo'; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
Resources/skeleton/acme-demo-bundle/Acme/DemoBundle/EventListener/ControllerListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
namespace Acme\DemoBundle\EventListener; | ||
|
||
use Symfony\Component\HttpKernel\HttpKernelInterface; | ||
use Symfony\Component\HttpKernel\Event\FilterControllerEvent; | ||
use Acme\DemoBundle\Twig\Extension\DemoExtension; | ||
|
||
class ControllerListener | ||
{ | ||
protected $extension; | ||
|
||
public function __construct(DemoExtension $extension) | ||
{ | ||
$this->extension = $extension; | ||
} | ||
|
||
public function onKernelController(FilterControllerEvent $event) | ||
{ | ||
if (HttpKernelInterface::MASTER_REQUEST === $event->getRequestType()) { | ||
$this->extension->setController($event->getController()); | ||
} | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
Resources/skeleton/acme-demo-bundle/Acme/DemoBundle/Form/ContactType.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Acme\DemoBundle\Form; | ||
|
||
use Symfony\Component\Form\AbstractType; | ||
use Symfony\Component\Form\FormBuilderInterface; | ||
|
||
class ContactType extends AbstractType | ||
{ | ||
public function buildForm(FormBuilderInterface $builder, array $options) | ||
{ | ||
$builder->add('email', 'email'); | ||
$builder->add('message', 'textarea'); | ||
} | ||
|
||
public function getName() | ||
{ | ||
return 'contact'; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
Resources/skeleton/acme-demo-bundle/Acme/DemoBundle/Resources/config/routing.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
_welcome: | ||
pattern: / | ||
defaults: { _controller: AcmeDemoBundle:Welcome:index } | ||
|
||
_demo_secured: | ||
resource: "@AcmeDemoBundle/Controller/SecuredController.php" | ||
type: annotation | ||
|
||
_demo: | ||
resource: "@AcmeDemoBundle/Controller/DemoController.php" | ||
type: annotation | ||
prefix: /demo |
18 changes: 18 additions & 0 deletions
18
Resources/skeleton/acme-demo-bundle/Acme/DemoBundle/Resources/config/services.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" ?> | ||
|
||
<container xmlns="http://symfony.com/schema/dic/services" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
||
<services> | ||
<service id="twig.extension.acme.demo" class="Acme\DemoBundle\Twig\Extension\DemoExtension" public="false"> | ||
<tag name="twig.extension" /> | ||
<argument type="service" id="twig.loader" /> | ||
</service> | ||
|
||
<service id="acme.demo.listener" class="Acme\DemoBundle\EventListener\ControllerListener"> | ||
<tag name="kernel.event_listener" event="kernel.controller" method="onKernelController" /> | ||
<argument type="service" id="twig.extension.acme.demo" /> | ||
</service> | ||
</services> | ||
</container> |
Oops, something went wrong.