public static function api_menu() { $classes = Kodoc::classes(); ksort($classes); $menu = array(); $route = Route::get('jelly/docs/api'); foreach ($classes as $class) { $class = Kodoc::factory($class); $link = HTML::anchor($route->uri(array('class' => $class->class->name)), $class->class->name); // Only include classes in the Jelly or Jelly Test packages if (isset($class->tags['package'])) { foreach ($class->tags['package'] as $package) { if (in_array($package, array('Jelly', 'Jelly Test'))) { $menu[$package][] = $link; } } } } // Sort the packages ksort($menu); $output = array('<ol>'); foreach ($menu as $package => $list) { // Sort the class list sort($list); $output[] = "<li><strong>{$package}</strong>\n\t<ul><li>" . implode("</li><li>", $list) . "</li></ul>\n</li>"; } $output[] = '</ol>'; return implode("\n", $output); }
public static function classes(array $list = NULL) { if ($list === NULL) { $list = Kohana::list_files('classes'); } $classes = array(); foreach ($list as $name => $path) { if (is_array($path)) { $classes += Kodoc::classes($path); } else { // Remove "classes/" and the extension $class = substr($name, 8, -strlen(EXT)); // Convert slashes to underscores $class = str_replace('/', '_', strtolower($class)); $classes[$class] = $class; } } return $classes; }
public static function class_methods(array $list = NULL) { $list = Kodoc::classes($list); $classes = array(); foreach ($list as $class) { $_class = new ReflectionClass($class); if (stripos($_class->name, 'Kohana') === 0) { // Skip the extension stuff stuff continue; } $methods = array(); foreach ($_class->getMethods() as $_method) { $methods[] = $_method->name; } sort($methods); $classes[$_class->name] = $methods; } return $classes; }
/** * Get all classes and methods of files in a list. * * > I personally don't like this as it was used on the index page. Way too much stuff on one page. It has potential for a package index page though. * > For example: class_methods( Kohana::list_files('classes/sprig') ) could make a nice index page for the sprig package in the api browser * > ~bluehawk * */ public static function class_methods(array $list = NULL) { $list = Kodoc::classes($list); $classes = array(); foreach ($list as $class) { // Skip transparent extension classes if (Kodoc::is_transparent($class)) { continue; } $_class = new ReflectionClass($class); $methods = array(); foreach ($_class->getMethods() as $_method) { $declares = $_method->getDeclaringClass()->name; // Remove the transparent prefix from declaring classes if ($child = Kodoc::is_transparent($declares)) { $declares = $child; } if ($declares === $_class->name or $declares === "Core") { $methods[] = $_method->name; } } sort($methods); $classes[$_class->name] = $methods; } return $classes; }
/** * Get all classes and methods of files in a list. * * > I personally don't like this as it was used on the index page. Way too much stuff on one page. It has potential for a package index page though. * > For example: class_methods( Kohana::list_files('classes/sprig') ) could make a nice index page for the sprig package in the api browser * > ~bluehawk * */ public static function class_methods(array $list = NULL) { $list = Kodoc::classes($list); $classes = array(); foreach ($list as $class) { $_class = new ReflectionClass($class); if (stripos($_class->name, 'Kohana_') === 0) { // Skip transparent extension classes continue; } $methods = array(); foreach ($_class->getMethods() as $_method) { $declares = $_method->getDeclaringClass()->name; if (stripos($declares, 'Kohana_') === 0) { // Remove "Kohana_" $declares = substr($declares, 7); } if ($declares === $_class->name or $declares === "Core") { $methods[] = $_method->name; } } sort($methods); $classes[$_class->name] = $methods; } return $classes; }
/** * Returns an array of all the classes available, built by listing all files in the classes folder and then trying to create that class. * * This means any empty class files (as in complety empty) will cause an exception * * @param array array of files, obtained using Kohana::list_files * @return array an array of all the class names */ public static function classes($type = NULL) { $classes = array(); if ($type === NULL) { foreach (array('libraries', 'helpers', 'models', 'controllers', 'core', 'config') as $type) { $classes[$type] = Kodoc::classes($type); } } else { $files = Kohana::list_files($type); foreach ($files as $class) { // Remove directory and the extension $class = basename($class, EXT); // Add Controller prefix if ($type === 'controllers') { $class .= '_Controller'; } else { if ($type === 'models') { $class .= '_Model'; } } $classes[$class] = $class; } } return $classes; }
public function action_index() { $msg = array(); $exclude_class = array_map('strtolower', Kohana::config('cs.exclude_class')); // arrays of different mask types and precise names $prec = array(); // like 'someword' $ast_left = array(); // like '*someword' $ast_right = array(); // like 'someword*' $two_ast = array(); // like '*someword*' foreach ($exclude_class as $mask) { if (strpos($mask, '*') === 0 and strrpos($mask, '*') === strlen($mask) - 1) { // any occurrence $two_ast[] = substr($mask, 1, -1); } elseif (strpos($mask, '*') === 0) { // masked as '*someword' $ast_left[] = substr($mask, 1); } elseif (strrpos($mask, '*') === strlen($mask) - 1) { // masked as 'someword*' $ast_right[] = substr($mask, 0, -1); } else { $prec[] = $mask; } } $classes = Kodoc::classes(); // remove excluded classes from list foreach ($classes as $class) { if (isset($classes['kohana_' . $class])) { unset($classes['kohana_' . $class]); } // exclude classes that have names set precisely if (in_array(strtolower($class), $prec)) { unset($classes[$class]); continue; } $is_class_unset = FALSE; // exclude classes that have names set by mask of type '*someword*' foreach ($two_ast as $mask) { if (strpos(strtolower($class), $mask) !== FALSE) { unset($classes[$class]); $is_class_unset = TRUE; break; } } if ($is_class_unset) { continue; } // exclude classes that have names set by mask of type '*someword' foreach ($ast_left as $mask) { if (substr(strtolower($class), -strlen($mask)) == $mask) { unset($classes[$class]); $is_class_unset = TRUE; break; } } if ($is_class_unset) { continue; } // exclude classes that have names set by mask of type 'someword*' foreach ($ast_right as $mask) { if (strpos(strtolower($class), $mask) === 0) { unset($classes[$class]); break; } } } $is_cache = Kohana::config('cs.cache'); // do we need to save actual state in cache $is_save_cache = FALSE; // check if caching turned on if ($is_cache) { // check whether classes set + exclude classes set was modified $cache_name = sha1(serialize($classes)) . $this->ext; $dir = Kohana_Core::$cache_dir . DIRECTORY_SEPARATOR; if (!is_dir($dir)) { $msg[] = 'No cache directory ' . $dir; $is_save_cache = TRUE; } else { if (is_file($dir . $cache_name)) { $tmp = file_get_contents($dir . $cache_name); if ($tmp) { $classes = unserialize($tmp); $msg[] = 'Data loaded from cache'; } else { $is_save_cache = TRUE; // set for data not be taken from cache $msg[] = 'Failed to load cache'; } } else { $is_save_cache = TRUE; foreach (glob($dir . '*' . $this->ext) as $filename) { if (!unlink($filename)) { $msg[] = 'Can not delete cache file ' . $filename; } } } } } if (!$is_cache or $is_save_cache) { foreach ($classes as $class) { $r_class = Kodoc_Class::factory($class); // to prevent exception when Kodoc::properties() throws exception try { $props = $r_class->properties(); } catch (Kohana_Exception $e) { $props = array(); $msg[] = $e->getMessage(); } $classes[$class] = array('description' => $r_class->description, 'modifiers' => $r_class->modifiers, 'properties' => $props, 'methods' => $r_class->methods()); } if ($is_save_cache) { if (is_dir($dir) and is_writable($dir)) { if (!file_put_contents($dir . $cache_name, serialize($classes))) { $msg[] = 'Failed to save cache'; } } else { $msg[] = 'Not exsisting or not writable cache dir'; } } } $this->template->content = $classes; $this->template->msg = $msg; }