I am using slim framework. But when i refresh the page i got the following error. My all paths are correct but still getting this error.
{
"message": "Slim Application Error",
"exception": [
{
"type": "DI\\DependencyException",
"code": 0,
"message": "Error while injecting dependencies into App\\Action\\User\\UserListDataTableAction: No entry or class found for 'App\\Domain\\User\\Service\\UserListDataTable'",
"file": "/opt/lampp/htdocs/slim/vendor/php-di/php-di/src/Definition/Resolver/ObjectCreator.php",
"line": 147
},
{
"type": "DI\\NotFoundException",
"code": 0,
"message": "No entry or class found for 'App\\Domain\\User\\Service\\UserListDataTable'",
"file": "/opt/lampp/htdocs/slim/vendor/php-di/php-di/src/Container.php",
"line": 135
}
]
}
<?php
namespace App\Action\User;
use App\Domain\User\Service\UserListDataTable;
use App\Responder\JsonResponder;
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
final class UserListDataTableAction
{
private $userListDataTable;
private $responder;
public function __construct(
UserListDataTable $userListDataTable,
JsonResponder $responder
) {
$this->userListDataTable = $userListDataTable;
$this->responder = $responder;
}
}
Please guide me where i am wrong.
Any solution appreciated!
Related
I have a param in my API:
/** -------- */
#[ORM\JoinColumn(nullable: false)]
#[Groups([Group::CLIENT])]
#[Assert\NotBlank(message: "test not blank message")]
private ?Client $client = null;
/** -------------- */
When I call API without 'client' param I get correct answer:
{
"type": "https://tools.ietf.org/html/rfc2616#section-10",
"title": "An error occurred",
"detail": "client: test not blank message",
"violations": [
{
"propertyPath": "client",
"message": "test not blank message",
"code": "c1051bb4-d103-4f74-8988-acbcafc7fdc3"
}
]
}
But I need to check empty values as well and in this case I get Invalid IRI error.
Request:
{
...
"client": "",
...
}
Response:
{
"type": "https://tools.ietf.org/html/rfc2616#section-10",
"title": "An error occurred",
"detail": "Invalid IRI \"\".",
}
Is it possible to check type of requested param for embedded items in annotations? It works for not embedded items (error returns: the type of attribute must be ). But what about embedded.
I tried use Assert\Type + Assert\Valid but it does not work.
I'm working on a PHP/Lumen 8.x foreach loop to manage the update/insert of records from a mysql DB table in which I'm trying to catch any errors during the update/insert process so that it can continue with subsequent logs in case of error. As I am with Lumen and we are in a certain namespace environment in the catch statement I use "\Exception" to identify the type of exception. However, in no case in which an error occurs can I catch it and in the controller output, that is, in the controller response, an error indicating "Recursion detected" is triggered. I can't catch this last error either.
This is the code snippet for the foreach(...) { ... try..catch ...} block:
foreach($prdsData as $prod){
$cr_sku = $prod['SKU'];
try{
$res_prod_uc[$cr_sku]['err'] = false;
$res_prod_uc[$cr_sku]['res'] = wc_product_update($pd);
} catch( \Exception $e ){
$res_prod_uc[$cr_sku]['err'] = true;
$cr_err_dt = array(
'code' => $e->getCode(),
'msg' => $e->getMessage(),
'file' => $e->getFile(),
'line' => $e->getLine(),
'trace' => $e->getTrace()
);
$res_prod_uc[$cr_sku]['err_data'] = $cr_err_dt;
continue;
}
}
return response()->json($res_prod_uc,200); // this is where the "Recursion detected" error is triggered
This is the output (JSON) of the "Recursion detected" error:
{
"message": "Recursion detected",
"exception": "InvalidArgumentException",
"file": "..../blog/vendor/illuminate/http/JsonResponse.php",
"line": 88,
"trace": [
{
"file": "..../blog/vendor/symfony/http-foundation/JsonResponse.php",
"line": 54,
"function": "setData",
"class": "Illuminate\\Http\\JsonResponse",
"type": "->"
},
{
"file": "..../blog/vendor/illuminate/http/JsonResponse.php",
"line": 32,
"function": "__construct",
"class": "Symfony\\Component\\HttpFoundation\\JsonResponse",
"type": "->"
},
{
"file": "..../blog/vendor/laravel/lumen-framework/src/Http/ResponseFactory.php",
"line": 40,
"function": "__construct",
"class": "Illuminate\\Http\\JsonResponse",
"type": "->"
},
/* this is my controller */
{
"file": "..../blog/app/Http/Controllers/ProductsController.php",
"line": 145,
"function": "json",
"class": "Laravel\\Lumen\\Http\\ResponseFactory",
"type": "->"
},....
How can I go about catching any errors?
Thanks in advance
What was happening is exactly what you say #aynber. I did check and, yes, exceptions are being cached, but the line 'trace' => $e->getTraceAsString() does indeed allocate data where at deeper levels there is object recursion. And by the time the thread reaches return response()->json($res,200); (Which is outside of the try..catch block) the "Recursion detected" error is raised. This error is generated by a call to the json_encode() PHP function found within the Lumen 8 framework.
The solution I used was to replace the getTrace() method with the getTraceAsString() Exception object method.
$api->version('v1', ['middleware' => 'api.auth'], function($api){
$api->get('auth/user', 'App\Http\Controllers\Api\ApiUserController#getAuthUser');
$api->get('auth/getInfo', 'App\Http\Controllers\Api\ApiUserAppointmentController#getInfo');
$api->get('auth/show/{id}', 'App\Http\Controllers\Api\ApiUserAppointmentController#show');
});
public function show($id)
{
echo $id;die;
}
Error
"message": "404 Not Found",
"status_code": 404,
"debug": {
"line": 161,
"file": "C:\\xampp\\htdocs\\G2Project\\medcrip\\vendor\\laravel\\framework\\src\\Illuminate\\Routing\\RouteCollection.php",
I stuck when adding parameter in get method don't know why this is say not found. if i remove {id} from route it works fine but when i do add {id} that says to me not found.
Please advice thanks in advance
To make the auth/show/{id} route work, you should use this URI:
/api/auth/show/53
instead of this:
/api/auth/show/?id=53
https://github.com/hasbridge/php-json-schema
Getting error Class 'JsonValidator' not found.
I did install composer.json as in git folder.
I did put my json schema, json data files in src/Json and created a php file to validate as mentioned in git.
getting error class Class 'JsonValidator' not found.
In their example, they're creating a JsonValidator object.
This is different from the actual namespace of the class, which is Json\Validator.
Try dropping use Json\Validator as JsonValidator at the top of your file so that you're able to refer to the class the same way the docs do.
I'd expand their docs from:
$someJson = '{"foo":"bar"}';
$jsonObject = json_decode($someJson);
$validator = new JsonValidator('/path/to/yourschema.json');
$validator->validate($jsonObject);
To
<?php
namespace Your\Domain;
use Json\Validator as JsonValidator;
require_once('./vendor/autoload.php');
$someJson = '{"foo": "bar"}';
$jsonObject = json_decode($someJson);
$validator = new JsonValidator('/path/to/yourschema.json');
$validator->validate($jsonObject);
Alternatively, you could substitute new JsonValidator('/path/to/yourschema.json') for new Json\Validator('/path/to/yourschema.json').
Edit: By the way - you might find the example schemas at json-schema.org helpful when using this library.
Here's the main one from that link:
{
"title": "Example Schema",
"type": "object",
"properties": {
"firstName": {
"type": "string"
},
"lastName": {
"type": "string"
},
"age": {
"description": "Age in years",
"type": "integer",
"minimum": 0
}
},
"required": ["firstName", "lastName"]
}
Save this file somewhere in your project and refer to it instead of /path/to/yourschema.json.
Restler is refusing to instantiate any of my API classes. It's just always saying it fails on Route, but doesn't bother to provide any other useful information. I installed Restler via composer via "restler/framework" : "3.0.0-RC6" and then created an index.php that looks like this:
<?php
require __DIR__.'/../vendor/autoload.php';
use Luracast\Restler\Restler;
$r = new Restler();
$r->addAPIClass('Explorer');
$r->addAPIClass('Play');
$r->handle();
In the exact same directory as the index.php I've created a file called Play.php that looks like so:
<?php
public class Play
{
public function __construct() {
error_log("I called the constructor!\n", 3, '/tmp/scott');
}
public function index() {
error_log("I called the index\n", 3, '/tmp/scott');
}
When I call http://.../api/play I never see the /tmp/scott file created, and I just get the generic failure response from Restler:
{
"error": {
"code": 404,
"message": "Not Found"
},
"debug": {
"source": "Routes.php:438 at route stage",
"stages": {
"success": [
"get"
],
"failure": [
"route",
"negotiate",
"message"
]
}
}
}
As Luracast noted in the comments, I had to edit the composer.json to add this stanza:
"autoload": {
"psr-0": {
"": "api"
}
}
and then run composer dump-autoload