Skip to content

Commit

Permalink
Lots of Zikula-Ajax fixes.
Browse files Browse the repository at this point in the history
In the process of consolidating. Eventually we should just have one front controller.
  • Loading branch information
Drak committed Apr 20, 2012
1 parent 10369a1 commit 623a696
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 379 deletions.
4 changes: 0 additions & 4 deletions src/Zikula/Bundle/CoreBundle/CoreBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Zikula\Bundle\CoreBundle;

use Zikula\Bundle\CoreBundle\DependencyInjection\Compiler\RegisterCoreListenersPass;
use Zikula\Bundle\CoreBundle\DependencyInjection\Compiler\ControllerResolverCompilerPass;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Compiler\PassConfig;
use Symfony\Component\DependencyInjection\Scope;
Expand All @@ -18,8 +17,5 @@ public function build(ContainerBuilder $container)

// $container->addScope(new Scope('request'));
$container->addCompilerPass(new RegisterCoreListenersPass(), PassConfig::TYPE_AFTER_REMOVING);
if (isset($_GET['type']) && $_GET['type'] == 'ajax') {
$container->addCompilerPass(new ControllerResolverCompilerPass(), PassConfig::TYPE_AFTER_REMOVING);
}
}
}

This file was deleted.

8 changes: 0 additions & 8 deletions src/Zikula/Bundle/CoreBundle/Resources/config/web.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

<parameters>
<parameter key="controller_resolver.class">Zikula\Framework\ControllerResolver</parameter>
<parameter key="controller_resolver_ajax.class">Zikula\Framework\AjaxControllerResolver</parameter>
<!-- <parameter key="controller_name_converter.class">Symfony\Bundle\FrameworkBundle\Controller\ControllerNameParser</parameter>-->
<!-- <parameter key="response_listener.class">Symfony\Component\HttpKernel\EventListener\ResponseListener</parameter>-->
<!-- <parameter key="streamed_response_listener.class">Symfony\Component\HttpKernel\EventListener\StreamedResponseListener</parameter>-->
Expand All @@ -26,13 +25,6 @@
<argument type="service" id="logger" on-invalid="ignore" />-->
</service>

<service id="controller_resolver_ajax" class="%controller_resolver_ajax.class%">
<tag name="monolog.logger" channel="request" />
<!--<argument type="service" id="service_container" /> -->
<!-- <argument type="service" id="controller_name_converter" />
<argument type="service" id="logger" on-invalid="ignore" />-->
</service>

<!-- <service id="response_listener" class="%response_listener.class%">
<tag name="kernel.event_subscriber" />
<argument>%kernel.charset%</argument>
Expand Down
49 changes: 0 additions & 49 deletions src/Zikula/Framework/AjaxControllerResolver.php

This file was deleted.

74 changes: 0 additions & 74 deletions src/Zikula/Framework/AjaxModuleDispatcher.php

This file was deleted.

4 changes: 2 additions & 2 deletions src/Zikula/Framework/Controller/AbstractAjax.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ protected function configureView()
*/
public function checkAjaxToken($token=null)
{
$headerToken = $this->request->headers->get('HTTP_X_ZIKULA_AJAX_TOKEN', null);
$headerToken = $this->request->headers->get('X_ZIKULA_AJAX_TOKEN', null);

if ($headerToken == session_id()) {
if ($headerToken == $this->request->getSession()->getId()) {
return;
}

Expand Down
4 changes: 3 additions & 1 deletion src/Zikula/Framework/ControllerResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public function __construct(LoggerInterface $logger = null)

public function getController(Request $request)
{
return array(new ModuleDispatcher, 'dispatch');
$method = isset($_GET['type']) && $_GET['type'] == 'ajax' ? 'ajaxDispatch' : 'dispatch';

return array(new ModuleDispatcher, $method);
}

public function getArguments(Request $request, $controller)
Expand Down
50 changes: 50 additions & 0 deletions src/Zikula/Framework/ModuleDispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Zikula\Framework\Response\PlainResponse;
use Zikula\Framework\Response\Ajax\NotFoundResponse;
use Zikula\Framework\Response\Ajax\UnavailableResponse;
use Zikula\Framework\Response\Ajax\ForbiddenResponse;
use Zikula\Framework\Response\Ajax\FatalResponse;
use Zikula\Framework\Exception\NotFoundException;
use Zikula\Framework\Exception\FatalException;
use Zikula\Framework\Exception\ForbiddenException;

class ModuleDispatcher
{
Expand Down Expand Up @@ -122,4 +129,47 @@ public function dispatch(Request $request)
break;
}
}

public function ajaxDispatch(Request $request)
{
$module = $request->attributes->get('_module');
$type = $request->attributes->get('_controller');
$func = $request->attributes->get('_action');

if (empty($func)) {
$response = new NotFoundResponse(__f("Missing parameter '%s'", 'func'));
}

// get module information
$modinfo = \ModUtil::getInfoFromName($module);
if ($modinfo == false) {
$response = new NotFoundResponse(__f("Error! The '%s' module is unknown.", \DataUtil::formatForDisplay($module)));
}

if (!\ModUtil::available($modinfo['name'])) {
$response = new NotFoundResponse(__f("Error! The '%s' module is not available.", \DataUtil::formatForDisplay($module)));
}

if (!\ModUtil::load($modinfo['name'], $type)) {
$response = new NotFoundResponse(__f("Error! The '%s' module is not available.", \DataUtil::formatForDisplay($module)));
}

// Dispatch controller.
try {
$response = \ModUtil::func($modinfo['name'], $type, $func);
} catch (NotFoundException $e) {
$response = new NotFoundResponse($e->getMessage());
} catch (ForbiddenException $e) {
$response = new ForbiddenResponse($e->getMessage());
} catch (FatalException $e) {
$response = new FatalResponse($e->getMessage());
} catch (\PDOException $e) {
$response = new FatalResponse($e->getMessage());
} catch (\Exception $e) {
$response = new FatalResponse($e->getMessage());
}

// Issue response.
return $response;
}
}
Loading

0 comments on commit 623a696

Please sign in to comment.