Skip to content

Commit 85f1a70

Browse files
iMattPromichaelcullum
authored andcommitted
Allow functionality within phpBB 3.2
* Allow functionality within phpBB 3.2 # Conflicts: # composer.json # config/services.yml * Reduce some duplication
1 parent ebd91e7 commit 85f1a70

4 files changed

Lines changed: 49 additions & 11 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"extra": {
2424
"display-name": "phpBB Skeleton Extension",
2525
"soft-require": {
26-
"phpbb/phpbb": ">=3.1.4,<3.2.0@dev"
26+
"phpbb/phpbb": ">=3.1.4,<3.3.0@dev"
2727
}
2828
}
2929
}

config/services.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ services:
1818
class: phpbb\skeleton\helper\packager
1919
arguments:
2020
- '@user'
21-
- '@path_helper'
21+
- '@service_container'
2222
- '@phpbb.skeleton.collection'
2323
- '%core.root_path%'
2424

helper/packager.php

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515

1616
use phpbb\config\config;
1717
use phpbb\di\service_collection;
18-
use phpbb\path_helper;
1918
use phpbb\template\context;
19+
use phpbb\template\twig\environment;
20+
use phpbb\template\twig\loader;
2021
use phpbb\template\twig\twig;
2122
use phpbb\user;
23+
use Symfony\Component\DependencyInjection\ContainerInterface;
2224
use Symfony\Component\Filesystem\Filesystem;
2325
use Symfony\Component\Finder\Finder;
2426

@@ -29,8 +31,8 @@ class packager
2931
/** @var user */
3032
protected $user;
3133

32-
/** @var path_helper */
33-
protected $path_helper;
34+
/** @var ContainerInterface */
35+
protected $phpbb_container;
3436

3537
/** @var service_collection */
3638
protected $collection;
@@ -39,14 +41,14 @@ class packager
3941
* Constructor
4042
*
4143
* @param user $user User instance (mostly for translation)
42-
* @param path_helper $path_helper The filesystem object
44+
* @param ContainerInterface $phpbb_container
4345
* @param service_collection $collection
4446
* @param string $root_path
4547
*/
46-
public function __construct(user $user, path_helper $path_helper, service_collection $collection, $root_path)
48+
public function __construct(user $user, ContainerInterface $phpbb_container, service_collection $collection, $root_path)
4749
{
4850
$this->user = $user;
49-
$this->path_helper = $path_helper;
51+
$this->phpbb_container = $phpbb_container;
5052
$this->collection = $collection;
5153
$this->root_path = $root_path;
5254
}
@@ -109,11 +111,43 @@ public function create_extension($data)
109111
$filesystem->remove($this->root_path . 'store/tmp-ext');
110112
$filesystem->mkdir($ext_path);
111113

112-
$template_engine = new twig($this->path_helper, new config(array(
114+
$config = new config(array(
113115
'load_tplcompile' => true,
114116
'tpl_allow_php' => false,
115117
'assets_version' => null,
116-
)), $this->user, new context());
118+
));
119+
120+
if (phpbb_version_compare(PHPBB_VERSION, '3.2.0-dev', '<'))
121+
{
122+
$template_engine = new twig(
123+
$this->phpbb_container->get('path_helper'),
124+
$config,
125+
$this->user,
126+
new context()
127+
);
128+
}
129+
else
130+
{
131+
$template_engine = new twig(
132+
$this->phpbb_container->get('path_helper'),
133+
$config,
134+
new context(),
135+
new environment(
136+
$config,
137+
$this->phpbb_container->get('filesystem'),
138+
$this->phpbb_container->get('path_helper'),
139+
$this->phpbb_container,
140+
$this->phpbb_container->getParameter('core.cache_dir'),
141+
$this->phpbb_container->get('ext.manager'),
142+
new loader(
143+
new \phpbb\filesystem\filesystem()
144+
)
145+
),
146+
$this->phpbb_container->getParameter('core.cache_dir'),
147+
$this->phpbb_container->get('user')
148+
);
149+
}
150+
117151
$template_engine->set_custom_style('skeletonextension', $this->root_path . 'ext/phpbb/skeleton/skeleton');
118152

119153
$template_engine->assign_vars(array(

skeleton/tests/dbal/simple_test.php.tpl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@
1313

1414
namespace {EXTENSION.vendor_name}\{EXTENSION.extension_name}\tests\dbal;
1515

16+
// Need to include functions.php to use phpbb_version_compare in this test
17+
require_once dirname(__FILE__) . '/../../../../../includes/functions.php';
18+
1619
class simple_test extends \phpbb_database_test_case
1720
{
1821
static protected function setup_extensions()
@@ -31,7 +34,8 @@ class simple_test extends \phpbb_database_test_case
3134
public function test_column()
3235
{
3336
$this->db = $this->new_dbal();
34-
$db_tools = new \phpbb\db\tools($this->db);
37+
$tools = (phpbb_version_compare(PHPBB_VERSION, '3.2.0-dev', '<') ? '\phpbb\db\tools' : '\phpbb\db\tools\tools');
38+
$db_tools = new $tools($this->db);
3539
$this->assertTrue($db_tools->sql_column_exists(USERS_TABLE, 'user_acme'), 'Asserting that column "user_acme" exists');
3640
$this->assertFalse($db_tools->sql_column_exists(USERS_TABLE, 'user_acme_demo'), 'Asserting that column "user_acme_demo" does not exist');
3741
}

0 commit comments

Comments
 (0)