Skip to content

Commit

Permalink
Convert sampledata plugins to service provider
Browse files Browse the repository at this point in the history
  • Loading branch information
laoneo committed Mar 22, 2023
1 parent 5a2d7d4 commit 2b4d0a4
Show file tree
Hide file tree
Showing 9 changed files with 783 additions and 665 deletions.
4 changes: 3 additions & 1 deletion plugins/sampledata/blog/blog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<authorUrl>www.joomla.org</authorUrl>
<version>3.8.0</version>
<description>PLG_SAMPLEDATA_BLOG_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\SampleData\Blog</namespace>
<files>
<filename plugin="blog">blog.php</filename>
<folder plugin="blog">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_sampledata_blog.ini</language>
Expand Down
49 changes: 49 additions & 0 deletions plugins/sampledata/blog/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage Sampledata.blog
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\SampleData\Blog\Extension\Blog;

return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new Blog(
$dispatcher,
(array) PluginHelper::getPlugin('sampledata', 'blog')
);
$plugin->setApplication(Factory::getApplication());
$plugin->setDatabase($container->get(DatabaseInterface::class));

return $plugin;
}
);
}
};

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion plugins/sampledata/multilang/multilang.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
<authorUrl>www.joomla.org</authorUrl>
<version>4.0.0</version>
<description>PLG_SAMPLEDATA_MULTILANG_XML_DESCRIPTION</description>
<namespace path="src">Joomla\Plugin\SampleData\MultiLanguage</namespace>
<files>
<filename plugin="multilang">multilang.php</filename>
<folder plugin="multilang">services</folder>
<folder>src</folder>
</files>
<languages>
<language tag="en-GB">language/en-GB/plg_sampledata_multilang.ini</language>
Expand Down
49 changes: 49 additions & 0 deletions plugins/sampledata/multilang/services/provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

/**
* @package Joomla.Plugin
* @subpackage Sampledata.multilang
*
* @copyright (C) 2023 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

defined('_JEXEC') or die;

use Joomla\CMS\Extension\PluginInterface;
use Joomla\CMS\Factory;
use Joomla\CMS\Plugin\PluginHelper;
use Joomla\Database\DatabaseInterface;
use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use Joomla\Event\DispatcherInterface;
use Joomla\Plugin\SampleData\MultiLanguage\Extension\MultiLanguage;

return new class () implements ServiceProviderInterface {
/**
* Registers the service provider with a DI container.
*
* @param Container $container The DI container.
*
* @return void
*
* @since __DEPLOY_VERSION__
*/
public function register(Container $container): void
{
$container->set(
PluginInterface::class,
function (Container $container) {
$dispatcher = $container->get(DispatcherInterface::class);
$plugin = new MultiLanguage(
$dispatcher,
(array) PluginHelper::getPlugin('sampledata', 'multilang')
);
$plugin->setApplication(Factory::getApplication());
$plugin->setDatabase($container->get(DatabaseInterface::class));

return $plugin;
}
);
}
};
Loading

0 comments on commit 2b4d0a4

Please sign in to comment.