Created
February 6, 2010 03:44
-
-
Save isaiahdw/296515 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php defined('SYSPATH') or die('No direct script access.'); | |
/** | |
* @package Core | |
* | |
* Generates a file to aid Zend Studio's code completion. | |
* Kohana uses class suffixes which aren't used when the class is instantiated. | |
* This script builds a lookup table of class names minus the suffix | |
* | |
* @author Peter Bowyer <peter@mapledesign.co.uk> | |
* @thanks Maple Design Ltd - http://www.mapledesign.co.uk/code/ | |
* @version 1.3 (Kohana 2.3.4 compatible) | |
* @todo Strip out comments before scanning files, so phrases like | |
* 'interface for finding, creating, and deleting cached' don't mess up the regex! | |
* The ReflectionParameter class would be the 'proper' way to tackle this problem... | |
* See: http://uk3.php.net/manual/en/language.oop5.reflection.php#language.oop5.reflection.reflectionparameter | |
*/ | |
class Autocomplete_Controller extends Controller { | |
public function index() | |
{ | |
$out = "<?php\n". | |
"// auto-generated by Kohana-Zend Autocomplete\n". | |
"// Developed by Peter Bowyer, Maple Design (http://www.mapledesign.co.uk/code/\n". | |
"// Last generated: ".date('Y-m-d H:i:s T')."\n\n"; | |
$files = array_merge(Kohana::list_files('libraries'), Kohana::list_files('helpers')); | |
$classes['extend'] = $classes['not_extend'] = array(); | |
foreach ($files as $file) | |
{ | |
$file_contents = file_get_contents($file); | |
$tokens = token_get_all($file_contents); | |
$found_name = FALSE; | |
foreach($tokens as $token) | |
{ | |
// Loop until we find a class or interface | |
if ($token[0] === T_CLASS OR $token[0] === T_INTERFACE OR $found_name) | |
{ | |
// The first string is the class/interface name | |
if ($token[0] === T_STRING) | |
{ | |
// We only care about classes with a _Core suffix | |
if (($suffix = strripos($token[1], '_Core')) > 0) | |
{ | |
$classes['extend'][] = str_ireplace('_Core', '', $token[1]); | |
} | |
else | |
{ | |
$classes['not_extend'][] = $token[1]; | |
} | |
$found_name = FALSE; | |
} | |
else | |
{ | |
$found_name = TRUE; | |
} | |
} | |
} | |
} | |
// Ignore '_Core' classes that have already been transparently extended | |
$classes = array_diff($classes['extend'], $classes['not_extend']); | |
foreach ($classes as $class) | |
{ | |
// Create autocomplete output | |
$out .= 'Class '.$class.' extends '.$class.'_Core {}'."\n\n"; | |
} | |
$cache_path = Kohana::config('core.internal_cache_path'); | |
file_put_contents($cache_path.'kohana_autocomplete.php', $out); | |
echo $cache_path.'kohana_autocomplete.php was successfully generated'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment