Example #1
0
 /**
  * @name: activate
  * @description: Activates an event
  */
 public function activate($type, $filename)
 {
     $type = strtolower($type);
     $this->logger->log('DEBUG', "Activating event Type:({$type}) File:({$filename})");
     list($name, $method) = explode(".", $filename);
     if (!Registry::instanceExists($name)) {
         $this->logger->log('ERROR', "Error activating method {$filename} for event type {$type}.  Could not find instance '{$name}'.");
         return;
     }
     if ($type == "setup") {
         $eventObj = new stdClass();
         $eventObj->type = 'setup';
         $this->callEventHandler($eventObj, $filename);
     } else {
         if (in_array($type, self::$EVENT_TYPES)) {
             if (!isset($this->events[$type]) || !in_array($filename, $this->events[$type])) {
                 $this->events[$type][] = $filename;
             } else {
                 $this->logger->log('ERROR', "Error activating event Type:({$type}) File:({$filename}). Event already activated!");
             }
         } else {
             $time = $this->util->parseTime($type);
             if ($time > 0) {
                 $key = $this->getKeyForCronEvent($time, $filename);
                 if ($key === null) {
                     $this->cronevents[] = array('nextevent' => 0, 'filename' => $filename, 'time' => $time);
                 } else {
                     $this->logger->log('ERROR', "Error activating event Type:({$type}) File:({$filename}). Event already activated!");
                 }
             } else {
                 $this->logger->log('ERROR', "Error activating event Type:({$type}) File:({$filename}). The type is not a recognized event type!");
             }
         }
     }
 }
 /**
  * @name: register
  * @description: Registers a subcommand
  */
 public function register($module, $channel, $filename, $command, $admin, $parent_command, $description = 'none', $help = '', $defaultStatus = null)
 {
     $command = strtolower($command);
     $module = strtoupper($module);
     if (!$this->chatBot->processCommandArgs($channel, $admin)) {
         $this->logger->log('ERROR', "Invalid args for {$module}:subcommand({$command})");
         return;
     }
     list($name, $method) = explode(".", $filename);
     if (!Registry::instanceExists($name)) {
         $this->logger->log('ERROR', "Error registering method {$filename} for subcommand {$command}.  Could not find instance '{$name}'.");
         return;
     }
     if ($defaultStatus === null) {
         if ($this->chatBot->vars['default_module_status'] == 1) {
             $status = 1;
         } else {
             $status = 0;
         }
     } else {
         $status = $defaultStatus;
     }
     for ($i = 0; $i < count($channel); $i++) {
         $this->logger->log('DEBUG', "Adding Subcommand to list:({$command}) File:({$filename}) Admin:({$admin}) Channel:({$channel[$i]})");
         if ($this->chatBot->existing_subcmds[$channel[$i]][$command] == true) {
             $sql = "UPDATE cmdcfg_<myname> SET `module` = ?, `verify` = ?, `file` = ?, `description` = ?, `dependson` = ?, `help` = ? WHERE `cmd` = ? AND `type` = ?";
             $this->db->exec($sql, $module, '1', $filename, $description, $parent_command, $help, $command, $channel[$i]);
         } else {
             $sql = "INSERT INTO cmdcfg_<myname> (`module`, `type`, `file`, `cmd`, `admin`, `description`, `verify`, `cmdevent`, `dependson`, `status`, `help`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
             $this->db->exec($sql, $module, $channel[$i], $filename, $command, $admin[$i], $description, '1', 'subcmd', $parent_command, $status, $help);
         }
     }
 }
