tonic icon indicating copy to clipboard operation
tonic copied to clipboard

New class not loaded

Open guilanh opened this issue 10 years ago • 3 comments

Hi, I am using Respond CMS that uses tonic RESTful. I am trying to add a new class in the rest directory. But this class cannot be loaded. I run the following code

require_once '../vendor/peej/tonic/src/Tonic/Autoloader.php';

$app = new Tonic\Application(); $request = new Tonic\Request();

require_once 'myclass.php';

$resource = $app->getResource($request); $response = $resource->exec(); $response->output();

The class was not loaded, I got error 'Tonic\NotFoundException'. Any help would be appreciated.

Regards guilan

guilanh avatar Mar 27 '15 15:03 guilanh

Tonic requires that resource classes are already loaded so that it can reflect upon them. You either need to require your class before instantiating Tonic\Application, or get Tonic to require resources for you by using the "load" configuration option.

peej avatar Mar 29 '15 19:03 peej

I also run this script:

require_once '../vendor/peej/tonic/src/Tonic/Autoloader.php'; $app = new Tonic\Application(array( 'load' => 'myclass.php' )); $request = new Tonic\Request(); $resource = $app->getResource($request); $response = $resource->exec(); $response->output(); echo "load myclass";

The script failed at the line: $resource = $app->getResource($request);

Any idea why the resource cannot be got?

guilanh avatar Mar 31 '15 09:03 guilanh

Having drilled down from Application.php and found the failure occurred at the line 236: $docComment = $this->parseDocComment($classReflector->getDocComment()); getDocComment reads uri from the comments on the top of the class. I didn't copy this comments. I didn't know the comments are so vital in PHP, which is not normal concept. I added the comment /* @uri /myclass/test */. Now myclass is working OK.

guilanh avatar Mar 31 '15 12:03 guilanh