コード例 #1
0
 /**
  * @Setup
  * This handler is called on bot startup.
  */
 public function setup()
 {
     // construct list of command handlers
     $filename = array();
     $reflectedClass = new ReflectionClass($this);
     $className = Registry::formatName(get_class($this));
     foreach ($reflectedClass->getMethods() as $reflectedMethod) {
         if (preg_match('/command$/i', $reflectedMethod->name)) {
             $filename[] = "{$className}.{$reflectedMethod->name}";
         }
     }
     $filename = implode(',', $filename);
     $this->commandManager->activate("msg", $filename, "config", "mod");
     $this->commandManager->activate("guild", $filename, "config", "mod");
     $this->commandManager->activate("priv", $filename, "config", "mod");
     $this->helpManager->register($this->moduleName, "config", "config.txt", "mod", "Configure Commands/Events");
 }
コード例 #2
0
 /**
  * Deactivates events that are annotated on one or more method names
  * if the events are not already deactivated
  *
  * @param Object obj
  * @param String methodName1
  * @param String methodName2 ...
  */
 public function deactivateIfActivated($obj)
 {
     $eventMethods = func_get_args();
     array_shift($eventMethods);
     foreach ($eventMethods as $eventMethod) {
         $call = Registry::formatName(get_class($obj)) . "." . $eventMethod;
         $type = $this->getEventTypeByMethod($obj, $eventMethod);
         if ($type !== null) {
             if (!isset($this->events[$type]) || !in_array($call, $this->events[$type])) {
                 // event already deactivated
                 continue;
             }
             $this->deactivate($type, $call);
         } else {
             $this->logger->log('ERROR', "Could not find event for '{$call}'");
         }
     }
 }
コード例 #3
0
 public static function getNewInstancesInDir($path)
 {
     $original = get_declared_classes();
     if ($dir = dir($path)) {
         while (false !== ($file = $dir->read())) {
             if (!is_dir($path . '/' . $file) && preg_match("/\\.php\$/i", $file)) {
                 require_once "{$path}/{$file}";
             }
         }
         $dir->close();
     }
     $new = array_diff(get_declared_classes(), $original);
     $newInstances = array();
     foreach ($new as $className) {
         $reflection = new ReflectionAnnotatedClass($className);
         if ($reflection->hasAnnotation('Instance')) {
             if ($reflection->getAnnotation('Instance')->value != '') {
                 $name = $reflection->getAnnotation('Instance')->value;
             } else {
                 $name = Registry::formatName($className);
             }
             $newInstances[$name] = $className;
         }
     }
     return $newInstances;
 }