Skip to content

[6.0] Remove the dispatch event functions in model and view #45431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 0 additions & 51 deletions libraries/src/MVC/Model/BaseDatabaseModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
use Joomla\Database\Exception\DatabaseNotFoundException;
use Joomla\Event\DispatcherAwareInterface;
use Joomla\Event\DispatcherAwareTrait;
use Joomla\Event\DispatcherInterface;
use Joomla\Event\EventInterface;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -333,55 +331,6 @@ protected function bootComponent($component): ComponentInterface
return Factory::getApplication()->bootComponent($component);
}

/**
* Get the event dispatcher.
*
* The override was made to keep a backward compatibility for legacy component.
* TODO: Remove the override in 6.0
*
* @return DispatcherInterface
*
* @since 4.4.0
* @throws \UnexpectedValueException May be thrown if the dispatcher has not been set.
*/
public function getDispatcher()
{
if (!$this->dispatcher) {
@trigger_error(
\sprintf('Dispatcher for %s should be set through MVC factory. It will throw an exception in 6.0', __CLASS__),
E_USER_DEPRECATED
);

return Factory::getContainer()->get(DispatcherInterface::class);
}

return $this->dispatcher;
}

/**
* Dispatches the given event on the internal dispatcher, does a fallback to the global one.
*
* @param EventInterface $event The event
*
* @return void
*
* @since 4.1.0
*
* @deprecated 4.4 will be removed in 6.0. Use $this->getDispatcher() directly.
*/
protected function dispatchEvent(EventInterface $event)
{
$this->getDispatcher()->dispatch($event->getName(), $event);

@trigger_error(
\sprintf(
'Method %s is deprecated and will be removed in 6.0. Use getDispatcher()->dispatch() directly.',
__METHOD__
),
E_USER_DEPRECATED
);
}

/**
* Get the database driver.
*
Expand Down
52 changes: 0 additions & 52 deletions libraries/src/MVC/View/AbstractView.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,13 @@

use Joomla\CMS\Document\Document;
use Joomla\CMS\Document\DocumentAwareInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\LanguageAwareInterface;
use Joomla\CMS\Language\LanguageAwareTrait;
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
use Joomla\CMS\Object\LegacyErrorHandlingTrait;
use Joomla\CMS\Object\LegacyPropertyManagementTrait;
use Joomla\Event\DispatcherAwareInterface;
use Joomla\Event\DispatcherAwareTrait;
use Joomla\Event\DispatcherInterface;
use Joomla\Event\EventInterface;

// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
Expand Down Expand Up @@ -292,53 +289,4 @@ public function setDocument(Document $document): void
{
$this->document = $document;
}

/**
* Get the event dispatcher.
*
* The override was made to keep a backward compatibility for legacy component.
* TODO: Remove the override in 6.0
*
* @return DispatcherInterface
*
* @since 4.4.0
* @throws \UnexpectedValueException May be thrown if the dispatcher has not been set.
*/
public function getDispatcher()
{
if (!$this->dispatcher) {
@trigger_error(
\sprintf('Dispatcher for %s should be set through MVC factory. It will throw an exception in 6.0', __CLASS__),
E_USER_DEPRECATED
);

return Factory::getContainer()->get(DispatcherInterface::class);
}

return $this->dispatcher;
}

/**
* Dispatches the given event on the internal dispatcher, does a fallback to the global one.
*
* @param EventInterface $event The event
*
* @return void
*
* @since 4.1.0
*
* @deprecated 4.4 will be removed in 6.0. Use $this->getDispatcher() directly.
*/
protected function dispatchEvent(EventInterface $event)
{
$this->getDispatcher()->dispatch($event->getName(), $event);

@trigger_error(
\sprintf(
'Method %s is deprecated and will be removed in 6.0. Use getDispatcher()->dispatch() directly.',
__METHOD__
),
E_USER_DEPRECATED
);
}
}
30 changes: 0 additions & 30 deletions tests/Unit/Libraries/Cms/MVC/View/AbstractViewTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,6 @@

use Joomla\CMS\MVC\Model\BaseModel;
use Joomla\CMS\MVC\View\AbstractView;
use Joomla\Event\DispatcherInterface;
use Joomla\Event\Event;
use Joomla\Event\EventInterface;
use Joomla\Tests\Unit\UnitTestCase;

/**
Expand Down Expand Up @@ -220,31 +217,4 @@ public function display($tpl = null)

$this->assertEquals('test', $view->get('unit'));
}

/**
* @testdox can dispatch an event
*
* @return void
*
* @since 4.2.0
*/
public function testDispatchEvent()
{
$event = new Event('test');
$dispatcher = $this->createMock(DispatcherInterface::class);
$dispatcher->expects($this->once())->method('dispatch')->with($this->equalTo('test'), $this->equalTo($event));

$view = new class () extends AbstractView {
public function dispatchEvent(EventInterface $event)
{
parent::dispatchEvent($event);
}

public function display($tpl = null)
{
}
};
$view->setDispatcher($dispatcher);
$view->dispatchEvent($event);
}
}