[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/lib/plugins/config/core/Setting/ -> SettingAuthtype.php (source)

   1  <?php
   2  
   3  namespace dokuwiki\plugin\config\core\Setting;
   4  
   5  /**
   6   * Class setting_authtype
   7   */
   8  class SettingAuthtype extends SettingMultichoice
   9  {
  10      /** @inheritdoc */
  11      public function initialize($default = null, $local = null, $protected = null)
  12      {
  13          /** @var $plugin_controller \dokuwiki\Extension\PluginController */
  14          global $plugin_controller;
  15  
  16          // retrieve auth types provided by plugins
  17          foreach ($plugin_controller->getList('auth') as $plugin) {
  18              $this->choices[] = $plugin;
  19          }
  20  
  21          parent::initialize($default, $local, $protected);
  22      }
  23  
  24      /** @inheritdoc */
  25      public function update($input)
  26      {
  27          /** @var $plugin_controller \dokuwiki\Extension\PluginController */
  28          global $plugin_controller;
  29  
  30          // is an update possible/requested?
  31          $local = $this->local;                       // save this, parent::update() may change it
  32          if (!parent::update($input)) return false;    // nothing changed or an error caught by parent
  33          $this->local = $local;                       // restore original, more error checking to come
  34  
  35          // attempt to load the plugin
  36          $auth_plugin = $plugin_controller->load('auth', $input);
  37  
  38          // @TODO: throw an error in plugin controller instead of returning null
  39          if (is_null($auth_plugin)) {
  40              $this->error = true;
  41              msg('Cannot load Auth Plugin "' . $input . '"', -1);
  42              return false;
  43          }
  44  
  45          // verify proper instantiation (is this really a plugin?) @TODO use instanceof? implement interface?
  46          if (is_object($auth_plugin) && !method_exists($auth_plugin, 'getPluginName')) {
  47              $this->error = true;
  48              msg('Cannot create Auth Plugin "' . $input . '"', -1);
  49              return false;
  50          }
  51  
  52          // did we change the auth type? logout
  53          global $conf;
  54          if ($conf['authtype'] != $input) {
  55              msg('Authentication system changed. Please re-login.');
  56              auth_logoff();
  57          }
  58  
  59          $this->local = $input;
  60          return true;
  61      }
  62  }