Commit 5c4ad4ce authored by Hermann Mayer's avatar Hermann Mayer

Initial Rewrite of Services Engine.

parent d4f6d577
......@@ -107,6 +107,8 @@ class DefaultController extends Controller
*/
public function showPageAction($slug = '', $service = '', $renderService = true, Response $serviceReponse = null)
{
// Get Entity Manager
$em = $this->getDoctrine()->getEntityManager();
......@@ -135,16 +137,72 @@ class DefaultController extends Controller
('homepage' != $page->getService()->getName())
) {
$serviceReponse = $this->forward('JityHomepageBundle:Service:show', array(
'page' => $page
));
$serviceReponse = $this->get('jity_service.handler')
->getController($page->getService()->getName())
->process()
;
}
// Return the rendered result
return $this->render('JityHomepageBundle:Default:index.html.twig', array(
'page' => $page,
'service' => (isset($serviceReponse)) ? $serviceReponse->getContent() : ''
'service' => (isset($serviceReponse)) ? $serviceReponse : ''
));
// // Get Entity Manager
// $em = $this->getDoctrine()->getEntityManager();
// // Try to get the requested Page
// if (!empty($slug)) {
// $page = $em->getRepository('JityHomepageBundle:Page')->findOneBySlug($slug);
// } elseif (!empty($service)) {
// $curService = $em->getRepository('JityHomepageBundle:Service')->findOneByName($service);
// $page = $curService->getPages()->first();
// // We dont want to render a infinite loop here
// $renderService = false;
// }
// // Page was not found
// if (!$page) {
// return $this->forward('JityHomepageBundle:Default:showInfo', array('template' => 'homepage_notfound'));
// }
// // On service relation jump into
// if (($service = $page->getService()) &&
// (true === $renderService) &&
// ('homepage' != $page->getService()->getName())
// ) {
// $serviceReponse = $this->forward('JityHomepageBundle:Service:show', array(
// 'page' => $page
// ));
// }
// // Return the rendered result
// return $this->render('JityHomepageBundle:Default:index.html.twig', array(
// 'page' => $page,
// 'service' => (isset($serviceReponse)) ? $serviceReponse->getContent() : ''
// ));
}
/**
......
<?php
namespace Jity\HomepageBundle\DependencyInjection\Compiler;
use Symfony\Component\DependencyInjection\ContainerBuilder,
Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface,
Symfony\Component\DependencyInjection\Reference;
/**
* ServiceCompilerPass
*
* @uses CompilerPassInterface
* @version $id$
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
class ServiceCompilerPass implements CompilerPassInterface
{
/**
* process
*
* @param ContainerBuilder $container
* @access public
* @return void
*/
public function process(ContainerBuilder $container)
{
if (!$container->hasDefinition('jity_service.handler')) {
return;
}
$definition = $container->getDefinition(
'jity_service.handler'
);
$taggedServices = $container->findTaggedServiceIds(
'jity_service.controller'
);
foreach ($taggedServices as $id => $attributes) {
$definition->addMethodCall(
'addController',
array(new Reference($id))
);
}
}
}
<?php
namespace Jity\HomepageBundle\DependencyInjection\Service;
use Symfony\Component\DependencyInjection\ContainerInterface,
JMS\DiExtraBundle\Annotation as DI;
/**
* AbstractService
*
* @abstract
* @version $id$
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
abstract class AbstractService
{
/**
* getName
*
* @abstract
* @access public
* @return void
*/
abstract public function getName();
/**
* getDescription
*
* @abstract
* @access public
* @return void
*/
abstract public function getDescription();
/**
* process
*
* @abstract
* @access public
* @return void
*/
abstract public function process();
/**
* @var container
* @access protected
*/
protected $container;
/**
* __construct
*
* @DI\InjectParams({
* "container" = @DI\Inject("service_container")
* })
*
* @access public
* @return void
*/
public function __construct(ContainerInterface $container)
{
$this->container = $container;
}
/**
* getSectionFromConfig
*
* @param mixed $section
* @access public
* @return void
*/
public function getSectionFromConfig($section = null)
{
if (null === $section) {
$section = strtolower($this->getName());
}
// Get bundle config from container
$config = (object) $this->container->getParameter('jity_homepage');
if (isset($config->$section)) {
return $config->$section;
}
return array();
}
}
<?php
namespace Jity\HomepageBundle\DependencyInjection\Service\Controller;
use Jity\HomepageBundle\DependencyInjection\Service\AbstractService,
Symfony\Bundle\FrameworkBundle\Controller\Controller,
JMS\DiExtraBundle\Annotation as DI;
use Symfony\Component\HttpFoundation\Response;
/**
* BlogController
*
* @DI\Service("jity_service.controller.blog", scope="request")
* @DI\Tag("jity_service.controller")
*
* @uses Controller
* @version $id$
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
class BlogController extends AbstractService
{
/**
* getName
*
* @access public
* @return void
*/
public function getName()
{
return 'blog';
}
/**
* getDescription
*
* @access public
* @return void
*/
public function getDescription()
{
return 'Fügt die Startseite eines Blogs hinzu.';
}
/**
* process
*
* @access public
* @return void
*/
public function process()
{
return $this->container->get('templating')->render('JityHomepageBundle:Service:Blog/news.html.twig', array());
}
}
<?php
namespace Jity\HomepageBundle\DependencyInjection\Service\Controller;
use Jity\HomepageBundle\DependencyInjection\Service\AbstractService,
Symfony\Bundle\FrameworkBundle\Controller\Controller,
JMS\DiExtraBundle\Annotation as DI;
use Jity\HomepageBundle\Entity\Contact,
Jity\HomepageBundle\Entity\Page,
Jity\HomepageBundle\Form\ContactType;
/**
* ContactController
*
* @DI\Service("jity_service.controller.contact", scope="request")
* @DI\Tag("jity_service.controller")
*
* @uses Controller
* @version $id$
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
class ContactController extends AbstractService
{
/**
* getName
*
* @access public
* @return void
*/
public function getName()
{
return 'contact';
}
/**
* getDescription
*
* @access public
* @return void
*/
public function getDescription()
{
return 'Fügt ein simples Kontakt-Formular hinzu.';
}
/**
* process
*
* @access public
* @return void
*/
public function process()
{
$entity = new Contact();
$form = $this->container->get('form.factory')
->create(new ContactType(), $entity)
->createView()
;
return $this->container->get('templating')->render('JityHomepageBundle:Service:Contact/new.html.twig', array(
'config' => $this->getSectionFromConfig(),
'form' => $form
));
}
/**
* sendContactMessageAction
*
* @access public
* @return void
*/
public function sendContactMessageAction()
{
// $entity = new Contact();
// $request = $this->getRequest();
// $form = $this->createForm(new ContactType(), $entity);
// $form->bind($request);
// if ($form->isValid()) {
// // Get bundle config from container
// $config = (object) $this->container->getParameter('jity_homepage');
// // Prepare and Send a Contact Email
// $message = \Swift_Message::newInstance()
// ->setSubject('[Jity] Neue Kontakt Mitteilung wurde verfasst')
// ->setFrom('info@jity.de')
// ->setTo($config->impress['contact']['email'])
// ->setBody($this->renderView('JityHomepageBundle:Service:contact_email.html.twig', array(
// 'contact' => $entity,
// 'config' => $config->impress
// )), 'text/html')
// ;
// $this->get('mailer')->send($message);
// // Write entitiy
// $em = $this->getDoctrine()->getEntityManager();
// $em->persist($entity);
// $em->flush();
// // Write flash message and redirect back
// $this->get('session')->getFlashBag()->add('success', 'Ihre Mitteilung wurde erfolgreich übermittelt.');
// return $this->redirect($this->generateUrl('page', array(
// 'slug' => 'kontakt'
// )));
// }
// // Render the form with the given errors
// $partial = $this->render('JityHomepageBundle:Service:contact.html.twig', array(
// 'form' => $form->createView()
// ));
// // Respond the filled form over the Default Controller
// return $this->forward('JityHomepageBundle:Default:showPage', array(
// 'slug' => 'kontakt',
// 'renderService' => false,
// 'serviceReponse' => new Response($partial->getContent())
// ));
}
}
<?php
namespace Jity\HomepageBundle\DependencyInjection\Service\Controller;
use Jity\HomepageBundle\DependencyInjection\Service\AbstractService,
Symfony\Bundle\FrameworkBundle\Controller\Controller,
JMS\DiExtraBundle\Annotation as DI;
use Symfony\Component\HttpFoundation\Response;
/**
* ImpressController
*
* @DI\Service("jity_service.controller.impress", scope="request")
* @DI\Tag("jity_service.controller")
*
* @uses Controller
* @version $id$
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
class ImpressController extends AbstractService
{
/**
* getName
*
* @access public
* @return void
*/
public function getName()
{
return 'impress';
}
/**
* getDescription
*
* @access public
* @return void
*/
public function getDescription()
{
return 'Fügt ein Impressum hinzu.';
}
/**
* process
*
* @access public
* @return void
*/
public function process()
{
return $this->container->get('templating')->render('JityHomepageBundle:Service:Impress/impress.html.twig', array(
'config' => $this->getSectionFromConfig()
));
}
}
<?php
namespace Jity\HomepageBundle\DependencyInjection\Service;
use Jity\HomepageBundle\DependencyInjection\Service\AbstractService,
Symfony\Bundle\FrameworkBundle\Controller\Controller,
JMS\DiExtraBundle\Annotation as DI;
/**
* Handler
*
* @DI\Service("jity_service.handler", scope="request")
*
* @version $id$
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
class Handler
{
private $controller;
/**
* addController
*
* @param AbstractService $controller
* @access public
* @return void
*/
public function addController(AbstractService $controller)
{
$this->controller[$controller->getName()] = $controller;
return $this;
}
/**
* getController
*
* @param string $name
* @access public
* @return void
*/
public function getController($name)
{
if (array_key_exists((string)$name, $this->controller)) {
return $this->controller[(string)$name];
}
return false;
}
/**
* getMetaMapping
*
* @access public
* @return void
*/
public function getMetaMapping()
{
$map = array();
foreach ($this->controller as $controller) {
$map[$controller->getName()]['description'] = $controller->getDescription();
}
return $map;
}
}
......@@ -2,8 +2,31 @@
namespace Jity\HomepageBundle;
use Symfony\Component\HttpKernel\Bundle\Bundle;
use Symfony\Component\HttpKernel\Bundle\Bundle,
Symfony\Component\DependencyInjection\ContainerBuilder,
Jity\HomepageBundle\DependencyInjection\Compiler\ServiceCompilerPass;
/**
* JityHomepageBundle
*
* @uses Bundle
* @version $id$
* @author Hermann Mayer <hermann.mayer92@gmail.com>
*/
class JityHomepageBundle extends Bundle
{
/**
* build
*
* @param ContainerBuilder $container
* @access public
* @return void
*/
public function build(ContainerBuilder $container)
{
parent::build($container);
$container->addCompilerPass(new ServiceCompilerPass());
}
}
......@@ -31,7 +31,11 @@
{% if comment.author %}
{% set author = comment.author.firstName ~ " " ~ comment.author.lastName %}
{% set authorEmail = ", " ~ comment.author.email %}
{% set authorAvatar = comment.author.picture %}
{% if comment.author.picture is not empty %}
{% set authorAvatar = '<img src="' ~ comment.author.picture ~ '" width="100" height="100" vspace="3" hspace="8" align="left"/>' %}
{% endif %}
{% endif %}
<item>
......@@ -39,8 +43,7 @@
<description>{{ comment.content }}</description>
<content:encoded>
<![CDATA[
<img src="{{ authorAvatar }}" width="100" height="100" vspace="3" hspace="8" align="left"/>
{{ comment.content }}
{{ authorAvatar }}{{ comment.content }}
]]>
</content:encoded>
<link>{{ url }}#comment-{{ comment.id }}</link>
......
{% render 'JityHomepageBundle:Blog:dashboard' %}
{% form_theme form 'JityHomepageBundle:Form:fields.html.twig' %}
{% block layout_content %}
<form novalidate action="{{ path('service_contact_send') }}" method="post" {{ form_enctype(form) }} class="form-horizontal hero-unit">
<legend>In Kontakt tretten</legend>
<div class="">
{{ form_widget(form) }}
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">
<i class="icon-envelope icon-white"></i>
Senden
</button>
<a href="{{ path('page') }}" class="btn btn-danger">
<i class="icon-share-alt icon-white"></i>
Zurück zur Homepage
</a>
</div>
</form>
{% render 'JityHomepageBundle:Editor:build' with {'syncElement': 'textarea[name="jity_homepagebundle_contacttype[message]"]'} %}
{% endblock %}
<!DOCTYPE unspecified PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head></head>
<body>
Guten Tag {{ config.site_admin.name }},<br>
<br>
es wurde von einem Benutzer ein Kontaktversuch unternommen.<br><br>
Daten des Benutzers:<br><br>
<b>Name:</b> {{ contact.name }}<br>
<b>Email Addresse:</b> {{ contact.email }}<br>
<b>Nachricht:</b> <br><br>
{{ contact.message }}
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment