1111namespace phpbb \ideas ;
1212
1313/**
14- * This ext class is optional and can be omitted if left empty.
15- * However, you can add special (un)installation commands in the
16- * methods enable_step(), disable_step() and purge_step(). As it is,
17- * these methods are defined in \phpbb\extension\base, which this
18- * class extends, but you can overwrite them to give special
19- * instructions for those cases.
20- */
14+ * This ext class is optional and can be omitted if left empty.
15+ * However, you can add special (un)installation commands in the
16+ * methods enable_step(), disable_step() and purge_step(). As it is,
17+ * these methods are defined in \phpbb\extension\base, which this
18+ * class extends, but you can overwrite them to give special
19+ * instructions for those cases.
20+ */
2121class ext extends \phpbb \extension \base
2222{
2323 public const SORT_AUTHOR = 'author ' ;
@@ -30,45 +30,61 @@ class ext extends \phpbb\extension\base
3030 public const SORT_MYIDEAS = 'egosearch ' ;
3131 public const SUBJECT_LENGTH = 120 ;
3232 public const NUM_IDEAS = 5 ;
33+ public const NOTIFICATION_TYPE_STATUS = 'phpbb.ideas.notification.type.status ' ;
3334
3435 /** @var array Idea status names and IDs */
35- public static $ statuses = array (
36+ public static $ statuses = [
3637 'NEW ' => 1 ,
3738 'IN_PROGRESS ' => 2 ,
3839 'IMPLEMENTED ' => 3 ,
3940 'DUPLICATE ' => 4 ,
4041 'INVALID ' => 5 ,
41- );
42+ ];
43+
44+ /** @var array Cached flipped statuses array */
45+ private static $ status_names ;
4246
4347 /**
4448 * Return the status name from the status ID.
4549 *
4650 * @param int $id ID of the status.
47- *
4851 * @return string The status name.
49- * @static
50- * @access public
5152 */
5253 public static function status_name ($ id )
5354 {
54- return array_flip (self ::$ statuses )[$ id ];
55+ if (self ::$ status_names === null )
56+ {
57+ self ::$ status_names = array_flip (self ::$ statuses );
58+ }
59+
60+ return self ::$ status_names [$ id ];
5561 }
5662
5763 /**
5864 * Check whether the extension can be enabled.
5965 *
60- * Requires phpBB >= 3.2.3 due to removal of deprecated Twig functions (ie Twig_SimpleFunction)
6166 * Requires phpBB >= 3.3.0 due to use of PHP 7 features
62- * Requires PHP >= 7.1 .0
67+ * Requires PHP >= 7.2 .0
6368 *
6469 * @return bool
65- * @access public
6670 */
6771 public function is_enableable ()
6872 {
69- return !(PHP_VERSION_ID < 70100 ||
70- phpbb_version_compare (PHPBB_VERSION , '3.3.0 ' , '< ' ) ||
71- phpbb_version_compare (PHPBB_VERSION , '4.0.0-dev ' , '>= ' ));
73+ return PHP_VERSION_ID >= 70200
74+ && phpbb_version_compare (PHPBB_VERSION , '3.3.0 ' , '>= ' )
75+ && phpbb_version_compare (PHPBB_VERSION , '4.0.0-dev ' , '< ' );
76+ }
77+
78+ /**
79+ * Handle notification management for extension lifecycle
80+ *
81+ * @param string $method The notification manager method to call
82+ * @return string
83+ */
84+ private function handle_notifications ($ method )
85+ {
86+ $ this ->container ->get ('notification_manager ' )->$ method (self ::NOTIFICATION_TYPE_STATUS );
87+ return 'notification ' ;
7288 }
7389
7490 /**
@@ -79,15 +95,7 @@ public function is_enableable()
7995 */
8096 public function enable_step ($ old_state )
8197 {
82- if ($ old_state === false )
83- {
84- $ this ->container ->get ('notification_manager ' )
85- ->enable_notifications ('phpbb.ideas.notification.type.status ' );
86-
87- return 'notification ' ;
88- }
89-
90- return parent ::enable_step ($ old_state );
98+ return $ old_state === false ? $ this ->handle_notifications ('enable_notifications ' ) : parent ::enable_step ($ old_state );
9199 }
92100
93101 /**
@@ -98,33 +106,17 @@ public function enable_step($old_state)
98106 */
99107 public function disable_step ($ old_state )
100108 {
101- if ($ old_state === false )
102- {
103- $ this ->container ->get ('notification_manager ' )
104- ->disable_notifications ('phpbb.ideas.notification.type.status ' );
105-
106- return 'notification ' ;
107- }
108-
109- return parent ::disable_step ($ old_state );
109+ return $ old_state === false ? $ this ->handle_notifications ('disable_notifications ' ) : parent ::disable_step ($ old_state );
110110 }
111111
112112 /**
113113 * Purge notifications for the extension
114114 *
115- * @param mixed $old_state
115+ * @param mixed $old_state
116116 * @return bool|string
117117 */
118118 public function purge_step ($ old_state )
119119 {
120- if ($ old_state === false )
121- {
122- $ this ->container ->get ('notification_manager ' )
123- ->purge_notifications ('phpbb.ideas.notification.type.status ' );
124-
125- return 'notification ' ;
126- }
127-
128- return parent ::purge_step ($ old_state );
120+ return $ old_state === false ? $ this ->handle_notifications ('purge_notifications ' ) : parent ::purge_step ($ old_state );
129121 }
130122}
0 commit comments