Example #3
0
 public function registerInstance($MODULE_NAME, $name, &$obj)
 {
     $name = strtolower($name);
     $this->logger->log('DEBUG', "Registering instance name '{$name}' for module '{$MODULE_NAME}'");
     if (Registry::instanceExists($name)) {
         $this->logger->log('WARN', "Instance with name '{$name}' already registered--replaced with new instance");
     }
     $obj->moduleName = $MODULE_NAME;
     Registry::setInstance($name, $obj);
     // register settings annotated on the class
     $reflection = new ReflectionAnnotatedClass($obj);
     foreach ($reflection->getProperties() as $property) {
         if ($property->hasAnnotation('Setting')) {
             $this->settingManager->add($MODULE_NAME, $property->getAnnotation('Setting')->value, $property->getAnnotation('Description')->value, $property->getAnnotation('Visibility')->value, $property->getAnnotation('Type')->value, $obj->{$property->name}, @$property->getAnnotation('Options')->value, @$property->getAnnotation('Intoptions')->value, @$property->getAnnotation('AccessLevel')->value, @$property->getAnnotation('Help')->value);
         }
     }
     // register commands, subcommands, and events annotated on the class
     $commands = array();
     $subcommands = array();
     foreach ($reflection->getAllAnnotations() as $annotation) {
         if ($annotation instanceof DefineCommand) {
             if (!$annotation->command) {
                 $this->logger->log('WARN', "Cannot parse @DefineCommand annotation in '{$name}'.");
             }
             $command = $annotation->command;
             $definition = array('channels' => $annotation->channels, 'defaultStatus' => $annotation->defaultStatus, 'accessLevel' => $annotation->accessLevel, 'description' => $annotation->description, 'help' => $annotation->help, 'handlers' => array());
             list($parentCommand, $subCommand) = explode(" ", $command, 2);
             if ($subCommand) {
                 $definition['parentCommand'] = $parentCommand;
                 $subcommands[$command] = $definition;
             } else {
                 $commands[$command] = $definition;
             }
             // register command alias if defined
             if ($annotation->alias) {
                 $this->commandAlias->register($MODULE_NAME, $command, $annotation->alias);
             }
         }
     }
     foreach ($reflection->getMethods() as $method) {
         if ($method->hasAnnotation('Setup')) {
             $this->setupHandlers[] = array($name, $method->name);
         } else {
             if ($method->hasAnnotation('HandlesCommand')) {
                 $commandName = $method->getAnnotation('HandlesCommand')->value;
                 $methodName = $method->name;
                 $handlerName = "{$name}.{$method->name}";
                 if (isset($commands[$commandName])) {
                     $commands[$commandName]['handlers'][] = $handlerName;
                 } else {
                     if (isset($subcommands[$commandName])) {
                         $subcommands[$commandName]['handlers'][] = $handlerName;
                     } else {
                         $this->logger->log('WARN', "Cannot handle command '{$commandName}' as it is not defined with @DefineCommand in '{$name}'.");
                     }
                 }
             } else {
                 if ($method->hasAnnotation('Event')) {
                     $this->eventManager->register($MODULE_NAME, $method->getAnnotation('Event')->value, $name . '.' . $method->name, @$method->getAnnotation('Description')->value, @$method->getAnnotation('Help')->value, @$method->getAnnotation('DefaultStatus')->value);
                 }
             }
         }
     }
     foreach ($commands as $command => $definition) {
         $this->commandManager->register($MODULE_NAME, $definition['channels'], implode(',', $definition['handlers']), $command, $definition['accessLevel'], $definition['description'], $definition['help'], $definition['defaultStatus']);
     }
     foreach ($subcommands as $subCommand => $definition) {
         $this->subcommandManager->register($MODULE_NAME, $definition['channels'], implode(',', $definition['handlers']), $subCommand, $definition['accessLevel'], $definition['parentCommand'], $definition['description'], $definition['help'], $definition['defaultStatus']);
     }
 }
 /**
  * Returns configuration key. This method is independent from oxConfig functionality.
  *
  * @return string
  */
 protected function getConfigurationKey()
 {
     if (Registry::instanceExists('oxConfigFile')) {
         $config = Registry::get('oxConfigFile');
     } else {
         $config = new ConfigFile(getShopBasePath() . '/config.inc.php');
         Registry::set('oxConfigFile', $config);
     }
     return $config->getVar('sConfigKey') ?: Config::DEFAULT_CONFIG_KEY;
 }
 /**
  * @name: activate
  * @description: Activates a command
  */
 public function activate($channel, $filename, $command, $admin = 'all')
 {
     $command = strtolower($command);
     $admin = strtolower($admin);
     $channel = strtolower($channel);
     $this->logger->log('DEBUG', "Activate Command:({$command}) Admin Type:({$admin}) File:({$filename}) Channel:({$channel})");
     foreach (explode(',', $filename) as $handler) {
         list($name, $method) = explode(".", $handler);
         if (!Registry::instanceExists($name)) {
             $this->logger->log('ERROR', "Error activating method {$handler} for command {$command}.  Could not find instance '{$name}'.");
             return;
         }
     }
     $obj = new stdClass();
     $obj->file = $filename;
     $obj->admin = $admin;
     $this->commands[$channel][$command] = $obj;
 }