/** * * @param type $moduleName * @param type $moduleListenersPath */ private static function attachModuleEventListeners($moduleSource, $moduleTarget, $moduleListenersPath) { $emitter = Di::getDefault()->get('events'); $myListeners = File::getFiles($moduleListenersPath, 'php'); foreach ($myListeners as $myListener) { $listener = basename($myListener, '.php'); $eventName = CamelCaseTransformation::camelCaseToCustom($moduleTarget, '-') . '.' . CamelCaseTransformation::camelCaseToCustom($listener, '.'); $emitter->on(strtolower($eventName), function ($params) use($listener, $moduleSource, $moduleTarget) { call_user_func(array($moduleSource . "\\Listeners\\" . $moduleTarget . "\\" . $listener, "execute"), $params); }); } }
/** * * @method get * @route /auth/[i:id]/[a:name] */ public function getDefaultAuthValuesAction() { $requestParam = $this->getParams('named'); $auth_id = $requestParam['id']; $param_name = strtolower(CamelCaseTransformation::camelCaseToCustom($requestParam['name'], '_')); $data = array(); if (in_array($param_name, self::$authInfosFields)) { $contact_template = AuthResourcesInfoRepository::getInfosFromName($param_name, $auth_id); if (!empty($contact_template)) { $data = array('id' => $contact_template['ar_id'], 'text' => $contact_template['ari_value']); } } return $this->router->response()->json($data); }
/** * * @param type $componentName * @return type */ public static function parseComponentName($componentName) { $call = ""; $parsedComponent = explode('.', $componentName); if (count($parsedComponent) == 1 || $parsedComponent[0] === 'core') { $call .= '\\Centreon\\Internal\\Form\\Component\\' . ucfirst($componentName); } else { $call .= '\\' . CamelCaseTransformation::customToCamelCase($parsedComponent[0], '-') . '\\Forms\\Components\\'; for ($i = 1; $i < count($parsedComponent); $i++) { $call .= ucfirst($parsedComponent[$i]); } } return $call; }
/** * */ public function generateAction() { $moduleCanonicalName = InputOutput::prompt(_("Type the module canonical name here (in CamelCase, it must not contains Module at the ends)"), function ($params, &$result) { call_user_func_array(array('\\Centreon\\Internal\\Module\\Informations', 'isCanonicalNameValid'), array($params, &$result)); }); // Display Name and short name $moduleDisplayName = CamelCaseTransformation::camelCaseToCustom($moduleCanonicalName, " "); $moduleShortname = strtolower(CamelCaseTransformation::camelCaseToCustom($moduleCanonicalName, "-")); $moduleGenerator = new Generator($moduleCanonicalName); $moduleGenerator->setModuleShortName($moduleShortname); $moduleGenerator->setModuleDisplayName($moduleDisplayName); // Get Module ShortName set by user $userAnswer = InputOutput::prompt(_("Type the module shortname here (seperate by -) [" . $moduleShortname . "]")); if (!empty($userAnswer)) { $moduleShortname = $userAnswer; } // Type User Name $moduleAuthor = InputOutput::prompt(_("Type your name here")); $moduleGenerator->setModuleAuthor($moduleAuthor); // Ask For generating Directory Structure InputOutput::display(_("Generating module full structure... "), false); $moduleGenerator->generateModuleStructure(); $moduleGenerator->generateConfigFile(); $moduleGenerator->createSampleInstaller(); InputOutput::display(_("Done\n"), true, "bgreen"); // Ask For sample Controller/View $generateController = InputOutput::prompt(_("Generate sample controller/view (yes/no)? [yes]")); if (empty($generateController) || $generateController == "yes" || $generateController == "y") { $moduleGenerator->createSampleController(); $moduleGenerator->createSampleView(); } // Ask to install the module $installModule = InputOutput::prompt(_("Install the module(yes/no)? [no] ")); if (!empty($installModule) && ($installModule == "yes" || $installModule == "y")) { $moduleInstaller = Informations::getModuleInstaller($moduleShortname); $moduleInstaller->install(); } }
/** * * @param string $canonicalName * @param array $result */ public static function isCanonicalNameValid($canonicalName, &$result) { $canonicalNameNotOk = true; $error = ""; if (!CamelCaseTransformation::isCamelCase($canonicalName)) { $canonicalNameNotOk = false; $error = "The given canonical name is not in CamelCase"; } elseif (ucwords(substr($canonicalName, -6)) === "Module") { $canonicalNameNotOk = false; $error = "The given canonical name contains 'Module' at the end"; } elseif (self::isModuleCanonicalExists($canonicalName)) { $canonicalNameNotOk = false; $error = "A module with the same canonical name already exist in your centreon"; } $result['success'] = $canonicalNameNotOk; $result['message'] = $error; }
/** * * @param type $validatorName * @return type */ protected function parseValidatorName($validatorName) { $call = ""; $parsedValidator = explode('.', $validatorName); if ($parsedValidator[0] === 'core') { $call .= '\\Centreon\\Internal\\Form\\Validators\\'; } else { $call .= '\\' . CamelCaseTransformation::customToCamelCase($parsedValidator[0], '-') . '\\Forms\\Validators\\'; } for ($i = 1; $i < count($parsedValidator); $i++) { $call .= ucfirst($parsedValidator[$i]); } return $call; }