diff --git a/classes/controller/devtools.php b/classes/controller/devtools.php new file mode 100644 index 0000000..b6f15ba --- /dev/null +++ b/classes/controller/devtools.php @@ -0,0 +1,111 @@ +template = View::factory('devtools/template'); + } + + public function after() + { + $this->request->response = $this->template; + } + + /** + * Dump constants, Kohana::init() settings, loaded modules, and install.php + */ + public function action_info() + { + $this->template->content = View::factory('devtools/info'); + } + + /** + * Show all classes that are getting transparent extended + */ + public function action_extension() + { + $classes = Arr::flatten(Kohana::list_files('classes')); + + $this->template->content = View::factory('devtools/extension',array('classes'=>$classes)); + } + + /** + * Test a route + */ + public function action_routetest() + { + // Check if a url was provided + $url = Arr::get($_POST,'url',FALSE); + + if ( ! $url) + { + // Try to find a config file + $url = Kohana::config('route-test'); + } + $this->template->content = View::factory('devtools/route-test',array( + // Get all the tests + 'tests' => Route_Tester::create_tests($url), + )); + } + + /** + * Dump all routes + */ + public function action_routes() + { + $this->template->content = View::factory('devtools/route-dump'); + } + + /** + * Dump all config files + */ + public function action_config() + { + $files = Kohana::list_files('config'); + + $configs = array(); + foreach($files as $key => $value) + { + // Trim off "config/" and ".php" + $configs[$key] = substr($key,7,-strlen(EXT)); + } + + $this->template->content = View::factory('devtools/config',array('configs'=>$configs)); + } + + /** + * Dump all message files + */ + public function action_message() + { + $files = Kohana::list_files('messages'); + + $messages = array(); + foreach($files as $key => $value) + { + // Trim off "messages/" and ".php" + $messages[$key] = substr($key,9,-strlen(EXT)); + } + $this->template->content = View::factory('devtools/message',array('messages'=>$messages)); + } + + /** + * Dump all i18n files + */ + public function action_i18n() + { + $files = Kohana::list_files('i18n'); + + $i18n = array(); + foreach($files as $key => $value) + { + // Trim off "i18n/" and ".php" + $i18n[$key] = substr($key,5,-strlen(EXT)); + } + $this->template->content = View::factory('devtools/i18n',array('i18n'=>$i18n)); + } + +} \ No newline at end of file diff --git a/classes/devtools/route.php b/classes/devtools/route.php new file mode 100644 index 0000000..8414224 --- /dev/null +++ b/classes/devtools/route.php @@ -0,0 +1,69 @@ + 'docs/media', + * 'controller' => 'userguide', + * 'action' => 'media', + * 'file' => 'image.png', + * ), + * + * 'blog/5/some-title` = array( + * 'route' => 'blog', + * 'controller' => 'blog', + * 'action' => 'article', + * 'id' => '5', + * 'title' => 'some-title', + * ), + * ); + * echo Route::test($urls); + * + * It's useful to store your array of urls to be tested in a config file, + * for example in `application/config/my-route-tests.php` return an array + * similar to the previous examples then call: + * + * echo Route::test(Kohana::config('your-route-tests')); + * + *@author Michael Peters + *@license http://creativecommons.org/licenses/by-sa/3.0/ + */ + public static function test($urls = NULL) + { + // If no url provide, use the current url + if ($urls === NULL) + { + $urls = Request::instance()->uri; + } + return View::factory('devtools/route-test',array( + // Get all the tests + 'tests' => Route_Tester::create_tests($urls), + )); + } + +} // End Route diff --git a/classes/devtools/route/tester.php b/classes/devtools/route/tester.php new file mode 100644 index 0000000..ce7b3f7 --- /dev/null +++ b/classes/devtools/route/tester.php @@ -0,0 +1,110 @@ + $value) + { + $current = new Route_Tester(); + + if (is_array($value)) + { + $current->url = $key; + $current->expected_params = $value; + } + else + { + $current->url = $value; + } + + // Test each route, and save the route and params if it matches + foreach (Route::all() as $route) + { + if ($current->params = $route->matches($current->url)) + { + $current->route = Route::name($route); + $current->params = array_merge(array('route'=>$current->route),$current->params); + break; + } + } + + $array[] = $current; + + } + + return $array; + + } + + public function get_params() + { + $array = array(); + + // Add the result and expected keys to the array + foreach ($this->params as $param => $value) + { + $array[$param]['result'] = $value; + } + + foreach ($this->expected_params as $param => $value) + { + $array[$param]['expected'] = $value; + } + + // Not the prettiest code in the word (wtf arrays), but oh well + foreach ($array as $item => $options) + { + // Assume they don't match. + $array[$item]['error'] = true; + + if ( ! isset($options['expected'])) + { + $array[$item]['expected'] = '[none]'; + } + else if ( ! isset($options['result'])) + { + $array[$item]['result'] = '[none]'; + } + else if ($options['result'] == $options['expected']) + { + $array[$item]['error'] = false; + } + } + + return $array; + } + +} + diff --git a/classes/route.php b/classes/route.php new file mode 100644 index 0000000..8ac54e4 --- /dev/null +++ b/classes/route.php @@ -0,0 +1,3 @@ +)') + ->defaults(array( + 'controller' => 'devtools', + 'action' => 'info' + )); + +if (Kohana::$environment != Kohana::DEVELOPMENT) + throw new Kohana_Exception('Devtools should not be enabled when not in development. Check your environment variable, or disable the devtools module.'); \ No newline at end of file diff --git a/views/devtools/config.php b/views/devtools/config.php new file mode 100644 index 0000000..e14e36d --- /dev/null +++ b/views/devtools/config.php @@ -0,0 +1,19 @@ +
Found classes.
+ +The highest file in the list is the one that takes precedence, the other files are essentially ignored by Kohana.
+ + $value) +{ + $class = substr($key,8,-strlen(EXT)); + $found = array_reverse(Kohana::find_file('classes',$class,NULL,TRUE)); + + if (count($found) > 1) + { + echo "$key is being transparently extended:"; + echo ""; + foreach($found as $path) + { + echo " ".Kohana::debug_path($path)."\n"; + } + echo ""; + } +} \ No newline at end of file diff --git a/views/devtools/i18n.php b/views/devtools/i18n.php new file mode 100644 index 0000000..33b5b80 --- /dev/null +++ b/views/devtools/i18n.php @@ -0,0 +1,17 @@ +
Kohana Version | +'.Kohana::CODENAME.'' ?> | +
---|---|
EXT | ++ |
DOCROOT | ++ |
APPPATH | ++ |
SYSPATH | ++ |
MODPATH | ++ |
Kohana::$environment | ++ |
Kohana::init() settings | +"base_url" = |
+
+ | + (has init.php file)'; ?> + | +
---|
No modules loaded
+ + +PHP Version | + =')): ?> ++ + | Kohana requires PHP 5.2.3 or newer, this version is . | + +|
---|---|---|---|
System Directory | + ++ + | The configured system directory does not exist or does not contain required files. |
+
+ |
Application Directory | + ++ + | The configured application directory does not exist or does not contain required files. |
+
+ |
Cache Directory | + ++ + | The directory is not writable. |
+
+ |
Logs Directory | + ++ + | The directory is not writable. |
+
+ |
PCRE UTF-8 | + +PCRE has not been compiled with UTF-8 support. | + +PCRE has not been compiled with Unicode property support. | + +Pass | + +
SPL Enabled | + +Pass | + +PHP SPL is either not loaded or not compiled in. | + +|
Reflection Enabled | + +Pass | + +PHP reflection is either not loaded or not compiled in. | + +|
Filters Enabled | + +Pass | + +The filter extension is either not loaded or not compiled in. | + +|
Iconv Extension Loaded | + +Pass | + +The iconv extension is not loaded. | + +|
Mbstring Not Overloaded | + +The mbstring extension is overloading PHP's native string functions. | + +Pass | + +|
Character Type (CTYPE) Extension | + +The ctype extension is not enabled. | + +Pass | + +|
URI Determination | + +Pass | + +Neither $_SERVER['REQUEST_URI'] , $_SERVER['PHP_SELF'] , or $_SERVER['PATH_INFO'] is available. |
+
+
+ The following extensions are not required to run the Kohana core, but if enabled can provide access to additional classes. +
+ +cURL Enabled | + +Pass | + +Kohana requires cURL for the Remote class. | + +
---|---|---|
mcrypt Enabled | + +Pass | + +Kohana requires mcrypt for the Encrypt class. | + +
GD Enabled | + +Pass | + +Kohana requires GD v2 for the Image class. | + +
PDO Enabled | + +Pass | + +Kohana can use PDO to support additional databases. | + +
Route uri | +
|
+
---|---|
Params with regex | + $regex) echo "\"$param\" = \"$regex\" " ?> |
+
Defaults | + $default) echo "\"$param\" = \"$default\" " ?> |
+
+
Compiled Regex | +
|
+
No routes
+ \ No newline at end of file diff --git a/views/devtools/route-test.php b/views/devtools/route-test.php new file mode 100644 index 0000000..fbc175d --- /dev/null +++ b/views/devtools/route-test.php @@ -0,0 +1,143 @@ + + ++ + + 'width:300px')) ?> + + +
+ + + +You can enter a uri to test above, or you can create a config file at config/route-test.php
for easy testing of lots of uris. You can also supply "expected" parameters to quickly test if your routes are functioning like you want them to. The format for the tests: (as it would appear in a config file:)
return array(
+
+ // Simply dump the route and params for these uris
+ 'some/url/to/test',
+ 'another/url',
+ 'guide/api/Class',
+ 'guide/media/image.png',
+
+ // Test that these uris returns the following route and params
+ 'guide/media/image.png' = array(
+ 'route' => 'docs/media',
+ 'controller' => 'userguide',
+ 'action' => 'media',
+ 'file' => 'image.png',
+ ),
+ 'blog/5/some-title` = array(
+ 'route' => 'blog',
+ 'controller' => 'blog',
+ 'action' => 'article',
+ 'id' => '5',
+ 'title' => 'some-title',
+ ),
+);
+
+
+
+
+
+
+
+ Testing the url "url ?> " | ||
---|---|---|
Did not match any routes | ||
param | result | expected | + + get_params() as $name => $param) + { + echo "
{$name} | {$param['result']} | {$param['expected']} | "; + } + ?> + + + + params as $key => $value): ?> +
: |
url}\"\n"; + + if ($test->route === FALSE) + { + echo " ! Did not match any routes\n"; + } + else + { + if ($test->expected_params) + { + foreach ($test->get_params() as $name => $param) + { + echo ($param['error'] ? ' ✓ ' : ' ! ' ).str_pad(str_pad($name.': ',15).$param['result'].' ',35).'(expecting '.$param['expected'].")\n"; + } + + } + else + { + foreach ($test->params as $key => $value) + { + echo ' '.str_pad($key.':',15).$value."\n"; + } + } + } + echo "\n"; + } + ?>+ + \ No newline at end of file diff --git a/views/devtools/template.php b/views/devtools/template.php new file mode 100644 index 0000000..bb7e84d --- /dev/null +++ b/views/devtools/template.php @@ -0,0 +1,189 @@ + + + + + + +