mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 06:08:52 +00:00
[ticket/11481] Use container for all classes and inject dependencies
PHPBB3-11481
This commit is contained in:
parent
b5f1484744
commit
3efe0eb246
9 changed files with 139 additions and 34 deletions
56
phpBB/config/feed.yml
Normal file
56
phpBB/config/feed.yml
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
services:
|
||||||
|
feed.helper:
|
||||||
|
class: phpbb_feed_helper
|
||||||
|
arguments:
|
||||||
|
- @config
|
||||||
|
- @user
|
||||||
|
- %core.root_path%
|
||||||
|
|
||||||
|
feed.factory:
|
||||||
|
class: phpbb_feed_factory
|
||||||
|
arguments:
|
||||||
|
- @service_container
|
||||||
|
- @config
|
||||||
|
- @dbal.conn
|
||||||
|
|
||||||
|
feed.forum:
|
||||||
|
class: phpbb_feed_forum
|
||||||
|
scope: prototype
|
||||||
|
arguments:
|
||||||
|
- @feed.helper
|
||||||
|
|
||||||
|
feed.forums:
|
||||||
|
class: phpbb_feed_forums
|
||||||
|
scope: prototype
|
||||||
|
arguments:
|
||||||
|
- @feed.helper
|
||||||
|
|
||||||
|
feed.news:
|
||||||
|
class: phpbb_feed_news
|
||||||
|
scope: prototype
|
||||||
|
arguments:
|
||||||
|
- @feed.helper
|
||||||
|
|
||||||
|
feed.overall:
|
||||||
|
class: phpbb_feed_overall
|
||||||
|
scope: prototype
|
||||||
|
arguments:
|
||||||
|
- @feed.helper
|
||||||
|
|
||||||
|
feed.topic:
|
||||||
|
class: phpbb_feed_topic
|
||||||
|
scope: prototype
|
||||||
|
arguments:
|
||||||
|
- @feed.helper
|
||||||
|
|
||||||
|
feed.topics:
|
||||||
|
class: phpbb_feed_topics
|
||||||
|
scope: prototype
|
||||||
|
arguments:
|
||||||
|
- @feed.helper
|
||||||
|
|
||||||
|
feed.topics_active:
|
||||||
|
class: phpbb_feed_topics_active
|
||||||
|
scope: prototype
|
||||||
|
arguments:
|
||||||
|
- @feed.helper
|
|
@ -63,7 +63,8 @@ $phpbb_feed_helper = $phpbb_container->get('feed.helper');
|
||||||
$board_url = $phpbb_feed_helper->get_board_url();
|
$board_url = $phpbb_feed_helper->get_board_url();
|
||||||
|
|
||||||
// Get correct feed object
|
// Get correct feed object
|
||||||
$feed = phpbb_feed_factory::init($mode, $forum_id, $topic_id);
|
$phpbb_feed_factory = $phpbb_container->get('feed.factory');
|
||||||
|
$feed = $phpbb_feed_factory->get_feed($mode, $forum_id, $topic_id);
|
||||||
|
|
||||||
// No feed found
|
// No feed found
|
||||||
if ($feed === false)
|
if ($feed === false)
|
||||||
|
|
|
@ -22,6 +22,12 @@ if (!defined('IN_PHPBB'))
|
||||||
*/
|
*/
|
||||||
abstract class phpbb_feed_base
|
abstract class phpbb_feed_base
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Feed helper object
|
||||||
|
* @var phpbb_feed_helper
|
||||||
|
*/
|
||||||
|
protected $helper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SQL Query to be executed to get feed items
|
* SQL Query to be executed to get feed items
|
||||||
*/
|
*/
|
||||||
|
@ -49,8 +55,11 @@ abstract class phpbb_feed_base
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param phpbb_feed_helper $helper Feed helper
|
||||||
|
* @return null
|
||||||
*/
|
*/
|
||||||
function __construct()
|
function __construct(phpbb_feed_helper $helper)
|
||||||
{
|
{
|
||||||
global $config;
|
global $config;
|
||||||
|
|
||||||
|
@ -67,6 +76,8 @@ abstract class phpbb_feed_base
|
||||||
$this->num_items = 10;
|
$this->num_items = 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->helper = $helper;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -225,6 +236,6 @@ abstract class phpbb_feed_base
|
||||||
return $user->lang['GUEST'];
|
return $user->lang['GUEST'];
|
||||||
}
|
}
|
||||||
|
|
||||||
return '<a href="' . feed_append_sid('/memberlist.' . $phpEx, 'mode=viewprofile&u=' . $author_id) . '">' . $row[$this->get('creator')] . '</a>';
|
return '<a href="' . $this->helper->append_sid('/memberlist.' . $phpEx, 'mode=viewprofile&u=' . $author_id) . '">' . $row[$this->get('creator')] . '</a>';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,33 @@ if (!defined('IN_PHPBB'))
|
||||||
*/
|
*/
|
||||||
class phpbb_feed_factory
|
class phpbb_feed_factory
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* Service container object
|
||||||
|
* @var object
|
||||||
|
*/
|
||||||
|
protected $container;
|
||||||
|
|
||||||
|
/** @var phpbb_config */
|
||||||
|
protected $config;
|
||||||
|
|
||||||
|
/** @var phpbb_db_driver */
|
||||||
|
protected $driver;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
*
|
||||||
|
* @param objec $container Container object
|
||||||
|
* @param phpbb_config $config Config object
|
||||||
|
* @param phpbb_db_driver $db Database connection
|
||||||
|
* @return null
|
||||||
|
*/
|
||||||
|
public function __construct($container, phpbb_config $config, phpbb_db_driver $db)
|
||||||
|
{
|
||||||
|
$this->container = $container;
|
||||||
|
$this->config = $config;
|
||||||
|
$this->db = $db;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return correct object for specified mode
|
* Return correct object for specified mode
|
||||||
*
|
*
|
||||||
|
@ -30,71 +57,69 @@ class phpbb_feed_factory
|
||||||
*
|
*
|
||||||
* @return object Returns correct feeds object for specified mode.
|
* @return object Returns correct feeds object for specified mode.
|
||||||
*/
|
*/
|
||||||
function init($mode, $forum_id, $topic_id)
|
function get_feed($mode, $forum_id, $topic_id)
|
||||||
{
|
{
|
||||||
global $config;
|
|
||||||
|
|
||||||
switch ($mode)
|
switch ($mode)
|
||||||
{
|
{
|
||||||
case 'forums':
|
case 'forums':
|
||||||
if (!$config['feed_overall_forums'])
|
if (!$this->config['feed_overall_forums'])
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new phpbb_feed_forums();
|
return $this->container->get('feed.forums');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'topics':
|
case 'topics':
|
||||||
case 'topics_new':
|
case 'topics_new':
|
||||||
if (!$config['feed_topics_new'])
|
if (!$this->config['feed_topics_new'])
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new phpbb_feed_topics();
|
return $this->container->get('feed.topics');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'topics_active':
|
case 'topics_active':
|
||||||
if (!$config['feed_topics_active'])
|
if (!$this->config['feed_topics_active'])
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new phpbb_feed_topics_active();
|
return $this->container->get('feed.topics_active');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'news':
|
case 'news':
|
||||||
global $db;
|
|
||||||
|
|
||||||
// Get at least one news forum
|
// Get at least one news forum
|
||||||
$sql = 'SELECT forum_id
|
$sql = 'SELECT forum_id
|
||||||
FROM ' . FORUMS_TABLE . '
|
FROM ' . FORUMS_TABLE . '
|
||||||
WHERE ' . $db->sql_bit_and('forum_options', FORUM_OPTION_FEED_NEWS, '<> 0');
|
WHERE ' . $this->db->sql_bit_and('forum_options', FORUM_OPTION_FEED_NEWS, '<> 0');
|
||||||
$result = $db->sql_query_limit($sql, 1, 0, 600);
|
$result = $this->db->sql_query_limit($sql, 1, 0, 600);
|
||||||
$s_feed_news = (int) $db->sql_fetchfield('forum_id');
|
$s_feed_news = (int) $this->db->sql_fetchfield('forum_id');
|
||||||
$db->sql_freeresult($result);
|
$this->db->sql_freeresult($result);
|
||||||
|
|
||||||
if (!$s_feed_news)
|
if (!$s_feed_news)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new phpbb_feed_news();
|
return $this->container->get('feed.news');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if ($topic_id && $config['feed_topic'])
|
if ($topic_id && $this->config['feed_topic'])
|
||||||
{
|
{
|
||||||
return new phpbb_feed_topic($topic_id);
|
return $this->container->get('feed.topic')
|
||||||
|
->set_topic_id($topic_id);
|
||||||
}
|
}
|
||||||
else if ($forum_id && $config['feed_forum'])
|
else if ($forum_id && $this->config['feed_forum'])
|
||||||
{
|
{
|
||||||
return new phpbb_feed_forum($forum_id);
|
return $this->container->get('feed.forum')
|
||||||
|
->set_forum_id($forum_id);
|
||||||
}
|
}
|
||||||
else if ($config['feed_overall'])
|
else if ($this->config['feed_overall'])
|
||||||
{
|
{
|
||||||
return new phpbb_feed_overall();
|
return $this->container->get('feed.overall');
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -28,11 +28,17 @@ class phpbb_feed_forum extends phpbb_feed_post_base
|
||||||
var $forum_id = 0;
|
var $forum_id = 0;
|
||||||
var $forum_data = array();
|
var $forum_data = array();
|
||||||
|
|
||||||
function __construct($forum_id)
|
/**
|
||||||
|
* Set the Forum ID
|
||||||
|
*
|
||||||
|
* @param int $forum_id Forum ID
|
||||||
|
* @return phpbb_feed_forum
|
||||||
|
*/
|
||||||
|
public function set_forum_id($topic_id)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
|
||||||
|
|
||||||
$this->forum_id = (int) $forum_id;
|
$this->forum_id = (int) $forum_id;
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
function open()
|
function open()
|
||||||
|
|
|
@ -65,7 +65,7 @@ class phpbb_feed_forums extends phpbb_feed_base
|
||||||
{
|
{
|
||||||
global $phpEx, $config;
|
global $phpEx, $config;
|
||||||
|
|
||||||
$item_row['link'] = feed_append_sid('/viewforum.' . $phpEx, 'f=' . $row['forum_id']);
|
$item_row['link'] = $this->helper->append_sid('/viewforum.' . $phpEx, 'f=' . $row['forum_id']);
|
||||||
|
|
||||||
if ($config['feed_item_statistics'])
|
if ($config['feed_item_statistics'])
|
||||||
{
|
{
|
||||||
|
|
|
@ -47,7 +47,7 @@ abstract class phpbb_feed_post_base extends phpbb_feed_base
|
||||||
{
|
{
|
||||||
global $phpEx, $config, $user;
|
global $phpEx, $config, $user;
|
||||||
|
|
||||||
$item_row['link'] = feed_append_sid('/viewtopic.' . $phpEx, "t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}");
|
$item_row['link'] = $this->helper->append_sid('/viewtopic.' . $phpEx, "t={$row['topic_id']}&p={$row['post_id']}#p{$row['post_id']}");
|
||||||
|
|
||||||
if ($config['feed_item_statistics'])
|
if ($config['feed_item_statistics'])
|
||||||
{
|
{
|
||||||
|
|
|
@ -28,11 +28,17 @@ class phpbb_feed_topic extends phpbb_feed_post_base
|
||||||
var $forum_id = 0;
|
var $forum_id = 0;
|
||||||
var $topic_data = array();
|
var $topic_data = array();
|
||||||
|
|
||||||
function __construct($topic_id)
|
/**
|
||||||
|
* Set the Topic ID
|
||||||
|
*
|
||||||
|
* @param int $topic_id Topic ID
|
||||||
|
* @return phpbb_feed_topic
|
||||||
|
*/
|
||||||
|
public function set_topic_id($topic_id)
|
||||||
{
|
{
|
||||||
parent::__construct();
|
|
||||||
|
|
||||||
$this->topic_id = (int) $topic_id;
|
$this->topic_id = (int) $topic_id;
|
||||||
|
|
||||||
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
function open()
|
function open()
|
||||||
|
|
|
@ -47,7 +47,7 @@ abstract class phpbb_feed_topic_base extends phpbb_feed_base
|
||||||
{
|
{
|
||||||
global $phpEx, $config, $user;
|
global $phpEx, $config, $user;
|
||||||
|
|
||||||
$item_row['link'] = feed_append_sid('/viewtopic.' . $phpEx, 't=' . $row['topic_id'] . '&p=' . $row['post_id'] . '#p' . $row['post_id']);
|
$item_row['link'] = $this->helper->append_sid('/viewtopic.' . $phpEx, 't=' . $row['topic_id'] . '&p=' . $row['post_id'] . '#p' . $row['post_id']);
|
||||||
|
|
||||||
if ($config['feed_item_statistics'])
|
if ($config['feed_item_statistics'])
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue