aboutsummaryrefslogtreecommitdiffstats
path: root/phpBB/includes/hook
diff options
context:
space:
mode:
authorIgor Wiedler <igor@wiedler.ch>2013-01-02 21:52:57 +0100
committerIgor Wiedler <igor@wiedler.ch>2013-01-02 21:52:57 +0100
commit208770d7fddefb7ac46dd63387bc8ab4a2724edd (patch)
tree4d9377436c29a2b272505f7d9039d7110a48054d /phpBB/includes/hook
parent1ca63fb30215c6fb4e51fdffc43c29ad0b417b42 (diff)
parent0483971f7786b10c3359dfbe4912501de0d6c7de (diff)
downloadforums-208770d7fddefb7ac46dd63387bc8ab4a2724edd.tar
forums-208770d7fddefb7ac46dd63387bc8ab4a2724edd.tar.gz
forums-208770d7fddefb7ac46dd63387bc8ab4a2724edd.tar.bz2
forums-208770d7fddefb7ac46dd63387bc8ab4a2724edd.tar.xz
forums-208770d7fddefb7ac46dd63387bc8ab4a2724edd.zip
Merge remote-tracking branch 'p/ticket/11305' into develop
* p/ticket/11305: [ticket/11305] Mock container for cache driver in functional create_user() [ticket/11305] Check for $cache being null before using it in db drivers. [ticket/11305] Define hook finder as a service on the container. [ticket/11305] Adjust comment. [ticket/11305] Use phpbb_create_default_container. [ticket/11305] Create a normal container during final installation step. [ticket/11305] Retrieve cache driver from container rather than cache service. [ticket/11305] Extract hook finder from cache service.
Diffstat (limited to 'phpBB/includes/hook')
-rw-r--r--phpBB/includes/hook/finder.php84
1 files changed, 84 insertions, 0 deletions
diff --git a/phpBB/includes/hook/finder.php b/phpBB/includes/hook/finder.php
new file mode 100644
index 0000000000..065e685514
--- /dev/null
+++ b/phpBB/includes/hook/finder.php
@@ -0,0 +1,84 @@
+<?php
+/**
+*
+* @package extension
+* @copyright (c) 2013 phpBB Group
+* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
+*
+*/
+
+/**
+* @ignore
+*/
+if (!defined('IN_PHPBB'))
+{
+ exit;
+}
+
+/**
+* The hook finder locates installed hooks.
+*
+* @package phpBB3
+*/
+class phpbb_hook_finder
+{
+ protected $phpbb_root_path;
+ protected $cache;
+ protected $php_ext;
+
+ /**
+ * Creates a new finder instance.
+ *
+ * @param string $phpbb_root_path Path to the phpbb root directory
+ * @param string $php_ext php file extension
+ * @param phpbb_cache_driver_interface $cache A cache instance or null
+ */
+ public function __construct($phpbb_root_path, $php_ext, phpbb_cache_driver_interface $cache = null)
+ {
+ $this->phpbb_root_path = $phpbb_root_path;
+ $this->cache = $cache;
+ $this->php_ext = $php_ext;
+ }
+
+ /**
+ * Finds all hook files.
+ *
+ * @param bool $cache Whether the result should be cached
+ * @return array An array of paths to found hook files
+ */
+ public function find($cache = true)
+ {
+ if (!defined('DEBUG') && $cache && $this->cache)
+ {
+ $hook_files = $this->cache->get('_hooks');
+ if ($hook_files !== false)
+ {
+ return $hook_files;
+ }
+ }
+
+ $hook_files = array();
+
+ // Now search for hooks...
+ $dh = @opendir($this->phpbb_root_path . 'includes/hooks/');
+
+ if ($dh)
+ {
+ while (($file = readdir($dh)) !== false)
+ {
+ if (strpos($file, 'hook_') === 0 && substr($file, -(strlen($this->php_ext) + 1)) === '.' . $this->php_ext)
+ {
+ $hook_files[] = substr($file, 0, -(strlen($this->php_ext) + 1));
+ }
+ }
+ closedir($dh);
+ }
+
+ if ($cache && $this->cache)
+ {
+ $this->cache->put('_hooks', $hook_files);
+ }
+
+ return $hook_files;
+ }
+}