/** * Executes all parsers * @param string $text Text * @return string */ public function parser($text) { //Gets all current class methods, except for `parser()` and `remove()` $methods = getChildMethods(get_class(), ['parser', 'remove']); //Calls dynamically each method foreach ($methods as $method) { $text = self::$method($text); } return $text; }
/** * Gets all menu name methods from a plugin * @param string $plugin Plugin name * @return array|null */ public function getMenuMethods($plugin) { //Gets all methods from `$PLUGIN\View\Helper\MenuHelper` $methods = getChildMethods(sprintf('\\%s\\View\\Helper\\MenuHelper', $plugin)); if (empty($methods)) { return null; } //Filters invalid name methods $methods = preg_grep('/^(?!_).+$/', $methods); return array_values($methods); }
/** * Gets all update methods. * * Each value contains the name method and the version number. * @return array */ protected function _getAllUpdateMethods() { $methods = getChildMethods(get_called_class()); return af(array_map(function ($method) { //Filters invalid method names if (!preg_match('/^to([0-9]+)v([0-9]+)v(.+)$/', $method, $matches)) { return false; } //Returns array with the name method and the version number return ['name' => $method, 'version' => sprintf('%s.%s.%s', $matches[1], $matches[2], $matches[3])]; }, $methods)); }
/** * Generate the sitemap. * * For each plugin, it calls dynamically all methods from class * `$PLUGIN\Utility\Sitemap`. * Each method must be return an array or urls to add to the sitemap. * @return string * @see MeCms\Utility\Sitemap * @uses MeCms\Core\Plugin::all() * @uses parse() */ public function generate() { //Adds the homepage $url = [self::parse('/')]; foreach (Plugin::all() as $plugin) { //Sets the class name $class = sprintf('\\%s\\Utility\\Sitemap', $plugin); //Gets all methods from `$PLUGIN\Utility\Sitemap` class $methods = getChildMethods($class); if (empty($methods)) { continue; } //Calls all methods foreach ($methods as $method) { $url = am($url, call_user_func([$class, $method])); } } $xml = Xml::fromArray(['urlset' => ['xmlns:' => 'http://www.sitemaps.org/schemas/sitemap/0.9', 'url' => $url]], ['pretty' => true]); return $xml->asXML(); }