X-Git-Url: http://www.aleph1.co.uk/gitweb/?p=yaffs-website;a=blobdiff_plain;f=vendor%2Fchi-teck%2Fdrupal-code-generator%2Fsrc%2FUtils.php;fp=vendor%2Fchi-teck%2Fdrupal-code-generator%2Fsrc%2FUtils.php;h=feea5cb47883814991de7490cefb7f1a5ed6c1ce;hp=0000000000000000000000000000000000000000;hb=af6d1fb995500ae68849458ee10d66abbdcfb252;hpb=680c79a86e3ed402f263faeac92e89fb6d9edcc0 diff --git a/vendor/chi-teck/drupal-code-generator/src/Utils.php b/vendor/chi-teck/drupal-code-generator/src/Utils.php new file mode 100644 index 000000000..feea5cb47 --- /dev/null +++ b/vendor/chi-teck/drupal-code-generator/src/Utils.php @@ -0,0 +1,201 @@ +setValidator([Utils::class, 'validateRequired']); + $questions['machine_name'] = new Question('Module machine name'); + $questions['machine_name']->setValidator([Utils::class, 'validateMachineName']); + return $questions; + } + + /** + * Returns default questions for plugin generators. + * + * @return \Symfony\Component\Console\Question\Question[] + * Array of default questions. + */ + public static function defaultPluginQuestions() { + $questions = Utils::defaultQuestions(); + $questions['plugin_label'] = new Question('Plugin label', 'Example'); + $questions['plugin_label']->setValidator([Utils::class, 'validateRequired']); + $questions['plugin_id'] = new Question('Plugin ID', [Utils::class, 'defaultPluginId']); + $questions['plugin_id']->setValidator([Utils::class, 'validateMachineName']); + return $questions; + } + + /** + * Returns extension root. + * + * @return string|bool + * Extension root directory or false if it was not found. + */ + public static function getExtensionRoot($directory) { + $extension_root = FALSE; + for ($i = 1; $i <= 5; $i++) { + $info_file = $directory . '/' . basename($directory) . '.info'; + if (file_exists($info_file) || file_exists($info_file . '.yml')) { + $extension_root = $directory; + break; + } + $directory = dirname($directory); + } + return $extension_root; + } + + /** + * Removes a given number of lines from the beginning of the string. + */ + public static function removeHeader($content, $header_size) { + return implode("\n", array_slice(explode("\n", $content), $header_size)); + } + + /** + * Return the user's home directory. + */ + public static function getHomeDirectory() { + return isset($_SERVER['HOME']) ? $_SERVER['HOME'] : getenv('HOME'); + } + + /** + * Replaces all tokens in a given string with appropriate values. + * + * @param string $text + * A string potentially containing replaceable tokens. + * @param array $data + * An array where keys are token names and values are replacements. + * + * @return string + * Text with tokens replaced. + */ + public static function tokenReplace($text, array $data) { + $tokens = []; + foreach ($data as $var_name => $var) { + if (is_string($var)) { + $tokens['{' . $var_name . '}'] = $var; + } + } + return str_replace(array_keys($tokens), array_values($tokens), $text); + } + +}