-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 16e81c2
Showing
15 changed files
with
999 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php defined('SYSPATH') or die('No direct script access.'); | ||
|
||
class Controller_devtools extends Controller { | ||
|
||
public $template; | ||
|
||
public function before() | ||
{ | ||
$this->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)); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php defined('SYSPATH') or die('No direct script access.'); | ||
|
||
class Devtools_Route extends Kohana_Route { | ||
|
||
/** | ||
* Test a URL or an array of URLs to see which routes they match. | ||
* | ||
* If no param is passed it will test the current url: | ||
* | ||
* // Test the current url | ||
* echo Route::test(); | ||
* | ||
* To test on a single url: | ||
* | ||
* echo Route::test('some/url/to/test'); | ||
* | ||
* To test several urls: | ||
* | ||
* echo Route::test(array( | ||
* 'some/url/to/test', | ||
* 'another/url', | ||
* 'guide/api/Class', | ||
* 'guide/media/image.png', | ||
* )); | ||
* | ||
* You may also pass the route and parameters you expect, by passing each | ||
* url as a key with an array of expected values. | ||
* | ||
* $urls = array( | ||
* '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', | ||
* ), | ||
* ); | ||
* 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 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
<?php defined('SYSPATH') or die ('No direct script access.'); | ||
/** | ||
* Kohana 3 Route tester class. Use it by calling [Route::test] | ||
* | ||
* @package Bluehawk/Devtools | ||
* @author Michael Peters | ||
*/ | ||
class Devtools_Route_Tester { | ||
|
||
// The url for this test | ||
public $url; | ||
|
||
// The route this url matched | ||
public $route = FALSE; | ||
|
||
// The params the route returned | ||
public $params; | ||
|
||
// The optional expected params from the config | ||
public $expected_params = FALSE; | ||
|
||
/** | ||
* Get an array of Route_Tester objects from the config settings | ||
* | ||
* @param $tests A URL to test, or an array of URLs to test. | ||
* @returns array An array of Route_Tester objects | ||
*/ | ||
public static function create_tests($tests) | ||
{ | ||
if (is_string($tests)) | ||
{ | ||
$tests = array($tests); | ||
} | ||
|
||
$array = array(); | ||
|
||
// Get the url and optional expected_params from the config | ||
foreach ($tests as $key => $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; | ||
} | ||
|
||
} | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php defined('SYSPATH') or die('No direct script access.'); | ||
|
||
class Route extends Devtools_Route { } |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?php defined('SYSPATH') or die ('No direct script access.'); | ||
|
||
class Route_Tester extends Devtools_Route_Tester { } | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php defined('SYSPATH') or die('No direct script access.'); | ||
|
||
Route::set('devtools','devtools(/<action>)') | ||
->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.'); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<h1>Config Dump</h1> | ||
|
||
<?php | ||
|
||
foreach ($configs as $path => $name) | ||
{ | ||
echo "<h3>$path</h3>"; | ||
|
||
try | ||
{ | ||
echo Kohana::debug(Kohana::config($name)); | ||
} | ||
catch (exception $e) | ||
{ | ||
echo "Something went terribly wrong. This is usually caused by | ||
undefined constants because of missing dependancies. Error | ||
message: " . Kohana::exception_text($e); | ||
} | ||
} |
Empty file.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<h1>Transparent Extension</h1> | ||
|
||
<p>Found <?php echo count($classes) ?> classes.</p> | ||
|
||
<p>The highest file in the list is the one that takes precedence, the other files are essentially ignored by Kohana.</p> | ||
|
||
<?php | ||
foreach ($classes as $key => $value) | ||
{ | ||
$class = substr($key,8,-strlen(EXT)); | ||
$found = array_reverse(Kohana::find_file('classes',$class,NULL,TRUE)); | ||
|
||
if (count($found) > 1) | ||
{ | ||
echo "<strong>$key</strong> is being transparently extended:"; | ||
echo "<pre>"; | ||
foreach($found as $path) | ||
{ | ||
echo " ".Kohana::debug_path($path)."\n"; | ||
} | ||
echo "</pre>"; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<h1>I18n Dump</h1> | ||
|
||
<?php | ||
|
||
foreach ($i18n as $path => $name) | ||
{ | ||
echo "<h3>$path</h3>"; | ||
|
||
try | ||
{ | ||
echo Kohana::debug(I18n::load($name)); | ||
} | ||
catch (exception $e) | ||
{ | ||
echo "Something went terribly wrong. Error message: " . Kohana::exception_text($e); | ||
} | ||
} |
Oops, something went wrong.