Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

Method for adding extra identifiers to Abstract Controller Event Manager #6553

Closed
wants to merge 5 commits into from

Conversation

ibekiaris
Copy link

I extended the functionallity of Zend\Mvc\Controller\AbstractController because i face the following problem:

There was a need of a Zf2 module with the following structure:

Module Name: Modules

Modules

  • src

-- FolderA
-- FolderB

  • view

-- foldera
-- folderb

I wanted to disable the layout only for that module. So i need an identifier for that module only.

However namespace configuration was the following

   return array(
        'Zend\Loader\StandardAutoloader' => array(
                'namespaces' => array(
                   'FolderA' => __DIR__ . '/src/FolderA',
                   'FolderB' => __DIR__ . '/src/FolderB',
                ),
        ),
    );

Tha means that identifiers in AbstractController event manager are:

'Zend\Stdlib\DispatchableInterface'
'Zend\Mvc\Controller\AbstractController'
'FolderA\Controller\IndexController'
'AbstractModulesController'
'FolderA' (or FolderB)

So i ve added some lines of code in case someone need to extend AstractActionController and implement his own

"AbstractActionController" class setting also his own identifiers to the event manager.

@weierophinney
Copy link
Member

I'd actually prefer that we use the existing $eventIdentifier property for this. To do this, remove it from the setIdentifier() call, and then do the following:

  • if not an array, cast to an array
  • pass the value to addIdentifiers()

If you make that change, I'll merge.

@@ -159,13 +165,19 @@ public function getResponse()
*/
public function setEventManager(EventManagerInterface $events)
{
$events->setIdentifiers(array(
$eventManagerIdentifiers = array(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indented with 4+5 spaces instead of 4+4.

@ibekiaris
Copy link
Author

Hope its OK now

get_class($this),
$this->eventIdentifier,
substr(get_class($this), 0, strpos(get_class($this), '\\'))
));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep the above, but remove the $this->eventIdentifier entry.

@ibekiaris
Copy link
Author

I did changes there. Thank you very much for the guideness.

Just a question: why not simply casting (array cast) rather than checking if $this->eventIdentifier is array? Is there a performance matter?

Thanks in advance.

@weierophinney
Copy link
Member

why not simply casting (array cast) rather than checking if $this->eventIdentifier is array? Is there a performance matter?

More of a "it doesn't always work the way you expect" situation, particularly with empty values.

@ibekiaris
Copy link
Author

Thanks for the reply

Ocramius added a commit that referenced this pull request Nov 22, 2014
Ocramius added a commit that referenced this pull request Nov 22, 2014
Ocramius added a commit that referenced this pull request Nov 22, 2014
Ocramius added a commit that referenced this pull request Nov 22, 2014
@Ocramius
Copy link
Member

@ibekiaris I added tests and manually merged into develop at a16bff4, thanks!

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants