Getting `PHP Parse error: syntax error, unexpected ':', expecting ';' or '{'` - parsing

How can I fix this error?
PHP Parse error: syntax error, unexpected ':', expecting ';' or '{' in /home/domainname/public_html/..../src/Parse/HttpClients/ParseCurlHttpClient.php on line 154
PHP sürümü: 7.3.6
Code where error occurs:
public function getResponseContentType()
{
return $this->responseContentType;
}
/**
* Sets up our cURL request in advance
*/
public function setup() : void **//154 line**
{
// init parse curl
$this->parseCurl->init();
$this->parseCurl->setOptionsArray(array(
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_HEADER => 1,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_SSL_VERIFYPEER => true,
CURLOPT_SSL_VERIFYHOST => 2,
));
}
Code repo: https://github.com/parse-community/parse-php-sdk/blob/master/src/Parse/HttpClients/ParseCurlHttpClient.php

Related

SQS RedrivePolicy PHP SDK

Iam new to SQS php SDK, Iam not able to override RedrivePolicy using setQueueAttributes method :(
json string is not accepted as an attribute and I cannot find any clear resources to help me.
Have a look at the below example code:
$queueUrl = "QUEUE_URL";
$client = new SqsClient([
'profile' => 'default',
'region' => 'us-west-2',
'version' => '2012-11-05'
]);
try {
$result = $client->setQueueAttributes(array(
'Attributes' => [
'ReceiveMessageWaitTimeSeconds' => 20
],
'QueueUrl' => $queueUrl, // REQUIRED
));
var_dump($result);
} catch (AwsException $e) {
// output error message if fails
error_log($e->getMessage());
}
Full code:
https://github.com/awsdocs/aws-doc-sdk-examples/blob/master/php/example_code/sqs/LongPollingSetQueueAttributes.php

Yii2 - How to write OAuth Client

I am trying to add FitBit OAuth to my Yii2 app. I have successfully managed to setup other APIs, such as Google and Facebook - but these are using yii\authclient\clients. Here I am trying to write my own using yii\authclient\OAuth2. Here is the code I have:
<?php
namespace app\auth\clients;
class Fitbit extends \yii\authclient\OAuth2{
public $authUrl = 'https://www.fitbit.com/oauth2/authorize';
public $tokenUrl = 'https://api.fitbit.com/oauth2/token';
public $apiBaseUrl = 'https://api.fitbit.com';
public $scope = 'profile';
protected function initUserAttributes(){
return $this->api('/1/user', 'GET');
}
protected function defaultName(){
return 'fitbit';
}
protected function defaultTitle(){
return 'Fitbit';
}
}
Here is the configuration I have:
'authClientCollection' => [
'class' => 'yii\authclient\Collection',
'clients' => [
'google' => [
'class' => 'yii\authclient\clients\Google',
'clientId' => 'ID',
'clientSecret' => 'SECRET',
],
'fitbit' => [
'class' => 'app\auth\clients\Fitbit',
'clientId' => 'ID',
'clientSecret' => 'SECRET',
],
But I am stumped, as this is the error I get:
{"errors":[{
"errorType":"invalid_request",
"message":"Authorization header required. Visit https://dev.fitbit.com/docs/oauth2 for more information on the Fitbit Web API authorization process."
}],
"success":false}
Any help would be really appreciated. Thank you.
EDIT My current thinking is something along the lines of:
return $this->api('/1/user', 'GET', [], [
'WWW-Authenticate' => 'Authorization: Basic ' . base64_encode($this->client_id . ':' . $this->client_secret),
]);
But this still gives me the same error.

How to perform an HTTP request from a Module#onBootstrap(...) in ZF2?

In a Module class of a Zend Framework 2 application I'm sending an HTTP request to a special endpoint to get some information about the user. It works, when I do this within a factory (s. the 1st approach in the code below). It also works within a listener definition in the Module#onBootstrap(...) (s. the 2nd approach). But when I try to perform the call directly from the Module#onBootstrap(...) (s. the 3d approach), the call fails with the error:
PHP Fatal error: Uncaught exception 'Zend\\Http\\Client\\Adapter\\Exception\\TimeoutException' with message 'Read timed out after 30 seconds' in /var/www/path/to/project/vendor/zendframework/zend-http/src/Client/Adapter/Socket.php:600
Stack trace:
#0 /var/www/path/to/project/vendor/zendframework/zend-http/src/Client/Adapter/Socket.php(412): Zend\\Http\\Client\\Adapter\\Socket->_checkSocketReadTimeout()
#1 /var/www/path/to/project/vendor/zendframework/zend-http/src/Client.php(1389): Zend\\Http\\Client\\Adapter\\Socket->read()
#2 /var/www/path/to/project/vendor/zendframework/zend-http/src/Client.php(893): Zend\\Http\\Client->doRequest(Object(Zend\\Uri\\Http), 'POST', false, Array, '')
#3 /var/www/path/to/project/module/MyApi/src/MyApi/Module.php(158): Zend\\Http\\Client->send()
#4 /var/www/path/to/project/module/MyApi/src/MyApi/Module.php(33): MyApi\\Module->retrieveUserInfosEndpoint(Object(ZF\\ContentNegotiation\\Request), 'http://my-project...')
#5 [intern in /var/www/path/to/project/vendor/zendframework/zend-http/src/Client/Adapter/Socket.php on line 600
Why does the error occur? How to send an HTTP request from a Module#onBootstrap(...)?
namespace MyModule;
...
class Module
{
protected $userInfo;
public function onBootstrap(MvcEvent $mvcEvent)
{
// 3d approach -- it does NOT work
$userInfoEndpointUrl = $serviceManager->get('Config')['user_info_endpoint_url'];
$request = $serviceManager->get('Request');
$this->userInfo = $this->retrieveUserInfosEndpoint($request, $userInfoEndpointUrl);
...
$halPlugin->getEventManager()->attach('myeventname', function ($event) use (..., $serviceManager) {
// 2nd approach -- it works
$userInfoEndpointUrl = $serviceManager->get('Config')['user_info_endpoint_url'];
$request = $serviceManager->get('Request');
$this->userInfo = $this->retrieveUserInfosEndpoint($request, $userInfoEndpointUrl);
/*
PHP Fatal error:
Uncaught exception 'Zend\\Http\\Client\\Adapter\\Exception\\TimeoutException'
with message 'Read timed out after 30 seconds'
in /var/www/path/to/project/vendor/zendframework/zend-http/src/Client/Adapter/Socket.php:600
*/
...
});
...
}
...
public function getServiceConfig()
{
return array(
'factories' => array(
'MyModule\\V1\\Rest\\Foo\\FooService' => function(ServiceManager $serviceManager) {
// 1st approach -- it works
$userInfoEndpointUrl = $serviceManager->get('Config')['user_info_endpoint_url'];
$request = $serviceManager->get('Request');
$this->userInfo = $this->retrieveUserInfosEndpoint($request, $userInfoEndpointUrl);
...
return $fooService;
},
...
),
...
);
}
private function retrieveUserInfosEndpoint($request, $userInfoEndpointUrl)
{
$authorizationHeaderValue = $request->getHeader('Authorization')->getFieldValue();
$client = new Client();
$client->setUri($userInfoEndpointUrl);
$client->setMethod('POST');
$client->setOptions(['sslverifypeer' => false]);
$client->setHeaders(['Authorization' => $authorizationHeaderValue]);
$client->setOptions([
'maxredirects' => 10,
'timeout' => 30,
]);
$client->setParameterPost([]);
$response = $client->send();
$userInfo = json_decode($response->getContent(), true);
return $userInfo;
}
}
Well, I see now -- it actually can not work. Performing a new request starts the whole event chain recursively and causes an infinite loop.
In my case to avoid multiple requesting my userinfo endpoint I put the call into a factory and can use it in other factories as well as in event listeners:
namespace MyModule;
...
class Module
{
public function onBootstrap(MvcEvent $mvcEvent)
{
...
$halPlugin->getEventManager()->attach('myeventname', function ($event) use (..., $serviceManager) {
...
$userInfo = $serviceManager->get('MyModule\\Service\\UserInfo');
...
});
...
}
...
public function getServiceConfig()
{
return array(
'factories' => array(
'MyModule\\V1\\Rest\\Foo\\FooService' => function(ServiceManager $serviceManager) {
...
$userInfo = $serviceManager->get('MyModule\\Service\\UserInfo');
...
return $fooService;
},
'MyModule\\Service\\UserInfo' => function(ServiceManager $serviceManager) {
$userInfoEndpointUrl = $serviceManager->get('Config')['user_info_endpoint_url'];
$request = $serviceManager->get('Request');
$userInfo = $this->retrieveUserInfosEndpoint($request, $userInfoEndpointUrl);
return $userInfo;
},
...
),
...
);
}
}

\Zend\Form\Element\Collection validation as a whole

I have form with collection. And i attach validation to whole collecion - i just want to check the existence of certain relations between elements of the collection.
And it works great. in the case of wrong data - form does not pass the "isValid()" test.
But there is one problem. formElementErrors / getMessages didnt return anything.
What i do wrong?
My form:
class Form implements InputFilterProviderInterface {
/**
* #return array
*/
public function getInputFilterSpecification()
{
return [
[
'name' => 'legend',
'required' => true,
'allowEmpty' => false,
'validators' => [
['name' => 'Callback', 'options' => [
'messages' => [
\Zend\Validator\Callback::INVALID_VALUE => 'Wrong',
],
'callback' => function ($values, $context=[]) {
return false;
},
]],
]
],
];
}
public function init()
{
$this->add(
[
'name' => 'legend',
'type' => 'Zend\Form\Element\Collection',
'options' => [
'label' => 'Legenda',
'count' => 2,
'should_create_template' => true,
'allow_add' => true,
'template_placeholder' => '__placeholder__',
'target_element' => [
'type' => 'Narzedzie\Form\Legenda\LegendyOpcjeFieldset',
],
],
]
);
}
}
And view:
$element = $NarzedzieForm->get('legend');
var_dump($element->getMessages()); // in case of error - empty array!
echo $this->formElementErrors($element); // in case of error - empty string
echo $this->formColleciton($element);
Maybe you need to add both messages?
'messages' => [
\Zend\Validator\Callback::INVALID_VALUE => 'Wrong VALUE',
\Zend\Validator\Callback::INVALID_CALLBACK => 'Wrong CALLBACK',
],
as perhaps the invalid callback message is being suppressed as you are only supplying one? I would hope it would fall back to the default. But then all this validator message stuff seems a bit stupid to me the way it is done.
Looks like you have an error in your callback, which might be throwing an exception and is being caught in the validator in the try catch statement maybe?
should be?
function ($values, $context=[]) {
foreach ($values as $value) {
if ($value['el'] == '1') return false;
}
return true;
},
as in $values not $value for the array in the foreach? Probably want to check that key is set too, with an isset($value['el'])?

Issue with uninstalling spring-security-ldap plugin

I have a frustrating situation I cannot understand. I am developing an application using the Grails framework (Version: 3.4.0.RELEASE). I used the spring-security-core(1.2.7.3) and spring-security-ldap(1.0.6) plugins to manage credentials. I uninstall the ldap plugin, and for some reason it causes errors. Now when I try to run the project it gives me java errors for one of my groovy classes, such as "...java:15: ')' expected..." or "...java:15: ';' expected...". Everything ran great until I uninstall the ldap plugin. During compile it says "Compile error during compilation with javac". What's happening here? Let me know if I need to show some other code. And this is during runtime. There are no errors showing. I'm in such a hurry to finish the project that each time I get this problem I just create a new project and it runs fine. Just trying to avoid that as I progress in the project
EDIT:
Console output
| Loading Grails 2.2.4
| Configuring classpath.
| Environment set to development.....
| Packaging Grails application....
| Compiling 21 source files.
| Error Compilation error: startup failed:
Compile error during compilation with javac.
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: ')' expected
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: ';' expected
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: illegal start of expression
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: ';' expected
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: illegal start of expression
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: not a statement
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: not a statement
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: ';' expected
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: cannot find symbol
symbol : class util
location: package java
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: cannot find symbol
symbol : class lang
location: package java
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: cannot find symbol
symbol : constructor User(java.lang.String,java.lang.String,boolean,boolean,boolean,boolean,boolean)
location: class org.springframework.security.core.userdetails.User
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
C:\Users\cpu user\AppData\Local\Temp\groovy-generated-75457048637925996-java-source\com\example\ldap\MyUserDetails.java:15: package security does not exist
super ((java.lang.String)null, (java.lang.String)null, false, false, false, false, (java.util.Collection<java.lang.Object extends org.springframework.security.core.GrantedAuthority>)null);
^
Note: C:\projects\new portal project\InfinityPortalIntranet\src\java\com\example\ldap\AuthenticateUser.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
12 errors`
EDIT 2:
MyUserDetails.Groovy
package com.example.ldap
import org.springframework.security.core.GrantedAuthority
import org.springframework.security.core.userdetails.User
class MyUserDetails extends User {
// extra instance variables
final String fullname
final String email
final String title
final String firstName
final String lastName
MyUserDetails(String username, String password, boolean enabled, boolean accountNonExpired,
boolean credentialsNonExpired, boolean accountNonLocked,
Collection<GrantedAuthority> authorities,
String fullname, String email, String title, String firstName, String lastName) {
super(username, password, enabled, accountNonExpired, credentialsNonExpired, accountNonLocked,
authorities)
this.fullname = fullname
this.email = email
this.title = title
this.firstName = firstName
this.lastName = lastName
}
}

Resources