peej/tonic — Issue #60: Autoload broken
Author: iDarkBls
Created: 2011-12-08 21:30:12+00:00
State: open

Autoload does not work for me:

in Tonic.php:658/333

"class_exists" call triggers the autoload function defined to dynamicaly load resource classes. Need to add FALSE as the second parameter to prevent firing.

in Tonic:471

The __toString is itended to display loaded resources. So, only loaded resources must be filtered. Ad a conditionnal on loaded value

Here is a patch:

Index: tonic.php
===================================================================
--- tonic.php	(revision 19)
+++ tonic.php	(working copy)
@@ -330,7 +330,7 @@
}

// load definitions of already loaded resource classes
- $resourceClassName = class_exists('Tonic\\Resource') ? 'Tonic\\Resource' : 'Resource';
+ $resourceClassName = class_exists('Tonic\\Resource', FALSE) ? 'Tonic\\Resource' : 'Resource';
foreach (get_declared_classes() as $className) {
if (is_subclass_of($className, $resourceClassName)) {

@@ -469,12 +469,14 @@
}
$str .= 'Loaded Resources:'."\n";
foreach ($this->resources as $uri => $resource) {
- $str .= "\t".$uri."\n";
- if (isset($resource['namespace']) && $resource['namespace']) $str .= "\t\tNamespace: ".$resource['namespace']."\n";
- $str .= "\t\tClass: ".$resource['class']."\n";
- $str .= "\t\tFile: ".$resource['filename'];
- if (isset($resource['line']) && $resource['line']) $str .= '#'.$resource['line'];
- $str .= "\n";
+ if ($resource['loaded']) {
+	$str .= "\t".$uri."\n";
+	if (isset($resource['namespace']) && $resource['namespace']) $str .= "\t\tNamespace: ".$resource['namespace']."\n";
+	$str .= "\t\tClass: ".$resource['class']."\n";
+	$str .= "\t\tFile: ".$resource['filename'];
+	if (isset($resource['line']) && $resource['line']) $str .= '#'.$resource['line'];
+	$str .= "\n";
+	}
}
return $str;
}
@@ -653,7 +655,7 @@
$parameters
);

- $responseClassName = class_exists('Tonic\\Response') ? 'Tonic\\Response' : 'Response';
+ $responseClassName = class_exists('Tonic\\Response', FALSE) ? 'Tonic\\Response' : 'Response';
if (!$response || !($response instanceof $responseClassName)) {
throw new Exception('Method '.$request->method.' of '.get_class($this).' did not return a Response object');
}