[ Index ]

PHP Cross Reference of phpBB-3.3.14-deutsch

title

Body

[close]

/phpbb/hook/ -> finder.php (source)

   1  <?php
   2  /**
   3  *
   4  * This file is part of the phpBB Forum Software package.
   5  *
   6  * @copyright (c) phpBB Limited <https://www.phpbb.com>
   7  * @license GNU General Public License, version 2 (GPL-2.0)
   8  *
   9  * For full copyright and license information, please see
  10  * the docs/CREDITS.txt file.
  11  *
  12  */
  13  
  14  namespace phpbb\hook;
  15  
  16  /**
  17  * The hook finder locates installed hooks.
  18  */
  19  class finder
  20  {
  21      /**
  22       * @var \phpbb\cache\driver\driver_interface
  23       */
  24      protected $cache;
  25  
  26      /**
  27       * @var string
  28       */
  29      protected $phpbb_root_path;
  30  
  31      /**
  32       * @var string
  33       */
  34      protected $php_ext;
  35  
  36      /**
  37      * Creates a new finder instance.
  38      *
  39      * @param string $phpbb_root_path Path to the phpbb root directory
  40      * @param string $php_ext php file extension
  41      * @param \phpbb\cache\driver\driver_interface $cache A cache instance or null
  42      */
  43  	public function __construct($phpbb_root_path, $php_ext, \phpbb\cache\driver\driver_interface $cache = null)
  44      {
  45          $this->phpbb_root_path = $phpbb_root_path;
  46          $this->cache = $cache;
  47          $this->php_ext = $php_ext;
  48      }
  49  
  50      /**
  51      * Finds all hook files.
  52      *
  53      * @param bool $cache Whether the result should be cached
  54      * @return array An array of paths to found hook files
  55      */
  56  	public function find($cache = true)
  57      {
  58          if (!defined('DEBUG') && $cache && $this->cache)
  59          {
  60              $hook_files = $this->cache->get('_hooks');
  61              if ($hook_files !== false)
  62              {
  63                  return $hook_files;
  64              }
  65          }
  66  
  67          $hook_files = array();
  68  
  69          // Now search for hooks...
  70          $dh = @opendir($this->phpbb_root_path . 'includes/hooks/');
  71  
  72          if ($dh)
  73          {
  74              while (($file = readdir($dh)) !== false)
  75              {
  76                  if (strpos($file, 'hook_') === 0 && substr($file, -strlen('.' . $this->php_ext)) === '.' . $this->php_ext)
  77                  {
  78                      $hook_files[] = substr($file, 0, -(strlen($this->php_ext) + 1));
  79                  }
  80              }
  81              closedir($dh);
  82          }
  83  
  84          if ($cache && $this->cache)
  85          {
  86              $this->cache->put('_hooks', $hook_files);
  87          }
  88  
  89          return $hook_files;
  90      }
  91  }


Generated: Mon Nov 25 19:05:08 2024 Cross-referenced by PHPXref 0.7.1