示例#1
0
 /**
  * Class constructor.
  *
  * @param string $plugin_name Name of the plguin.
  * @throws \InvalidArgumentException If the plugin name isn't correct.
  * @throws \RuntimeException If the plugin does not exist.
  */
 public function __construct($plugin_name)
 {
     if (!Utils::isValidPluginName($plugin_name)) {
         throw new \InvalidArgumentException('Wrong plugin name');
     }
     if (!Utils::pluginExists($plugin_name)) {
         throw new \RuntimeException('Plugin is not found');
     }
     $this->pluginName = $plugin_name;
 }
示例#2
0
 /**
  * Loads state by plugin's name.
  *
  * @param string $name Name of the plugin which state should be loaded.
  * @return State|boolean An instance of state or boolean false on failure.
  */
 public static function loadByName($name)
 {
     if (!Utils::isValidPluginName($name)) {
         return false;
     }
     // Load plugin state
     $info = Database::getInstance()->query('SELECT * FROM {plugin} WHERE name = :name', array(':name' => $name), array('return_rows' => Database::RETURN_ONE_ROW));
     // There is no such record in database
     if (!$info) {
         return false;
     }
     // Create and populate object
     $state = new self();
     $state->populateFromDbFields($info);
     return $state;
 }