-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extending the actions class to add a getDoctrineMenu() method to acti…
…ons.
- Loading branch information
1 parent
e703179
commit 35d4b31
Showing
5 changed files
with
110 additions
and
8 deletions.
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
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,66 @@ | ||
<?php | ||
/** | ||
* Adds methods that can be called from the actions class | ||
* | ||
* @package ioDoctrineMenuPlugin | ||
* @subpackage actions | ||
* @author Ryan Weaver <ryan@thatsquality.com> | ||
*/ | ||
class ioDoctrineMenuActions | ||
{ | ||
/** | ||
* @var ioDoctrineMenuPluginConfiguration | ||
*/ | ||
protected $_pluginConfiguration; | ||
|
||
/** | ||
* Class constructor | ||
* | ||
* @param ioDoctrineMenuPluginConfiguration $configuration | ||
*/ | ||
public function __construct(ioDoctrineMenuPluginConfiguration $configuration) | ||
{ | ||
$this->_pluginConfiguration = $configuration; | ||
} | ||
|
||
/** | ||
* Returns an ioMenuItem tree loaded from the given name that corresponds | ||
* to a root node name in the ioDoctrineMenuItem model. | ||
* | ||
* This method cann be called directly from the actions class. | ||
* | ||
* @param string $name The name of the root menu item to return | ||
* @return ioMenuItem | ||
*/ | ||
public function getDoctrineMenu($name) | ||
{ | ||
return $this->_pluginConfiguration->getMenuManager() | ||
->getMenu($name); | ||
} | ||
|
||
/** | ||
* Listener method for method_not_found events | ||
* | ||
* This allows any public other methods in this class to be called as | ||
* if they were in the actions class. | ||
*/ | ||
public function extend(sfEvent $event) | ||
{ | ||
$this->_subject = $event->getSubject(); | ||
$method = $event['method']; | ||
$arguments = $event['arguments']; | ||
|
||
if (method_exists($this, $method)) | ||
{ | ||
$result = call_user_func_array(array($this, $method), $arguments); | ||
|
||
$event->setReturnValue($result); | ||
|
||
return true; | ||
} | ||
else | ||
{ | ||
return false; | ||
} | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
test/fixtures/project/apps/frontend/modules/test/actions/actions.class.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,15 @@ | ||
<?php | ||
// test actions class | ||
class testActions extends sfActions | ||
{ | ||
// tests calling ->getMenu() on the actions class | ||
public function executeGetMenu(sfWebRequest $request) | ||
{ | ||
$this->menu = $this->getDoctrineMenu('Root li'); | ||
$this->setTemplate('render'); | ||
$this->renderText($this->menu->render()); | ||
|
||
$this->setLayout(false); | ||
return sfView::NONE; | ||
} | ||
} |
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,23 @@ | ||
<?php | ||
|
||
require_once dirname(__FILE__).'/../bootstrap/functional.php'; | ||
require_once sfConfig::get('sf_lib_dir').'/test/unitHelper.php'; | ||
|
||
$browser = new sfTestFunctional(new sfBrowser()); | ||
|
||
create_doctrine_test_tree($browser->test()); | ||
$browser->info('1 - Goto a url that uses ioDoctrineMenuActions->getMenu()') | ||
->get('/actions/get-menu') | ||
|
||
->with('request')->begin() | ||
->isParameter('module', 'test') | ||
->isParameter('action', 'getMenu') | ||
->end() | ||
|
||
->with('response')->begin() | ||
->isStatusCode(200) | ||
->info(' 1.1 - Check for the root ul and its 7 descendants.') | ||
->checkElement('ul.root', true) | ||
->checkElement('ul.root li', 7) | ||
->end() | ||
; |