I am currently trying to figure out why I get this error:
FatalThrowableError: Class 'App\Http\Controllers\Object' not found in Operators.php line 23
This is the Operators.php controller from where the error is coming from:
public function getOperatorData()
{
$api = new Client([
'base_uri' => 'https://www.space-track.org',
'cookies' => true,
]); $api->post('ajaxauth/login', [
'form_params' => [
'identity' => '#',
'password' => '#',
],
]);
$response = $api->get('basicspacedata/query/class/satcat/orderby/INTLDES%20desc/limit/1/metadata/false');
$mydata = json_decode($response->getBody()->getContents());
$object = new Object();
$object->intldes = $mydata->INTLDES;
$object->satname = $mydata->SATNAME;
$object->save();
return view('pages/satellite-database', compact('object'));
}
The specific line from where the error comes from is:
$object = new Object();
The line shown above should be creating a new model for querying`in a blade file later on.
I am usually able to solve these (either I forgot the 'use' or something), but I have been unable to solve this error.
Turns out the problem lay in the $mydata = json_decode($response->getBody()->getContents());.
Once I changed $mydata to return, I managed to make the JSON format properly and get the $object array to work.
Related
I have a php class that uses guzzle to call an API and get a response:
public function getResponseToken()
{
$response = $this->myGUzzleClient->request(
'POST',
'/token.php,
[
'headers' => [
'Content-Type' => 'application/x-www-form-urlencoded'
],
'form_params' => [
'username' => $this->params['username'],
'password' => $this->params['password'],
]
]
);
return json_decode($response->getBody()->getContents())->token;
}
I am trying to test this method using guzzle mock handler, this is what I have done so far but not working:
public function testGetResponseToken()
{
$token = 'stringtoken12345stringtoken12345stringtoken12345';
$mockHandler = new MockHandler([
new Response(200, ['X-Foo' => 'Bar'], $token)
]
);
$handlerStack = HandlerStack::create($mockHandler);
$client = new Client(['handler' => $handlerStack]);
$myService = new MyService(
new Logger('testLogger'),
$client,
$this->config
);
$this->assertEquals($token, $myService->getResponseToken());
}
the error I am getting says "Trying to get property of non-object", so looks to me MyService is not using the handler to make the call. What am I doing wrong?
The class works as expected outside of the test context. Also note the client in normally injected in MyService from service.yml (I am using symfony).
Your handler work fine, you just mock the wrong response data. You should make the response as raw json.
Try
$token = 'stringtoken12345stringtoken12345stringtoken12345';
$mockHandler = new MockHandler(
[
new Response(200, ['X-Foo' => 'Bar'], \json_encode([ 'token' => $token ]))
]
);
Now it should be works
I'm using https://github.com/AlexaCRM/php-crm-toolkit to send data from a form to an entity in CRM.
With normal fields it's okay but when I want to add 'new_produit_demande' it's gives error because that field is assigned to another entity ('new_produituic') and ('contact')
Any suggestions?
This is some code and it's not working.
<?php
require 'autoload.php' ;
use AlexaCRM\CRMToolkit\Client as OrganizationService;
use AlexaCRM\CRMToolkit\Settings;
$options = [
'serverUrl' => 'https://xxxxx',
'username' => 'xxxx',
'password' => 'xxxx',
'authMode' => 'xxx',
];
$serviceSettings = new Settings( $options );
$service = new OrganizationService( $serviceSettings );
$guid = 'd5bac140-b68b-e911-80cc-005056aa3849';
$contact = $service->entity('contact');
$contact->firstname='product1';
$contact->new_produit_demande = new EntityReference('new_produituic',$guid);
$contactId = $contact->create();
The error:
Fatal error: Class 'EntityReference' not found in C:\xampp\htdocs\ccr\test.php on line 29
You have to include the below namespace:
use AlexaCRM\CRMToolkit\Entity\EntityReference;
I am posting data to my script file to receive data. In my script file, File.php, I am not able to get the object patient in the dumped results. When i do var_dump($get_patient_info->patient);,
it throws an error saying Object {patient} not found.
Could i be mapping the data wrongly?
PS: Beginner in Laravel
SendingData Controller
$hospitalData = [];
$hospitalData[] = [
'patient' => 'Mohammed Shammar',
'number' => '34',
],
$url = "https://example.com/file.php";
$client = new Client();
$request = $client->post($url, [
'multipart' => [
[
'name' => 'patient_info',
'contents' => json_encode($hospitalData),
],
],
]);
$response = $request->getBody();
return $response;
File.php
$get_patient_info = $_POST['patient_info'];
var_dump($get_patient_info);
Results
string(189) "[{"patient":"Mohammed Shammar","number":"34"}]"
You can json_decode and fetch the data as follows,
$temp = json_decode($get_patient_info);
echo $get_patient_info[0]->patient;
json_decode — Decodes a JSON string
Hope this helps.
I am completely new to PHP SOAP . After doing some R&D for my problem I got some links of stackoverflow but didn't get the perfect solution.
Here is my problem :
I am creating a SOAP client that will execute a method called GetPassword and It will return an encrypted password with response code '100' if the credentials is correct. In case of wrong credential a response code '101' and the response status will receive.
Here is my code (I am hiding the credentials for security purpose):
$url= "http://bsestarmfdemo.bseindia.com/StarMFFileUploadService/StarMFFileUploadService.svc?wsdl";
$method = "GetPassword";
$error=0;
$client = new SoapClient($url, array('soap_version' => SOAP_1_2 , 'SoapAction'=>'http://tempuri.org/IStarMFFileUploadService/GetPassword'));
$actionHeader= array();
$actionHeader[] = new SoapHeader('http://www.w3.org/2005/08/addressing',
'Action',
'http://tempuri.org/IStarMFFileUploadService/GetPassword');
$actionHeader[] = new SoapHeader('http://www.w3.org/2005/08/addressing',
'To',
'http://bsestarmfdemo.bseindia.com/StarMFFileUploadService/StarMFFileUploadService.svc/Basic');
$client->__setSoapHeaders($actionHeader);
$param = array('MemberId' => 'XXXXX', 'Password' => 'XXXXXXX', 'UserId' => 'XXXXXXX');
try{
$info = $client->__call($method, array($param));
}
catch (SoapFault $fault) {
$error = 1;
}
if($error==1) {
$xml=$fault;
}else{
$xml = $info;
}
echo($xml);
Some couples of days ago I got this error and the error was happening due to the mismatch of parameters. But this time I think the parameters are correct. So may be I am doing some small mistakes.. Please help me to find the mistakes.
If any input needed, please let me know in the comment, I will update.
Please Note : I tested the wsdl URL with the SoapUI software and it is returning perfectly.
The Problem was with Parameter . Just analyze the structure of the Method GetPassword and found that it take only one parameter named 'Param' which is an object and inside the Param object it is taking the values of MemberId', 'Password' , 'UserId'.
So just need to change one line of code.
use
$param =array ('Param' => array('MemberId' => 'XXXXX', 'Password' => 'XXXXXXX', 'UserId' => 'XXXXXXX') );
Instead of
$param = array('MemberId' => 'XXXXX', 'Password' => 'XXXXXXX', 'UserId' => 'XXXXXXX');
and the issue resolved.
This is the code I am using
$client = new Client();
$requests = [
$client->createRequest('GET', 'http://httpbin.org'),
$client->createRequest('GET', 'http://httpbin.org')
];
$options = [
'complete' => [
[
'fn' => function (CompleteEvent $event) {
$crawler = new Crawler('GET', $event->getRequest()->getUrl());
echo '<p>'.$crawler->filter('title')->text().'</p>';
},
'priority' => 0,
'once' => false
]
]
];
$pool = new Pool($client, $requests, $options);
$pool->wait();
It gives no error but it outputs nothing either. I have tried replacing the URLs but still I get no output.
Your primary issue with the code sample is the instantiation of your Symfony\Component\DomCrawler\Crawler object. As currently written, "GET" is the sole content of $crawler; as a result the call to $crawler->filter() returns an instance of Symfony\Component\DomCrawler\Crawler that contains an empty DOMNodeList. This is why your output is empty.
Replace:
$crawler = new Crawler('GET', $event->getRequest()->getUrl());
with:
$crawler = new Crawler(null, $event->getRequest()->getUrl());
$crawler->addContent(
$event->getResponse()->getBody(),
$event->getResponse()->getHeader('Content-Type')
);